面向對象编程教程_王育坚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 #include<iostream.h> #include<math.h> int main() { int a,b,c; int s,S; cin>>a>>b>>c; s=(a+b+c)/2; S=powl(s*(s-a)*(s-b)*(s-c),0.5); if(S==0) cout<<"此三边不能构成三角形!"<<endl; else { cout<<"面积:"<<endl; cout<<S<<endl; } return 0; } 2-46从键盘输入一个大写字母,然后改用小写字母在屏幕输出。 2-46 #include<iostream.h> int main() { char ch; int a; cout<<"输入一个大写字母:"<<endl; cin>>ch; if(ch>=65 && ch<=91) { ch=ch+32; // a=(int)ch; cout<<ch<<endl; } else cout<<"该字母不是字母或不是字母大写!"<<endl; return 0; } 2-47用户输入两个整数,编程输出稍大于第一个整数而又是第2个整数的倍数的数。计算公式是:valuel+value2-value1%value2. 2-47 #include<iostream.h> int main() { int value1,value2; int result; cin>>value1>>value2; result=value1+value2-value1%value2; cout<<"该整数为:"<<result<<endl; return 0; } 2-48华氏温度转换为摄氏温度的公式是:C=(F-32)*5/9.。编写一个程序,输入一个华氏温度,程序输出相应的摄氏温度。请将32和5/9用const型变量表示。 2-48 #include<iostream.h> int main() { const float i=32.0; const float j=5.0/9.0; float degFahr; float degCel; cin>>degFahr; // for(degFahr=0;degFahr<=300;degFahr+=10) // { degCel=j*(degFahr-i); cout<<"华氏温度:"<<degFahr<<endl; cout<<"摄氏温度:"<<degCel<<endl; // } return 0; } 2-49 从键盘输入20个整数,检查100是否存在于这些整数中,若是的话,求出他是第几个被输入的。 2-49 #include<iostream.h> int main() { int Array[20]; int i,count=0,c=0; for(i=0;i<20;i++) cin>>Array[i]; for(i=0;i<20;i++) { if(Array[i]==100 && count==0) { cout<<"100存在该数组中!"<<endl; count++; } if(Array[i]!=100) { c++; if(c==19) cout<<"100不存在该数组中!"<<endl; } } for(i=0;i<20;i++) { if(Array[i]==100) cout<<"它是第"<<i+1<<"个被输入的!"<<endl; } return 0; } 2-50 从键盘输入一个N X N的整型数组,并将每一行的最大值显示输出。 2-50 #include<iostream.h> int main() { int Array[100][100]={0}; int n,temp; cin>>n; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) cin>>Array[i][j]; for(int x=0;x<n;x++) for(int y=x+1;y<n;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;i<n;i++)

文档评论(0)

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

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

1亿VIP精品文档

相关文档