c++ primer plus(第6版)中文版 第二章编程练习答案
来源:互联网 发布:冒险岛数据库不能用了 编辑:程序博客网 时间:2024/06/11 14:21
第二章编程联练习答案:
2.1编写一个c++程序,它显示您的姓名和住址
// 2.1编写一个c++程序,它显示您的姓名和住址#include <iostream>using namespace std;int main(){cout << "My name is dongge" << endl;cout << "My address is China"<< endl;}
2.2编写一个c++程序,它要求用户输入一个以long为单位的距离,然后把它转换为码(1 long=220码)
// 2.2编写一个c++程序,它要求用户输入一个以long为单位的距离,然后把它转换为码(1 long=220码)#include <iostream>using namespace std;int main(){int n;cout<<"输入一个以long为单位的距离:";cin>> n;cout<< "转换之后为:" << n*220 << "码" << endl; return 0; }
2.3编写一个c++程序,它使用3个用户定义的函数,并生成输出
//2.3编写一个c++程序,它使用3个用户定义的函数,并生成输出#include <iostream>using namespace std;void myFuction1(){cout<<"Three blind mice"<<endl;}void myFuction2(){cout<<"see how they run"<<endl; }int main(){ myFuction1(); myFuction1(); myFuction2(); myFuction2(); return 0; }
2.4 编写一个程序,让用户输入其年龄,然后显示包含多少个月
//2.4 编写一个程序,让用户输入其年龄,然后显示包含多少个月#include <iostream>using namespace std;int main(){ int age; cout << "请输入你的年龄:"; cin >> age; cout << "包含" << age*12 << "个月" << endl;}
2.5输入摄氏温度值,显示华氏温度=1.8*摄氏温度+32.0
//2.5输入摄氏温度值,显示华氏温度=1.8*摄氏温度+32.0#include <iostream>using namespace std;double change(double n){ return n*1.8+32.0; }int main(){ int n; cout << "please enter a Celsius valus:"; cin >> n; cout << "20 degrees Celsius is " << change(n) <<" degrees Fashrenheit" << endl;}
2.6输入摄光年,显示天文单位(1光年=63240天文单位)
//2.6输入摄光年,显示天文单位(1光年=63240天文单位)#include <iostream>using namespace std;double change(double n){ return n*63240; }int main(){ double n; cout << "Enter the number of light years:"; cin >> n; cout << n << " light years = " << change(n) << " astronmical units" << endl;}
2.7编写一个程序,输入小时和分钟,显示时间
//2.7编写一个程序,输入小时和分钟,显示时间#include <iostream>using namespace std;void show(int h,int m){cout << "Time: " << h << ":" << m << endl;}int main(){int h,m;cout << "Enter the number of hours:";cin >> h;cout << "Enter the number of minutes:";cin >> m;show(h,m);}
1 0
- c++ primer plus(第6版)中文版 第二章编程练习答案
- c++ primer plus(第6版)中文版 第三章编程练习答案
- c++ primer plus(第6版)中文版 第四章编程练习答案
- c++ primer plus(第6版)中文版 第五章编程练习答案
- c++ primer plus(第6版)中文版 第六章编程练习答案
- c++ primer plus(第6版)中文版 第七章编程练习答案
- c++ primer plus(第6版)中文版 第八章编程练习答案
- c++ primer plus(第6版)中文版 第九章编程练习答案
- c++ primer plus(第6版)中文版 第十章编程练习答案
- c++ primer plus(第6版)中文版 第十一章编程练习答案
- c++ primer plus(第6版)中文版 第十二章编程练习答案
- c++ primer plus(第6版)中文版 第十三章编程练习答案
- C++Primer Plus第6版 4.13编程练习答案
- 《C Primer Plus(第5版)中文版》第6章编程练习第1题
- 《C Primer Plus(第5版)中文版》第6章编程练习第14题
- 《C Primer Plus(第5版)中文版》第6章编程练习第15题
- 《C Primer Plus(第5版)中文版》第6章编程练习第16题
- 《C Primer Plus(第5版)中文版》第7章编程练习第6题
- 如何学习
- ACM-博弈之Good Luck in CET-4 Everybody!——hdu1847
- 敏捷开发—初识庐山真面目
- ubuntu下安装 php的solr扩展
- 安装CTEX,系统path找回方法
- c++ primer plus(第6版)中文版 第二章编程练习答案
- 防守阵地 II
- 【C/C++多线程编程之六】pthread互斥量
- Android高级---Wifi,照相知识笔试题
- hdu 1054
- 为什么在使用WSAAsynSelect时会一直响应FD_ACCEPT消息
- Unity3D中JavaScript与C#对比
- hdu1427
- 浅谈c语言typedef 与结构体指针(个人小经验)