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

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

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

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

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

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

C++程序设计题解与上机指导 教材例题程序 第一章 Ch1-1 #include usingnamespacestd; intmain() { cout>a>>b; sum=a+b; couty)z=x; elsez=y; return(z); } intmain() {inta,b,m; cin>>a>>b; m=max(a,b); cout>a>>b; c=max(a,b); couty)z=x; elsez=y; return(z); } Ch1-4 #include usingnamespacestd; classStudent { private: intnum; intscore; public: voidsetdata() { cin>>num; cin>>score; } voiddisplay() { cout usingnamespacestd; intmain() { doublea=123.456,b=3.14159,c=-3214.67; cout usingnamespacestd; intmain() {floata,b,c,x1,x2; cin>>a>>b>>c; x1=(-b+sqrt(b*b-4*a*c))/(2*a); x2=(-b-sqrt(b*b-4*a*c))/(2*a); cout #include usingnamespacestd; intmain() { doublea,b,c; cout>a>>b>>c; if(a+b>c&&b+c>a&&c+a>b) { doubles,area; s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c)); cout>ch; ch=(ch>='A'&&ch>year; if(year%4==0) {if(year%100==0) {if(year%400==0) leap=true; elseleap=false;} else leap=true;} else leap=false; if(leap) cout>p>>w>>s; if(s>=3000)c=12; elsec=s/250; switch(c) {case0:d=0;break; case1:d=2;break; case2: case3:d=5;break; case4: case5: case6: case7:d=8;break; case8: case9: case10: case11:d=10;break; case12:d=15;break; } f=p*w*s*(1-d/100.0); cout usingnamespacestd; intmain() {ints=1; doublen=1,t=1,pi=0; while((fabs(t))>1e-7) {pi=pi+t; n=n+2; s=-s; t=s/n; } pi=pi*4; cout #include usingnamespacestd; intmain() {intm,k,i,n=0; boolprime; for(m=101;m='a'&&c='A'&&c'Z'&&c'z')c=c-26; } couty?x:y; return(z); } intmain() {inta,b,c; cout>a>>b; c=max(a,b); cout>a>>b; c=add(a,b); couta)a=b; if(c>a)a=c; returna; } Ch4-5 #include usingnamespacestd; intmain() {intmax(inta,intb,intc); doublemax(doublea,doubleb,doublec); longmax(longa,longb,longc); inti1,i2,i3,i; cin>>i1>>i2>>i3; i=max(i1,i2,i3); cout>d1>>d2>>d3; d=max(d1,d2,d3); cout>g1>>g2>>g3; g=max(g1,g2,g3); couta)a=b; if(c>a)a=c; returna; } doublemax(doublea,doubleb,doublec) {if(b>a)a=b; if(c>a)a=c; returna; } longmax(longa,longb,