C++编程,求大神帮忙题目看图片解答!急急!!!

 我来答
百度网友7a283bc
2014-12-25 · TA获得超过221个赞
知道小有建树答主
回答量:129
采纳率:83%
帮助的人:48.8万
展开全部
刚发过问候和中午商量什么的,结果又没看到你的回音,就看到采纳了。度度太会拦截了。冲这点,我这次帮你。呵呵
#include <iostream>
using namespace std;
class Shape
{
public:
virtual double area() const=0;
};

class Triangle:public Shape
{
double mh,ml;
public:
Triangle(double h,double l){mh=h; ml=l;}
double area()const{cout<<"the Triangle area is"<<mh*ml/2.0<<endl;return mh*ml/2.0;}
};

class Square:public Shape
{
double mh,ml;
public:
Square(double h,double l){mh=h; ml=l;}
double area()const{cout<<"the Square area is"<<mh*ml<<endl;return mh*ml;}
};

class Trapezoid : public Shape
{
double mh,mal,mbl;
public:
Trapezoid(double h,double l,double ll){mh=h; mal=l; mbl=ll;}
double area()const{cout<<"the Trapezoid area is"<<mh*(mal+mbl)/2.0<<endl;return mh*(mal+mbl)/2.0;}
};

void main()
{
Trapezoid t(1,2,3);
Square s(1,2);
Triangle ta(1,2);

Shape * p[3];
p[0]=&ta; p[1]=&t; p[2]=&s;
double d=0;
for(int i=0;i<3;i++)
d+=p[i]->area();
cout<<"all three area is "<<d<<endl;

}
更多追问追答
追问

可以看一下这几道判断题吗
格格是我大大王
2014-12-25
知道答主
回答量:4
采纳率:0%
帮助的人:2.6万
展开全部
#include <isotream.h>
using namespace std;
class Shape
{
public:
virtual double area()const=0;
};

class Point
{
public:
Point(double x,double y):m_x(x),m_y(y)
{}
virtual ~Point(){}
public:
double m_x;
double m_y;
};

class Square:public Shape
{
public:
Square(Point a,Point b, Point c, Point d)
:m_a(a),m_b(b),m_c(c),m_d(d)
{}
virtual ~Square(){}
double area()
{
return (1.0 / 2.0) * (m_a.m_x * m_b.m_y +
m_b.m_x * m_c.m_y +
m_c.m_x * m_a.m_y -
m_a.m_x * m_c.m_y -
m_b.m_x * m_a.m_y -
m_c.m_x * m_b.m_y) +
(1.0 / 2.0) * (m_b.m_x * m_c.m_y +
m_c.m_x * m_d.m_y +
m_d.m_x * m_b.m_y -
m_b.m_x * m_d.m_y -
m_c.m_x * m_b.m_y -
m_d.m_x * m_c.m_y) +
}
public:
Point m_a;
Point m_b;
Point m_c;
Point m_d;

};

class Trapezoid:public Shape
{
public:
Trapezoid(Point a,Point b, Point c, Point d)
:m_a(a),m_b(b),m_c(c),m_d(d)
{}
virtual ~Trapezoid(){}
double area()
{
return (1.0 / 2.0) * (m_a.m_x * m_b.m_y +
m_b.m_x * m_c.m_y +
m_c.m_x * m_a.m_y -
m_a.m_x * m_c.m_y -
m_b.m_x * m_a.m_y -
m_c.m_x * m_b.m_y) +
(1.0 / 2.0) * (m_b.m_x * m_c.m_y +
m_c.m_x * m_d.m_y +
m_d.m_x * m_b.m_y -
m_b.m_x * m_d.m_y -
m_c.m_x * m_b.m_y -
m_d.m_x * m_c.m_y) +
}
public:
Point m_a;
Point m_b;
Point m_c;
Point m_d;
};

class Triangle:public Shape
{
public:
Triangle(Point a, Point b, Point c)
:m_a(a),m_b(b),m_c(c)
{}
virtual ~Triangle(){}
double area()
{
return (1.0 / 2.0) * (m_a.m_x * m_b.m_y +
m_b.m_x * m_c.m_y +
m_c.m_x * m_a.m_y -
m_a.m_x * m_c.m_y -
m_b.m_x * m_a.m_y -
m_c.m_x * m_b.m_y);
}
public:
Point m_a;
Point m_b;
Point m_c;
};
int main()
{
Square square((0,2), (2,2), (0,0), (2,0));
Triangle triangle((0,0), (2,2), (4,0));
Trapezoid trapezoid((0,2), (2,2), (0,0), (4,0));
cout<<"totalarea = "<<square.area() + triangle.area() + trapezoid.area()<<endl;
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
no...6@163.com
2014-12-25
知道答主
回答量:5
采纳率:0%
帮助的人:6343
展开全部
g梵蒂冈发的个的非官方的
追问
什么?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式