C++编程,求大神帮忙题目看图片解答!急急!!!
展开全部
刚发过问候和中午商量什么的,结果又没看到你的回音,就看到采纳了。度度太会拦截了。冲这点,我这次帮你。呵呵
#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;
}
#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;
}
展开全部
#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;
}
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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
g梵蒂冈发的个的非官方的
追问
什么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询