问答题
return 0;
【参考答案】
修改程序时可以去掉类对象定义时的const关键词。即:
int main ( )
{
......
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
使用VC6打开考生文件夹下的工程MyProj4。此工程包含一个源程序文件 MyMain4.cpp,该程序将通过把类Distance定义为类Point的友元类来实现计算两点之间距离的功能。但程序中定义的类并不完整。请按要求完成下列操作,把类的定义补充完整。 ①把类Distance定义为类Point的友元类。请在注释“ **1**”之后添加适当的语句。 ②定义类Point的构造函数,完成给私有数据成员x和y的赋值,并且两个参数的默认值都为0。请在注释“ **2**”之后添加适当的语句。 ③完成类Distance的成员函数Dis(Point &p,Point &q)的定义,并在其中计算点p、q之间的距离,并且返回结果。假设两点之间的距离distance=sqrt((p.x-q.x)* (p.x-q.x)+(p.y-q.y)*(p.y-q.y))。请在注释“ **3**”之后添加适当的语句。 源程序文件MyMain4.cpp中的程序清单如下: MyMain4. cpp #include<iostream> #include<cmath> using namespace std; class Point public: * * 1 * * 定义类 Point 的构造函数 * * 2 * * void pint() cout<< x= <<x<<end1; cout<< y= <<y<<end1; private: float x,y; ; class Distance public: float Dis(Point &p, Point &q); ; float Distance :: Dis(Point &p, Point &q) * * 3 * * int main ( ) Point p(10,10),q(20,20); Distance d; cout<<d.Dis(p,q)<<end1; return 0;
点击查看答案&解析
相关试题
请编写一个函数resort,该函数的功能是:能...