小妖精姘头 发表于 2005-5-10 00:34:00

C++高手进来,求助

1。编写程序声明一个三维点point类,重载运算符“+”,“—”和“=”,实现三维点的加,减,和赋值。
2。声明一个Shape抽象类,在此基础上派生出Rectangle和Circle类,二者都由GetArea()函数计算对象的面积,由GetPerim()函数计算对象的周长。
3。编写一个程序,声明一个矩阵类,通过重载“+”,“—”和“ * ”,实现矩阵的相加,相减和相乘

Eagle 发表于 2005-5-10 12:56:00

哈哈哈哈,小CASE,前几天刚做过一个巨数运算类,差不多的。这个很简单的啊。都是C++的基本功啊。

suhuoyi 发表于 2005-8-20 17:12:00

<P>晕,随便找本书,就有例子差不多的啊</P><P>最基本的</P>

redfish 发表于 2005-8-22 21:57:00

MD这个还好意思问!!

末路洪者 发表于 2006-4-26 17:14:00

基本功

omi 发表于 2006-6-10 12:03:00

不懂

天地鸿蒙 发表于 2006-6-13 09:27:00

<p>一個個還真“狂”啊</p><p></p>

seanchen88 发表于 2006-7-26 15:46:00

<p>#include &lt;iostream.h&gt;<br/>//1<br/>class POINT {<br/>public:<br/>&nbsp;POINT (double x=0,double y=0,double z=0); //构造函数<br/>&nbsp;POINT (const POINT&amp; other);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //拷贝构造函数<br/>&nbsp;void print();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //显示函数<br/>&nbsp;&nbsp;&nbsp; POINT operator + (const POINT&amp; other);&nbsp;&nbsp;&nbsp; //重载加法<br/>&nbsp;POINT operator - (const POINT&amp; other);&nbsp;&nbsp;&nbsp; //重载减法<br/>&nbsp;POINT operator = (const POINT&amp; other);&nbsp;&nbsp;&nbsp; //重载赋值<br/>&nbsp;~POINT ();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //析构函数<br/>protected:<br/>&nbsp;double the_x,the_y,the_z;<br/>};</p><p>POINT::POINT (double x,double y,double z)<br/>{<br/>&nbsp;the_x=x;<br/>&nbsp;the_y=y;<br/>&nbsp;the_z=z;<br/>&nbsp;return;<br/>}</p><p>POINT::POINT (const POINT&amp; other)<br/>{<br/>&nbsp;the_x=other.the_x;<br/>&nbsp;the_y=other.the_y;<br/>&nbsp;the_z=other.the_z;<br/>&nbsp;return;<br/>}</p><p>void POINT::print ()<br/>{<br/>&nbsp;cout&lt;&lt;'('&lt;&lt;the_x&lt;&lt;','&lt;&lt;the_y&lt;&lt;','&lt;&lt;the_z&lt;&lt;')'&lt;&lt;endl;<br/>}</p><p>POINT POINT::operator + (const POINT&amp; other)<br/>{<br/>&nbsp;POINT temp;<br/>&nbsp;temp.the_x=the_x+other.the_x;<br/>&nbsp;temp.the_y=the_y+other.the_y;<br/>&nbsp;temp.the_z=the_z+other.the_z;<br/>&nbsp;return temp;<br/>}</p><p>POINT POINT::operator - (const POINT&amp; other)<br/>{<br/>&nbsp;POINT temp;<br/>&nbsp;temp.the_x=the_x-other.the_x;<br/>&nbsp;temp.the_y=the_y-other.the_y;<br/>&nbsp;temp.the_z=the_z-other.the_z;<br/>&nbsp;return temp;<br/>}</p><p>POINT POINT::operator = (const POINT&amp; other)<br/>{<br/>&nbsp;this-&gt;the_x=other.the_x;<br/>&nbsp;this-&gt;the_y=other.the_y;<br/>&nbsp;this-&gt;the_z=other.the_z;<br/>&nbsp;return *this;<br/>}</p><p>POINT::~POINT ()<br/>{}</p><p>//2<br/>class SHAPE {<br/>public:<br/>&nbsp;void set_size (double x,double y=0)<br/>&nbsp;{<br/>&nbsp;&nbsp;x_size=x;<br/>&nbsp;&nbsp;y_size=y;<br/>&nbsp;}<br/>&nbsp;virtual double GetArea ()=0;<br/>&nbsp;virtual double GetPerim ()=0;<br/>protected:<br/>&nbsp;double x_size,y_size;<br/>};</p><p>class RECTOANLE:public SHAPE {<br/>public:<br/>&nbsp;virtual double GetArea ()<br/>&nbsp;{<br/>&nbsp;&nbsp;return (x_size*y_size);<br/>&nbsp;}<br/>&nbsp;virtual double GetPerim ()<br/>&nbsp;{<br/>&nbsp;&nbsp;return (2*x_size+2*y_size);<br/>&nbsp;}<br/>};</p><p>class CIRCLE:public SHAPE {<br/>public:<br/>&nbsp;virtual double GetArea ()<br/>&nbsp;{<br/>&nbsp;&nbsp;return (3.14*x_size*x_size);<br/>&nbsp;}<br/>&nbsp;virtual double GetPerim ()<br/>&nbsp;{<br/>&nbsp;&nbsp;return (2*3.14*x_size);<br/>&nbsp;}<br/>};</p>

seanchen88 发表于 2006-7-26 15:47:00

第三个懒的编了,类似,自行编去。。。

刹那公子 发表于 2007-3-17 19:10:00

记得我们的教科书上就有这样的例题

x94664 发表于 2008-6-19 20:33:03

:P;P :o 表情弄住了····看不清了

[ 本帖最后由 x94664 于 2008-6-19 20:42 编辑 ]

jxiao2000 发表于 2008-7-18 22:12:14

12

1234

绿豆雪糕 发表于 2010-7-22 09:21:41

什么都问 唉
页: [1]
查看完整版本: C++高手进来,求助