加油机控制器全套:C++ 定义类,只给出定义就行,谢谢

来源:百度文库 编辑:高考问答 时间:2024/04/28 00:56:18
就四道题啊。只给出定义就好了,
谢谢大家。我给100分,

12. 用C++的类体系结构定义一个图形类体系结构,可以完成画点、画圆、画直线、画矩形及画三角形的功能,并可以利用虚函数自动计算不同图形的面积。

7. 定义一个矩阵类CMatrix:
(1) 重载适用于矩阵加、减运算符函数;
(2) 求矩阵的转置矩阵;
(3) 求两矩阵的积;

6. 定义一个一元多项式类CPolynomial:
(1) 重载适用于多项式的加、减运算符函数;
(2) 求两多项式的积;
5. 定义一个三维矢量类CVector:
(1) 重载适用于矢量的加、减运算符函数;
(2) 求矢量的模;
(3) 求矢量的点积、叉积;

//---------------------------------------------------------------------------
//图形类,所有以下图形的基类
class graphics
{
public:
graphics(); //构造函数,可以自己添加一些重载
virtual double acreage(); //计算面积
virtual void draw(); //画图
private:
// ... //一些私有变量定义
};

//点
class point:public graphics
{
public:
point();
virtual void draw();
private:
int x,y; //点的横纵坐标
};

//圆
class circle:public graphics
{
public:
circle();
virtual double acreage();
virtual void draw();
private:
point center; //圆心坐标,是一个point对象
double r; //半径
};

//直线
class line:public graphics
{
public:
line();
virtual void draw();
private:
point start,end; //直线的起始点
};

//矩形
class rectangle:public graphics
{
public:
rectangle();
virtual double acreage();
virtual void draw();
private:
point lefttop, rightbottom;//矩形的左上和右下的坐标
};

//三角形
class triangle:public graphics
{
public:
triangle();
virtual double acreage();
virtual void draw();
private:
point x,y,z; //三角形的三个顶点
};

//---------------------------------------------------------------------------
//矩阵类
class CMatrix
{
public:
CMatrix(int x, int y); //构造函数,指定行列数
~CMatrix(); //析构函数,删除data占用空间

CMatrix operator+(const CMatrix&); //重载加法运算
CMatrix operator-(const CMatrix&); //重载减法运算
CMatrix operator*(const CMatrix&); //两矩阵的积
CMatrix transpose(const CMatrix&); //转置矩阵
private:
int *data; //保存矩阵中的数据
int row,col; //保存矩阵的行列数
};
//---------------------------------------------------------------------------
//多项式类
class CPolynomial
{
public:
CPolynomial(int x); //构造函数

CPolynomial operator+(const CPolynomial&); //重载加法运算
CPolynomial operator-(const CPolynomial&); //重载减法运算
CPolynomial operator*(const CPolynomial&); //求两多项式的积
private:
int itemcount; //一无多项式的项数
};
//---------------------------------------------------------------------------
class CVector
{
public:
CVector(int x,int y,int z); //构造函数
CVector operator+(const CVector&); //重载加法运算
CVector operator-(const CVector&); //重载减法运算

double module(const CVector&); //求模
CVector dotmetrix(const CVector&, const CVector&);
CVector accumulate(const CVector&, const CVector&);
private:
int x,y,z; //三维矢量的三个方向值
};
//---------------------------------------------------------------------------