|
<p>c++的简单的类程序,调试不来了,帮忙修改一下。</p>
<p><img src="http://img.baidu.com/img/iknow/icn_point.gif"> 悬赏分:5 -</p>
<p>解决时间:2010-10-22 16:24</p>
<p>设计一个程序,定义一个矩形类,包括数据成员和函数成员。要求有构造函数、析构函数,完成赋值、修改、显示等功能的接口,并编写main 函数测试,要求用一个对象初始化另一对象。</p>
<p>#include<iostream.h></p>
<p>class Rectangle</p>
<p>{</p>
<p>int Left,Right,Top,Bottom;</p>
<p>public:</p>
<p>Rectangle (int left=0,int right=0,int top=0,int bottom=0);</p>
<p>~Rectangle();</p>
<p>void set(int left,int right,int top,int bottom)</p>
<p>{ Left=left;</p>
<p>Right=right;</p>
<p>Top=top;</p>
<p>Bottom=bottom;</p>
<p>}</p>
<p>void change(int left,int right,int top,int bottom)</p>
<p>{</p>
<p>Left=left;</p>
<p>Right=right;</p>
<p>Top=top;</p>
<p>Bottom=bottom;</p>
<p>}</p>
<p>void display();</p>
<p>};</p>
<p>void Rectangle::display()</p>
<p>{</p>
<p>cout<<"矩形的长为:"<<Left<<\'/n\'<<Right<<"矩形的宽为:"<<Top<<\'\n\'<<Bottom<<endl;</p>
<p>};</p>
<p>void main()</p>
<p>{</p>
<p>Rectangle r;</p>
<p>r.set(0,0,0,0);</p>
<p>r.change(3,3,4,4);</p>
<p>r.display();</p>
<p>}</p>
<p>提问者: 磨山墨水 - 三级</p>
<p>最佳答案</p>
<p>#include<iostream.h></p>
<p>#include <math.h></p>
<p>class Rectangle</p>
<p>{</p>
<p>private:</p>
<p>int Left,Right,Top,Bottom;</p>
<p>public:</p>
<p>Rectangle()</p>
<p>{</p>
<p>Left=0;</p>
<p>Right=0;</p>
<p>Top=0;</p>
<p>Bottom=0;</p>
<p>};</p>
<p>~Rectangle(){};</p>
<p>void set(int left,int right,int top,int bottom)</p>
<p>{ Left=left;</p>
<p>Right=right;</p>
<p>Top=top;</p>
<p>Bottom=bottom;</p>
<p>}</p>
<p>void change(int left,int right,int top,int bottom)</p>
<p>{</p>
<p>Left=left;</p>
<p>Right=right;</p>
<p>Top=top;</p>
<p>Bottom=bottom;</p>
<p>}</p>
<p>void display();</p>
<p>};</p>
<p>void Rectangle::display()</p>
<p>{</p>
<p>cout<<"矩形的长为:"<<Right-Left<<"矩形的宽为:"<<abs(Bottom-Top)<<endl;</p>
<p>};</p>
<p>void main()</p>
<p>{</p>
<p>Rectangle r;//要有默认构造函数</p>
<p>r.set(0,0,0,0);</p>
<p>// r.change(3,3,4,4);//坐标不是左上角和右下角的?你这个输入是什么?</p>
<p>r.change(2,6,2,9);</p>
<p>r.display();</p>
<p>}</p>
<p>0</p>
<p>回答者:</p>
<p><img src="http://img.baidu.com/img/iknow/icon_taojin.gif"></p>
<p>hi_xjy - 八级 2010-10-19 23:06</p>
<p>我来评论>></p>
<p>提问者对于答案的评价:</p>
<p>谢谢,也谢谢楼上。</p>
|
|