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

2024-11-25 16:41:49
推荐回答(3个)
回答1:

刚发过问候和中午商量什么的,结果又没看到你的回音,就看到采纳了。度度太会拦截了。冲这点,我这次帮你。呵呵
#include
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"<};

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"<};

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"<};

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 "<
}

回答2:

#include
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 = "< return 0;
}

回答3:

g梵蒂冈发的个的非官方的