资源描述:
《【编程课件】c++程序设计教程实验答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C++程序设计教程实验答案实验1.1#include"iostream.h"#include"iomanip.h"voidmain(){intx;cin>>x;inty;y=xx;cout<<"xx="<<hex<<y<<endl;}实验1.2#include"iostream.h"voidmain(){floatx=1,y=2,h=3,s;s=h(x+y)/2.0;cout<<"上底为
2、1,下底为2,高为3的梯形面积为:"<<s<<endl;}1实验1.3#include"iostream.h"voidmain(){floatx,y,z,s;cout<<"请输入三门成绩x,y,z:"<<endl;cin>>x>>y>>z;s=(x+y+z)/3;cout<<"三门课平均成绩为:"<<s<<endl;}2实验2.1#include"i
3、ostream.h"#include"iomanip.h"voidmain(){floats1,s2,s3;doubleaver;cout<<"输入三个数据:"<<endl;cin>>s1>>s2>>s3;aver=(s1+s2+s3)/3;aver=aver100+0.5;aver=(int)aver;aver=aver/100;cout<<"平均值="<<aver<<endl;}
4、3实验2.2#include"iostream.h"#include"math.h"voidmain(){doublex,y,z;cout<<"请输入直角三角形的两直角边长:"<<endl;cin>>x>>y;z=sqrt(xx+yy);cout<<"该直角三角形的斜边长为:"<<z<<endl;}实验2.4#include"iostream.h"voidmain(
5、){doublea,b,c,t,ave;cout<<"请输入三个数"<<endl;cin>>a>>b>>c;if(a<b)t=a;elset=b;if(t<c)t=t;elset=c;ave=(a+b+c)/3;4cout<<"三个数的平均值为"<<ave<<",其中最小的数为:"<<t<<endl;}实验2.3#include"iostream.
6、h"voidmain(){doublex,y,r,t;cout<<"请输入xy"<<endl;cin>>x>>y;r=xx+yy;if(r<=16&&r>=4)t=123.1415926;elset=0;cout<<t<<endl;}实验2.5#include"iostream.h"5voidmain(){charc1=‘f’,c2=‘l’,c3=‘y’;cout<<c1<<
7、c2<<c3<<endl;c1=c1+3;c2=c2+3;c3=c3+3;if(c1>’z’)c1=c1-26;if(c2>’z’)c2=c2-26;if(c3>’z’)c3=c3-26;cout<<c1<<c2<<c3<<endl;}实验3.1#include"iostream.h"voidmain(){intx,y;floatr1,r2;cin>>x>>y;if(x==0y==0)cout<<&qu
8、ot;inputerror"<<endl;else{if(x>y){r1=x/y;r2=x%y;}else6