读书人

求高手帮助!解决方法

发布时间: 2013-01-25 15:55:29 作者: rapoo

求高手帮助!
实验一题目:
1、请编写Shape类,除了颜色相关属性和方法以外,自行思考还可以添加什么属性和方法。
2、从Shape类中派生出二维点(Point), 矩形(Rect),线(Line), 三角形(Triangle), 圆形(Round)等类。(不限定只派生出以上图形,可自行派生出更多的图形)。
3、要求Shape类及派生类均是功能完整的。

[解决办法]


//凑合看吧,不想写了
#include <iostream>
using namespace std;
#define PI 3.141592653
class Shape
{
public:
Shape(){};
~Shape(){};
public:
virtual double area() const{return 0;}; //虚函数 ,求面积.. 图形类用如 矩形,三角....
virtual double Length() const{return 0;}; //求距离,point和Line类用
virtual void PrintArea() const{cout<<area()<<endl;} // 输出面积函数
virtual void PrintLength() const{cout<<Length()<<endl;} // 输出距离函数
virtual void PrintColor() const{cout<<_Color<<endl;} // 输出颜色函数
protected:
int_width; //宽
int_height;//高
int_x;//坐标x
int_y;//坐标y
int_Color; // 颜色值
};

class Point : public Shape
{
........
};
class Rect : public Shape
{
........
};
class Line : public Shape
{
.........
};
class Triangle : public Shape
{
.........
};
class Round : public Shape
{
........
};

读书人网 >C++

热点推荐