问答题
return 0;
【参考答案】
修改程序时可以去掉类对象定义时的const关键词。即:
int main ( )
{
......
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
请编写一个函数resort,该函数的功能是:能在一个数列中,对从指定位置开始的几个数,按相反顺序重新排列,并在主函数中输出新的数列。 注意:部分源程序已存在文件PROC4.cpp中。 请勿修改主函数和其他函数中的任何内容,仅在函数reson()的花括号中填写若干语句。 文件PROC4.cpp的内容如下: PROC4.cpp #include<iostream> using namespace std; void resort(int array[],int where,int arrount); int main() int number[20],where, arrount,i; cout<< input 20 numbers n ; for(i=0;i cin>>number[i]; cout<< how many do you want to sort: ; cin>>arrount; cout<< where do you want to start: ; cin>>where; resort(number,where,arrount); cout<< n resorted array as follow: n ; for(i=0;i<20;i++) cout<<number[i]; return 0; void resort(int array[ ],int where,int amount) ************
点击查看答案&解析
问答题
使用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,该函数的功能是:能...
使用VC6打开考生文件夹下的工程MyProj4。...