资源描述:
《c++面向对象程序设计课后习题答案(谭浩强版)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、第一章5:#includeusingnamespacestd;intmain(){cout<<"This"<<"is";cout<<"a"<<"C++";cout<<"program."<usingnamespacestd;intmain(){inta,b,c;a=10;b=23;c=a+b;cout<<"a+b=";cout<usingnamespacestd;intmai
2、n(){inta,b,c;intf(intx,inty,intz);cin>>a>>b>>c;c=f(a,b,c);cout<usingnamespacestd;intmain(){inta,b,c;cin>>a>>b;c=a+b;cout<<"a+b="<usi
3、ngnamespacestd;intmain(){intadd(intx,inty);inta,b,c;cin>>a>>b;c=add(a,b);cout<<"a+b="<usingnamespacestd;intmain(){voidsort(intx,inty,intz);intx,y,z;cin>>x>>y>>z;sort(x,y,z);return0;}voidsort(intx,in
4、ty,intz){inttemp;if(x>y){temp=x;x=y;y=temp;}//{}内3个语句的作用是将x和y的值互换)if(zusingnamespacestd;intmain(){intmax(inta,intb,intc=0);inta,b,c;cin>>a>>b>>c;co
5、ut<<"max(a,b,c)="<a)a=b;if(c>a)a=c;returna;}12:#includeusingnamespacestd;intmain(){voidchange(int,int);inta,b;cin>>a>>b;if(a6、0;}voidchange(int,int){intr1,r2,temp;temp=r1;r1=r2;r2=temp;}13:#includeusingnamespacestd;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<7、"<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;}14:#include#includeusingnamespacestd;intmain(){strings1="week",s2="end"
8、;cout<<"s1="<