C++程序设计教程第2版高等教育出版社第15章答案.docx
- 文档编号:7383717
- 上传时间:2023-01-23
- 格式:DOCX
- 页数:30
- 大小:22.84KB
C++程序设计教程第2版高等教育出版社第15章答案.docx
《C++程序设计教程第2版高等教育出版社第15章答案.docx》由会员分享,可在线阅读,更多相关《C++程序设计教程第2版高等教育出版社第15章答案.docx(30页珍藏版)》请在冰豆网上搜索。
C++程序设计教程第2版高等教育出版社第15章答案
第一早
//修改例1-1的HelloWorld程序,使其能够在计算机屏幕上显示"Iama
student,andIlikeprogramming!
“。
#include
usingnamespacestd;
intmain()
{
cout<<"Iamastudent,andIlikeprogramming!
"< system("pause>nul"); return0; } //修改例1-3的加法计算器程序,编写一个乘法计算器程序 #include usingnamespacestd; intmain() { doublea,b,c; cout«"请输入两个数字"< cin>>a>>b; c=a*b; cout< system("pause>nul"); return0; } //修改例1-4的生日卡程序,使其能够输入和显示日期 #include usingnamespacestd; intmain() { charname1[41],name2[41],date[41]; coutvv"请输入你的朋友的名字: "< cin>>name1; cout«"请输入你的名字: "< cin>>name2; cout<<"请输入日期"< cin>>date; system("cls"); cout<<"=========================================="< "< cout<<"祝你生日快乐! "< cout<<""< cout<<"=========================================="< "vvdatevv cout«" endl; system("pause>nul");return0; } /*参考例1-5,使用梯形法计算下列定积分的值 (sinx+eAx)dx[上限1,下限-1] 其中,积分区域等分数取为200,并比较计算结果和手算结果的。 #include #include usingnamespacestd; intmain() { doublea,b,h,sum; intn,i; a=1.00;II积分上限为1 b=-1.00;II积分下限为-1 n=200;II积分区间等分为200份 h=(a-b)In;II小区间长度 sum=(exp(a)+exp(b))/2;IIexp()为计算eAx的函数库for(i=1;i sum=sum+exp(b+i*h); sum=sum*h; cout«"结果是"vvsumvvendl; system("pause>nul"); return0; } II仿照例1-6,编写一个计算矩形面积的程序 #include usingnamespacestd; doublesquare(doublea,doubleb)II定义square函数 { doubles; s=a*b; returns; } intmain() { doublelength,wideth,mianji; cout«"请输入长度: "< cin>>length; cout<<"请输入宽度: "< cin>>wideth; mianji=square(length,wideth);system("cls"); cout«"面积为: "< system("pause>nul"); return0; } 第二章 //为例2-2添加数据检验部分。 给出三边长,检验其是否能构成一个三角形。 如 果检验不合格,输入信息“Errordata! ”。 #include #include usingnamespacestd; intmain() { doublea,b,c,s,area;system("title三角形面积计算程序-bylyz810"); system("color1e"); cout<<"请分别输入三边长a,b,c的值: "; cin>>a>>b>>c; if(a+b>c&&b+c>a&&a+c>b) { s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c));system("cls"); coutvv"面积为: "vvareavvendl; system("pause>nul"); return0; } else cout<<"Errordata! ";system("pause>nul"); return0; } //输入两个角度值x,y,计算式子[sin(|x|+|y|)]/[Vcos(|x+y|)] #include #include usingnamespacestd; intmain() { system("title计算式子的值-bylyz810"); system("color1e"); doublex,y,z,pi=3.1415926536,a,b,c,d;cout«"请分别输入x和y的值(角度): ";cin>>x>>y; x=pi*x/180; y=pi*y/180; c=fabs(x)+fabs(y); d=cos(fabs(x+y)); a=sin(c); b=sqrt(d); z=a/b; system("cls"); cout«"原式="< system("pause>nul"); return0; } /*编写一个程序,要求完成以下要求: 1.提示用户输入3个小数 2.显示这3个小数 3.将这三个小数相加并显示其结果 4.将结果按四舍五入发转换成整数并显示*/ #include usingnamespacestd; intmain() { longdoublea,b,c,d; system("color1e"); cout«"请输入3个小数: "< cin>>a>>b>>c; system("cls"); coutvv"你输入的是"<nul");d=a+b+c; system("cls");cout<nul"); if(a-int(a)<0.5) a=int(a); else a=int(a)+1; if(b-int(b)<0.5) b=int(b); else b=int(b)+1; if(c-int(c)<0.5) c=int(c); else c=int(c)+1; system("cls"); cout«"你输入的数进行四舍五入后是"<"< return0; } //从键盘输入任意3个整数,然后输入这3个数并计算平均值 #include usingnamespacestd; intmain() { doublea,b,c,d; system("color1e"); cout«"请输入三个整数: "< cin>>a>>b>>c; system("cls"); cout«"这三个整数是: "<"< system("pause>nul"); d=(a+b+c)/3; system("cls"); coutvv"这三个整数的平均数为:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 程序设计 教程 高等教育出版社 15 答案
![提示](https://static.bdocx.com/images/bang_tan.gif)