本文介绍了我在我的程序中使用了多重继承,但我无法获得所需的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <iostream>
using namespace std;
class add
{
protected:
int x;int y;
public:
int c;
void getvalueforadd(int a, int b)
{
x=a;y=b;
}
void display()
{
cout<<"the value of x and y are "<<x<<"\t"<<y;
}
void sum()
{
c=(x+y);
cout<<"Sum="<<c<<"\n";
}
};
class sub
{
protected:
int p,q;
public:
int d;
void getvalueforsub(int a,int b)
{
p=a;q=b;
}
void show()
{
cout<<"the value of p and q are "<<p<<"\t"<<q;
}
void diff()
{
d=(p-q);
cout<<"Diff="<<d<<"\n";
}
};
class mul:public add,public sub
{
protected:
int k;
public:
int getk()
{
return (c*d);
}
};
<b><b></b></b>
int main()
{
int m,n;
add A;
sub B;
mul D;
A.getvalueforadd(7,6);
B.getvalueforsub(6,3);
A.display();
B.show();
A.sum();
B.diff();
m=D.getk();
cout<<m;
return (0);
}
What I have tried:
<pre lang="C#">I want to divide the sum of numbers from first class 'add' and difference of numbers from second class 'sub' and then multiply both the results ..
推荐答案
这篇关于我在我的程序中使用了多重继承,但我无法获得所需的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!