#include <iostream>
using namespace std;
int main(){
cout<<"姓名:Thomas"<<endl;
cout<<"地址:重庆市"<<endl;return0;}
2.7.2
#include <iostream>
using namespace std;
int main(){
int dis_long;
int dis_yard;
cout<<"please input the int distance value as long:"<<endl;
cin>>dis_long;
dis_yard=dis_long*220;
cout<<"you has input the distance: "<<dis_long<<" long,"<<" equal to "<<dis_yard<<" yard."<<endl;return0;}
2.7.3
#include <iostream>
using namespace std;voidfun_1();voidfun_2();
int main(){fun_1();fun_1();fun_2();fun_2();return0;}voidfun_1(){
cout<<"Three blind mice"<<endl;}voidfun_2(){
cout<<"See how they run"<<endl;}
2.7.4
#include <iostream>
using namespace std;
int main(){
int age;
cout<<"Please input your age:"<<endl;
cin>>age;//据cin>>a 中a的变量类型读取数据,遇到结束符(Space、Tab、Enter)就结束//cin.get();//cin.get() 与 cin.get(char ch)用于读取字符,他们的使用是相似的,即:ch=cin.get() 与 cin.get(ch)是等价的
cout<<"Your age contains "<<age*12<<" months.";return0;}
2.7.5
#include <iostream>
using namespace std;
double cel_to_Fah(double Celsius){
double Fahrenheit;
Fahrenheit=1.8*Celsius+32.0;return Fahrenheit;}
int main(){
double temp_Celsius;
cout<<"Please enter a Celsius value:"<<endl;
cin>>temp_Celsius;
cout<<temp_Celsius<<" degrees Celsius is "<<cel_to_Fah(temp_Celsius)<<" degrees Fahrenheit"<<endl;return0;}
2.7.6
#include <iostream>
using namespace std;
double lig_to_ast(double light_years){
double astronomical;
astronomical=63240*light_years;return astronomical;}
int main(){
double light_years;
cout<<"Please enter the number of light years:"<<endl;
cin>>light_years;
cout<<light_years<<" light_years = "<<lig_to_ast(light_years)<<" astronomical units"<<endl;return0;}
2.7.7
#include <iostream>
using namespace std;voidprint_time(int hour, int min){
cout<<"Time "<<hour<<":"<<min<<endl;}
int main(){
int ent_hour;
int temp_hour;
int ent_min;
int temp_min;
cout<<"Please enter the number of hours:"<<endl;
cin>>temp_hour;while(temp_hour>24||temp_hour<0){
cout<<"Wrong hours, please enter the number of hours again:"<<endl;
cin>>temp_hour;}
ent_hour=temp_hour;
cout<<"Please enter the number of minutes:"<<endl;
cin>>temp_min;while(temp_min>60||temp_min<0){
cout<<"Wrong minutes, please enter the number of minutes again:"<<endl;
cin>>temp_min;}
ent_min=temp_min;print_time(ent_hour, ent_min);return0;}
C++ Primer Plus 第六版 第二章习题2.7.1#include <iostream>using namespace std;int main(){ cout<<"姓名:Thomas"<<endl; cout<<"地址:重庆市"<<endl; return 0;}2.7.2#inclu...