1、3.25设计一个类CRectangle,除了有相关的数据成员,该类要求包含下述成员函数:矩形从一个位置移动到另一个位置的Move()函数;改变矩形大小的Size()函数;返回矩形左上角的坐标坐标值的Where()函数;计算矩形面积的Area()函数。代码如下:#include #include class CRectangle private: double X; double Y; double Length; double Width; public: CRectangle(double s, double m, double L, double W) X=s; Y=m; Length=L
2、; Width=W; CRectangle() void Move(double , double); void Size(double ,double); void Where(); void Area(); ; void CRectangle:Move(double x, double y) cout矩形按向量(x,y)移动endl; cout现在矩形左上角所在的位置:endl; cout(X+x,Y+y)endl; void CRectangle:Where() cout现在矩形左上角所在的位置:endl; cout(X,Y)endl; void CRectangle:Size(doub
3、le l, double w) cout要更改的长:lendl; cout要更改的宽:wendl; Length=l; Width=w; cout面积是:Length*Widthendl; void CRectangle:Area() double area; area=Length*Width; cout面积是:areaendl; int main() CRectangle cr(2,3,5,4); cr.Where(); cr.Area(); cr.Move(1,2); cr.Size(4,5); return 0; 运行结果如下:2.设计一个类#include using namespa
4、ce std; class CPetrol public: CPetrol(); void setamount(); double total; private: double am_90; double am_93; double am_98; double price_90; double price_93; double price_98; ; CPetrol:CPetrol() price_90=3.96; price_93=4.05; price_98=4.38; void CPetrol:setamount() coutinput three amounts!am_90am_93a
5、m_98; total=am_90*price_90+am_93*price_93+am_98*price_98; void main() CPetrol c; c.setamount(); coutThe total isc.totalendl; 运行结果如下:3.#include class Line friend void setpoint(Line &A,Line &B); private: double a; double b; double c; public: Line (double a1, double b1, double c1) a=a1; b=b1; c=c1; Line(); ;void setpoint(Line &A,Line &B) double x;if(A.a/B.a!=A.b/B.b) x=-100; while(1) if( (-A.c-A.a*x)/A.b - (-B.c-B.a*x)/B.b ) 0.00001) break; x=x+0.00001; coutx (-A.c-A.a*x)/A.b; else couterrorendl; void main () Line A(1,2,-15),B(4,5,-16); setpoint(A,B);