预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共128页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

学习资料 C++程序设计题解与上机指导 习题程序 习题一 Xt1-5 #include<iostream> usingnamespacestd; intmain() { cout<<"This"<<"is"; cout<<"a"<<"C++"; cout<<"program."; return0; } Xt1-6 #include<iostream> usingnamespacestd; intmain() { inta,b,c; a=10; b=23; c=a+b; cout<<"a+b="; cout<<c; cout<<endl; return0; } Xt1-7 #include<iostream> usingnamespacestd; intmain() { inta,b,c; intf(intx,inty,intz); cin>>a>>b>>c; c=f(a,b,c); cout<<c<<endl; return0; } intf(intx,inty,intz) { intm; if(x<y)m=x; elsem=y; if(z<m)m=z; return(m); } Xt1-8 #include<iostream> usingnamespacestd; intmain() { inta,b,c; cin>>a>>b; c=a+b; cout<<"a+b="<<a+b<<endl; return0; } Xt1-9 #include<iostream> usingnamespacestd; intmain() { inta,b,c; intadd(intx,inty); cin>>a>>b; c=add(a,b); cout<<"a+b="<<c<<endl; return0; } intadd(intx,inty) {intz; z=x+y; return(z); } 习题二 Xt2-3 #include<iostream> usingnamespacestd; intmain() {charc1='a',c2='b',c3='c',c4='\101',c5='\116'; cout<<c1<<c2<<c3<<'\n'; cout<<"\t\b"<<c4<<'\t'<<c5<<'\n'; return0; } Xt2-4 #include<iostream> usingnamespacestd; intmain() {charc1='C',c2='+',c3='+'; cout<<"Isay:\""<<c1<<c2<<c3<<'\"'; cout<<"\t\t"<<"Hesays:\"C++isveryinteresting!\""<<'\n'; return0; } Xt2-7 #include<iostream> usingnamespacestd; intmain() {inti,j,m,n; i=8; j=10; m=++i+j++; n=(++i)+(++j)+m; cout<<i<<'\t'<<j<<'\t'<<m<<'\t'<<n<<endl; return0; } Xt2-8 #include<iostream> usingnamespacestd; intmain() {charc1='C',c2='h',c3='i',c4='n',c5='a'; c1+=4; c2+=4; c3+=4; c4+=4; c5+=4; cout<<"passwordis:"<<c1<<c2<<c3<<c4<<c5<<endl; return0; } 习题三 Xt3-2 #include<iostream> #include<iomanip> usingnamespacestd; intmain() {floath,r,l,s,sq,vq,vz; constfloatpi=3.1415926; cout<<"pleaseenterr,h:"; cin>>r>>h; l=2*pi*r; s=r*r*pi; sq=4*pi*r*r; vq=3.0/4.0*pi*r*r*r; vz=pi*r*r*h; cout<<setiosflags(ios::fixed)<<setiosflags(ios::right) <<setprecision(2); cout<<"l="<<setw(10)<<l<<endl; cout<<"s="<<setw(10)<<s<<endl; cout<<"sq="<<setw(10)<<sq<<endl; cout<<"vq="<<setw(10)<<vq<<endl; cout<<"vz="<<setw(10)<<vz<<endl; ret