问题描述
- 怎么求两个面积之和啊?求帮助!!!
-
#include
#include
class Shape
{
public :
virtual int area()=0;
};
class Trape :public Shape
{
int k,l,h;
public :
Trape (int a,int b,int c)
{
k=a;
l=b;
h=c;
}
int area()
{
cout<<"area="<<(k+l)*h/2<
return 0;
}
};
class Triang :public Shape
{
int a,b,c;
public :
Triang(int a1,int b1,int c1)
{
a=a1;
b=b1;
c=c1;
}
int area()
{
int p,s;
p=(a+b+c)/2;
s=p*(p-a)*(p-b)*(p-c);
cout
return 0;
}
};
int main()
{
Shape *s[2];
Trape t(1,2,3);
Triang t1(5,3,4);
s[0]=&t;
s[1]=&t1;
s[0]->area ();
s[1]->area ();cout<<"sum="<< ? <<endl; return 0;
}
解决方案
int x = s[0]->area () + s[1]->area ();
cout<<"sum="<< x <<endl;
解决方案二:
求两个大数之和
求两个矩阵之和(重载)
求两个对称矩阵之和与乘积
解决方案三:
#include
using namespace std;
int main()
{
int a,b,c,d,s;
cin>>a>>b>>c>>d;
s=a*b+c*d;
cout<<"面积之和为:"<<s<<endl;
return 0;
}
时间: 2024-12-21 20:34:11