小妖精姘头 2005-5-10 00:34
C++高手进来,求助
1。编写程序声明一个三维点point类,重载运算符“+”,“—”和“=”,实现三维点的加,减,和赋值。
2。声明一个Shape抽象类,在此基础上派生出Rectangle和Circle类,二者都由GetArea()函数计算对象的面积,由GetPerim()函数计算对象的周长。
3。编写一个程序,声明一个矩阵类,通过重载“+”,“—”和“ * ”,实现矩阵的相加,相减和相乘
Eagle 2005-5-10 12:56
哈哈哈哈,小CASE,前几天刚做过一个巨数运算类,差不多的。这个很简单的啊。都是C++的基本功啊。
suhuoyi 2005-8-20 17:12
<P>晕,随便找本书,就有例子差不多的啊</P><P>最基本的</P>
seanchen88 2006-7-26 15:46
<p>#include <iostream.h><br/>//1<br/>class POINT {<br/>public:<br/> POINT (double x=0,double y=0,double z=0); //构造函数<br/> POINT (const POINT& other); //拷贝构造函数<br/> void print(); //显示函数<br/> POINT operator + (const POINT& other); //重载加法<br/> POINT operator - (const POINT& other); //重载减法<br/> POINT operator = (const POINT& other); //重载赋值<br/> ~POINT (); //析构函数<br/>protected:<br/> double the_x,the_y,the_z;<br/>};</p><p>POINT::POINT (double x,double y,double z)<br/>{<br/> the_x=x;<br/> the_y=y;<br/> the_z=z;<br/> return;<br/>}</p><p>POINT::POINT (const POINT& other)<br/>{<br/> the_x=other.the_x;<br/> the_y=other.the_y;<br/> the_z=other.the_z;<br/> return;<br/>}</p><p>void POINT::print ()<br/>{<br/> cout<<'('<<the_x<<','<<the_y<<','<<the_z<<')'<<endl;<br/>}</p><p>POINT POINT::operator + (const POINT& other)<br/>{<br/> POINT temp;<br/> temp.the_x=the_x+other.the_x;<br/> temp.the_y=the_y+other.the_y;<br/> temp.the_z=the_z+other.the_z;<br/> return temp;<br/>}</p><p>POINT POINT::operator - (const POINT& other)<br/>{<br/> POINT temp;<br/> temp.the_x=the_x-other.the_x;<br/> temp.the_y=the_y-other.the_y;<br/> temp.the_z=the_z-other.the_z;<br/> return temp;<br/>}</p><p>POINT POINT::operator = (const POINT& other)<br/>{<br/> this->the_x=other.the_x;<br/> this->the_y=other.the_y;<br/> this->the_z=other.the_z;<br/> return *this;<br/>}</p><p>POINT::~POINT ()<br/>{}</p><p>//2<br/>class SHAPE {<br/>public:<br/> void set_size (double x,double y=0)<br/> {<br/> x_size=x;<br/> y_size=y;<br/> }<br/> virtual double GetArea ()=0;<br/> virtual double GetPerim ()=0;<br/>protected:<br/> double x_size,y_size;<br/>};</p><p>class RECTOANLE:public SHAPE {<br/>public:<br/> virtual double GetArea ()<br/> {<br/> return (x_size*y_size);<br/> }<br/> virtual double GetPerim ()<br/> {<br/> return (2*x_size+2*y_size);<br/> }<br/>};</p><p>class CIRCLE:public SHAPE {<br/>public:<br/> virtual double GetArea ()<br/> {<br/> return (3.14*x_size*x_size);<br/> }<br/> virtual double GetPerim ()<br/> {<br/> return (2*3.14*x_size);<br/> }<br/>};</p>
seanchen88 2006-7-26 15:47
第三个懒的编了,类似,自行编去。。。
x94664 2008-6-19 20:33
:P ;P :o 表情弄住了····看不清了
[[i] 本帖最后由 x94664 于 2008-6-19 20:42 编辑 [/i]]
jxiao2000 2008-7-18 22:12
12
1234