C++程序设计教程第2版高等教育出版社第15章答案.docx
- 文档编号:15446241
- 上传时间:2023-07-04
- 格式:DOCX
- 页数:40
- 大小:22.79KB
C++程序设计教程第2版高等教育出版社第15章答案.docx
《C++程序设计教程第2版高等教育出版社第15章答案.docx》由会员分享,可在线阅读,更多相关《C++程序设计教程第2版高等教育出版社第15章答案.docx(40页珍藏版)》请在冰点文库上搜索。
C++程序设计教程第2版高等教育出版社第15章答案
第一章
//修改例1-1的HelloWorldstudent,andIlikeprogramming!
#include
程序,使其能够在计算机屏幕上显示
“。
"Iama
{
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 { charname1[41],name2[41],date[41]; cout<<"请输入你的朋友的名字: "< cin>>name1; cout<<"请输入你的名字: "< cin>>name2; cout<<"请输入日期"< cin>>date; system("cls"); cout<<"=========================================="< "< cout<<"祝你生日快乐! "< cout<<""< cout<<"=========================================="< cout<<""< system("pause>nul"); return0; } /*参考例1-5,使用梯形法计算下列定积分的值 (sinx+e^x)dx[上限1,下限-1] 其中,积分区域等分数取为200,并比较计算结果和手算结果的。 */#include #include usingnamespacestd; intmain() { doublea,b,h,sum; intn,i; a=1.00; // 积分上限为1 b=-1.00; // 积分下限为-1 n=200; // 积分区间等分为200份 h=(a-b)/n; // 小区间长度 sum=(exp(a)+exp(b))/2;//exp()for(i=1;i 为计算 e^x 的函数库 cout<<"结果是"< system("pause>nul"); return0; } //仿照例1-6,编写一个计算矩形面积的程序 #include usingnamespacestd; doublesquare(doublea,doubleb)//定义 { doubles; s=a*b; returns; } intmain() { doublelength,wideth,mianji; cout<<"请输入长度: "< cin>>length; square 函数 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"); cout<<"面积为: "< system("pause>nul"); return0; } else cout<<"Errordata! "; system("pause>nul"); return0; } //输入两个角度值x,y,计算式子[sin(|x|+|y|)]/[√cos(|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"); cout<<"你输入的是"<nul");d=a+b+c; system("cls"); cout< system("echo按任意键继续&pause>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<<"你输入的数进行四舍五入后是"<nul");return0; } //从键盘输入任意3个整数,然后输入这3个数并计算平均值 #include { doublea,b,c,d; system("color1e"); cout<<"请输入三个整数: "< cin>>a>>b>>c; system("cls"); cout<<"这三个整数是: "< system("pause>nul"); d=(a+b+c)/3; system("cls"); cout<<"这三个整数的平均数为: "< system("pause>nul"); return0; } //编写一个程序,将字符串"LOVE"译成密码,采用替换加密法,加密规则为原来 的字母用字母表中其后面的第三个字母替换,例如c用f替换,y用b替换 #include usingnamespacestd; intmain() { chara='L',b='O',c='V',d='E'; a=a+3; b=b+3; c=c+3; d=d+3; system("color1e"); cout<<"翻译成密文为:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 程序设计 教程 高等教育出版社 15 答案