问答题

给定一个函数,其函数功能为:使10个整数按由小到大的顺序排列。在主函数中输入10个数,并输出结果。使用VC6打开考生文件夹下的工程RevProj5。此工程包含一个源程序文件RevMain5.cpp,该程序实现上述功能。但此程序运行有问题。请找出错误的地方,改正后将此程序调试正确。 注意:不得删行或增行,也不得更改程序结构。 文件RevMain5.cpp中的程序清单如下: //RevMain5.cpp #include<iostream> #include<iomanip> using namespace std; int main() { void sort(int array[],int n); int data[10],*p,i; cout<<"Input 10 numbers\n"; for (i=0; i<10; i++) cin>>data [i]; cout<<"the origined array is:"; for (p=data;p<data+10;p++) { if((p-&data[0]) %5==0) cout<<" \n"; cout<<setw (5) <<*p; } sort (data, 10); cout<<"\n the present array is:"; for(p=data;p〈data+10;p++) { if((p-&data[0])%5==0) cout<<"\n"; cout<<setw (5)<<*p; } } void sort(int array[],int n) { /* * * * * * * * *found * * * * * * * * * */ for(p1=array;p1<array+(n-1) ;p1++) { for (p2=p1+1 ;p2<array+n;p2++) { if (*p1>*p2) { /* * * * * * * * *found * * * * * * * * * */ temp=*p1; *p1=*p2; *p2=*p1; } } } }

【参考答案】

修改后的函数sort为: void sort(int array[],int n) { int *p1,*p2,te......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
热门 试题

问答题
使用VC6打开考生文件夹下的工程MyProj5。此工程包含一个源程序文件 MyMain5.cpp,其中定义了用于表示日期的类Date,但类Date的定义并不完整。请按要求完成下列操作,将类Date的定义补充完成:①定义私有数据成员length、width和labe1,其中length、width是int型,labe1是类point的对象。它们分别表示长方形的长、宽以及坐标点。请在注释“ **1**”之后添加适当的语句。②完成构造函数square的定义,使square对象的默认值为:length=0,width=0, label(0,0),请在注释“ **2**”之后添加适当的语句。③完成重载构造函数square(int l,int w,int x,int y)的定义,把数据成员length、width和对象labe1分别初始化为参数l、w、x和y的值,请在注释“ **3**”之后添加适当的语句。④完成成员函数get_area()的类外定义,此函数的功能是返回此长方形的面积,及返回length*width的值。请在注释“ **4**”之后添加适当的语句。注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。源程序文件MyMain5.cpp清单如下: MyMain5.cpp#include<iostream>using namespace std;class point{private:int x,y;public:void set (int i,int j){x=i;y=j;}int get_y (){return y;}};class square{ * * 1 * *public: * * 2 * *square(int l,int w, int x, int y){ * * 3 * *}void set(int l,int w){length=1;width=w;}int get_area() const{return length*width;}};int square::get_area() const{ * * 4 * *}int main(){square small(2,4,1,35);cout<<small.get_area()<<end1;return 0;}