欢迎来到天天文库
浏览记录
ID:37909101
大小:263.50 KB
页数:43页
时间:2019-06-02
《C++上机指导答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验答案实验一(略)实验二1、2、3、(1)#include//包含头文件命令usingnamespacestd;//使用名字空间stdintmain(){inta,b,c;//定义两个变量a和bcout<<"Pleaseinputtoa,bandc:"<>a>>b>>c;//等待用户从键盘输入数据intmax(intx,inty) ;//有两个形参的max函数原型声明cout<<"Max(a,b)="<2、x函数原型声明cout<<"Max(a,b,c)="<y) ?x:y;}//求两个数中的大者的函数intmax(intx,inty,intz)//求三个数中的大者的函数{inttemp;temp=max(x,y) ;temp=max(temp,z) ;returntemp ;}(2)#includeusingnamespacestd;intmain(){intmax(inta,intb,intc=0);inta,3、b,c;cin>>a>>b>>c;cout<<"max(a,b,c)="<a)a=b;if(c>a)a=c;returna;}4、(1)#includeusingnamespacestd;intmain(){voidsort(int*,int*,int*);inta,b,c,a1,b1,c1;cout<<"Pleaseenter3integers:";cin>>a>>b>>c;a1=a;b14、=b;c1=c;sort(&a1,&b1,&c1);cout<*j)change(i,j);if(*i>*k)change(i,k);if(*j>*k)change(j,k);}voidchange(int*x,int*y){inttemp;temp=*x;*x=*y;*y=temp;}(2)#include5、>usingnamespacestd;intmain(){voidsort(int&,int&,int&);inta,b,c,a1,b1,c1;cout<<"Pleaseenter3integers:";cin>>a>>b>>c;a1=a;b1=b;c1=c;sort(a1,b1,c1);cout<j)change(i,j);i6、f(i>k)change(i,k);if(j>k)change(j,k);}voidchange(int&x,int&y){inttemp;temp=x;x=y;y=temp;}5、#include#includeusingnamespacestd;intmain(){inta[5]={1,9,0,23,-45};floatb[5]={2.4f,7.6f,5.5f,6.6f,-2.3f};stringc[5]={”student”,”teacher”,”library”,”class”,”school”};voidsort(int[]);voidso7、rt(float[]);voidsort(double[]);sort(a);sort(b);sort(c);return0;}voidsort(inta[])//冒泡排序{inti,j,t;for(j=0;j<5;j++)for(i=0;i<5-j;i++)if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}cout<<"thesortednumbers:"<
2、x函数原型声明cout<<"Max(a,b,c)="<y) ?x:y;}//求两个数中的大者的函数intmax(intx,inty,intz)//求三个数中的大者的函数{inttemp;temp=max(x,y) ;temp=max(temp,z) ;returntemp ;}(2)#includeusingnamespacestd;intmain(){intmax(inta,intb,intc=0);inta,
3、b,c;cin>>a>>b>>c;cout<<"max(a,b,c)="<a)a=b;if(c>a)a=c;returna;}4、(1)#includeusingnamespacestd;intmain(){voidsort(int*,int*,int*);inta,b,c,a1,b1,c1;cout<<"Pleaseenter3integers:";cin>>a>>b>>c;a1=a;b1
4、=b;c1=c;sort(&a1,&b1,&c1);cout<*j)change(i,j);if(*i>*k)change(i,k);if(*j>*k)change(j,k);}voidchange(int*x,int*y){inttemp;temp=*x;*x=*y;*y=temp;}(2)#include5、>usingnamespacestd;intmain(){voidsort(int&,int&,int&);inta,b,c,a1,b1,c1;cout<<"Pleaseenter3integers:";cin>>a>>b>>c;a1=a;b1=b;c1=c;sort(a1,b1,c1);cout<j)change(i,j);i6、f(i>k)change(i,k);if(j>k)change(j,k);}voidchange(int&x,int&y){inttemp;temp=x;x=y;y=temp;}5、#include#includeusingnamespacestd;intmain(){inta[5]={1,9,0,23,-45};floatb[5]={2.4f,7.6f,5.5f,6.6f,-2.3f};stringc[5]={”student”,”teacher”,”library”,”class”,”school”};voidsort(int[]);voidso7、rt(float[]);voidsort(double[]);sort(a);sort(b);sort(c);return0;}voidsort(inta[])//冒泡排序{inti,j,t;for(j=0;j<5;j++)for(i=0;i<5-j;i++)if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}cout<<"thesortednumbers:"<
5、>usingnamespacestd;intmain(){voidsort(int&,int&,int&);inta,b,c,a1,b1,c1;cout<<"Pleaseenter3integers:";cin>>a>>b>>c;a1=a;b1=b;c1=c;sort(a1,b1,c1);cout<j)change(i,j);i
6、f(i>k)change(i,k);if(j>k)change(j,k);}voidchange(int&x,int&y){inttemp;temp=x;x=y;y=temp;}5、#include#includeusingnamespacestd;intmain(){inta[5]={1,9,0,23,-45};floatb[5]={2.4f,7.6f,5.5f,6.6f,-2.3f};stringc[5]={”student”,”teacher”,”library”,”class”,”school”};voidsort(int[]);voidso
7、rt(float[]);voidsort(double[]);sort(a);sort(b);sort(c);return0;}voidsort(inta[])//冒泡排序{inti,j,t;for(j=0;j<5;j++)for(i=0;i<5-j;i++)if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}cout<<"thesortednumbers:"<
此文档下载收益归作者所有