面向對象编程教程_王育坚VC__第2版_第二章课后习题.doc

面向對象编程教程_王育坚VC__第2版_第二章课后习题.doc

  1. 1、本文档共24页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
面向對象编程教程_王育坚VC__第2版_第二章课后习题

2-45编写一个程序,输入三角形的三条边的边长,求三角形的面积。 2-45 #includeiostream.h #includemath.h int main() { int a,b,c; int s,S; cinabc; s=(a+b+c)/2; S=powl(s*(s-a)*(s-b)*(s-c),0.5); if(S==0) cout此三边不能构成三角形!endl; else { cout面积:endl; coutSendl; } return 0; } 2-46从键盘输入一个大写字母,然后改用小写字母在屏幕输出。 2-46 #includeiostream.h int main() { char ch; int a; cout输入一个大写字母:endl; cinch; if(ch=65 ch=91) { ch=ch+32; // a=(int)ch; coutchendl; } else cout该字母不是字母或不是字母大写!endl; return 0; } 2-47用户输入两个整数,编程输出稍大于第一个整数而又是第2个整数的倍数的数。计算公式是:valuel+value2-value1%value2. 2-47 #includeiostream.h int main() { int value1,value2; int result; cinvalue1value2; result=value1+value2-value1%value2; cout该整数为:resultendl; return 0; } 2-48华氏温度转换为摄氏温度的公式是:C=(F-32)*5/9.。编写一个程序,输入一个华氏温度,程序输出相应的摄氏温度。请将32和5/9用const型变量表示。 2-48 #includeiostream.h int main() { const float i=32.0; const float j=5.0/9.0; float degFahr; float degCel; cindegFahr; // for(degFahr=0;degFahr=300;degFahr+=10) // { degCel=j*(degFahr-i); cout华氏温度:degFahrendl; cout摄氏温度:degCelendl; // } return 0; } 2-49 从键盘输入20个整数,检查100是否存在于这些整数中,若是的话,求出他是第几个被输入的。 2-49 #includeiostream.h int main() { int Array[20]; int i,count=0,c=0; for(i=0;i20;i++) cinArray[i]; for(i=0;i20;i++) { if(Array[i]==100 count==0) { cout100存在该数组中!endl; count++; } if(Array[i]!=100) { c++; if(c==19) cout100不存在该数组中!endl; } } for(i=0;i20;i++) { if(Array[i]==100) cout它是第i+1个被输入的!endl; } return 0; } 2-50 从键盘输入一个N X N的整型数组,并将每一行的最大值显示输出。 2-50 #includeiostream.h int main() { int Array[100][100]={0}; int n,temp; cinn; for(int i=0;in;i++) { for(int j=0;jn;j++) cinArray[i][j]; for(int x=0;xn;x++) for(int y=x+1;yn;y++) if(Array[i][x]Array[i][y]) { temp=Array[i][x]; Array[i][x]=Array[i][y]; Array[i][y]=temp; } } cout每一行的最大值:endl; for(i=0;in;i++) coutArray[i][0] ; coutendl; } 2-51 输入三个整数,采用指针方法将三个数按从大到小的顺序输出。 2-51 #includeiostream.h #includemath.h int main() { int Array[3]; int

文档评论(0)

dbtx + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档