下面Shape类是一个表示形状的抽象类,Area ( )为求图形面积的函数。请从Shape类派生梯形类(Trapezoid)
下面Shape类是一个表示形状的抽象类,Area()为求图形面积的函数。请从Shape类派生梯形类(Trapezoid)、圆形类(Circle),三角形类(Triangl...
下面Shape类是一个表示形状的抽象类,Area ( )为求图形面积的函数。请从Shape类派生梯形类(Trapezoid)、圆形类(Circle),三角形类(Triangle),并给出具体的求面积函数。其中,所有派生类计算面积需要用到的参数由构造函数给出,梯形面积计算需要上底、下底和高,三角形面积需要底和高,圆形面积需要半径。
形状的抽象类声明如下:
class Shape {
public:
virtual double Area( ) = 0;
}; 展开
形状的抽象类声明如下:
class Shape {
public:
virtual double Area( ) = 0;
}; 展开
展开全部
看看这样写行不,我自己编的如有错误还请指正:
#include<iostream>
#define PI 3.142
using namespace std;
class Shape
{
protected:
double R;
double Triangle_S;
double Triangle_H;
double Trapezoid_ON;
double Trapezoid_DOWN;
double Trapezoid_H;
public:
virtual void area(){};
};
class Circle:public Shape
{
public:
Circle(double r)
void area()
};
class Triangle:public Shape
{
public:
Triangle(double s,double h)
void area()
};
class Trapezoid:public Shape
{
public:
Trapezoid(double ON,double DOWN,double H)
void area()
};
void main()
{
Circle a(2);//求圆面积
a.area();
Triangle b(2,2);//求三角形面积
b.area();
Trapezoid c(2,2,2);//求梯形面积
c.area();
}
#include<iostream>
#define PI 3.142
using namespace std;
class Shape
{
protected:
double R;
double Triangle_S;
double Triangle_H;
double Trapezoid_ON;
double Trapezoid_DOWN;
double Trapezoid_H;
public:
virtual void area(){};
};
class Circle:public Shape
{
public:
Circle(double r)
void area()
};
class Triangle:public Shape
{
public:
Triangle(double s,double h)
void area()
};
class Trapezoid:public Shape
{
public:
Trapezoid(double ON,double DOWN,double H)
void area()
};
void main()
{
Circle a(2);//求圆面积
a.area();
Triangle b(2,2);//求三角形面积
b.area();
Trapezoid c(2,2,2);//求梯形面积
c.area();
}
展开全部
class Trapezoid : public Shape
{
private:
double top;
double bottom;
double height;
public:
Trapezoid(double t, double b, double h)
{
top = t;
bottom = b;
height = h;
}
double Area()
{
return (top + bottom) * height / 2;
}
};
#define PI 3.1415926
class Circle : public Shape
{
private:
double r;
public:
Circle(double r)
{
this->r = r;
}
double Area()
{
return PI * r * r;
}
};
class Triangle : public Shape
{
private:
double bottom;
double height;
public:
Triangle(double b, double h)
{
bottom = b;
height = h;
}
double Area()
{
return bottom * height / 2;
}
};
{
private:
double top;
double bottom;
double height;
public:
Trapezoid(double t, double b, double h)
{
top = t;
bottom = b;
height = h;
}
double Area()
{
return (top + bottom) * height / 2;
}
};
#define PI 3.1415926
class Circle : public Shape
{
private:
double r;
public:
Circle(double r)
{
this->r = r;
}
double Area()
{
return PI * r * r;
}
};
class Triangle : public Shape
{
private:
double bottom;
double height;
public:
Triangle(double b, double h)
{
bottom = b;
height = h;
}
double Area()
{
return bottom * height / 2;
}
};
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已过了爱做梦的年纪
却还是喜欢在午后做那白日梦
徘徊在梦中那棵老槐树旁
知了叫着落寞了的清愁
往昔的疼痛还在心间
残缺了的记忆已经滑落
却还是喜欢在午后做那白日梦
徘徊在梦中那棵老槐树旁
知了叫着落寞了的清愁
往昔的疼痛还在心间
残缺了的记忆已经滑落
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询