课后编程题(2章)

本章总结

题目预览

 

 题目解答

题目1

#include "stdafx.h"
#include<iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	cout << "my name is linda!"<<" my address is XXX"<<endl;
	system("pause");
	return 0;
}

  运行结果

 题目2

 1 #include "stdafx.h"
 2 #include<iostream>
 3 
 4 using namespace std;
 5 
 6 int _tmain(int argc, _TCHAR* argv[])
 7 {
 8     int dis;
 9     dis = 0;
10 
11     cout << "请输入距离:"<<endl;
12     cin >> dis;
13     cout << "您输入距离是:" << dis << "long" << endl;
14     cout << "转换后是:" << dis*220 << "" << endl;
15     system("pause");
16     return 0;
17 }

运行结果

 

 1 #include "stdafx.h"
 2 #include<iostream>
 3 
 4 using namespace std;
 5 
 6 void func1();
 7 void func2();
 8 
 9 int _tmain(int argc, _TCHAR* argv[])
10 {
11     func1();
12     func1();
13     func2();
14     func2();
15     system("pause");
16     return 0;
17 }
18 
19 void func1(){
20     cout << "Three blind mice" << endl;
21 }
22 
23 void func2(){
24     cout << "See how they run" << endl;
25 }

运行结果

  

 1 #include "stdafx.h"
 2 #include<iostream>
 3 
 4 using namespace std;
 5 
 6 
 7 
 8 int _tmain(int argc, _TCHAR* argv[])
 9 {
10     int age = 0;
11     cout << "请输入你的年龄:" << endl;
12     cin >> age;
13     cout << "换算成月份:" << age*12 << endl;
14 system("pause");
15     return 0;
16 }

运行结果

 

  

 #include "stdafx.h"
 2 #include<iostream>
 3 
 4 using namespace std;
 5 
 6 
 7 double Fahrenheit(int temp);
 8 int _tmain(int argc, _TCHAR* argv[])
 9 {
10     int temp = 0;
11     cout << "Please enter a Celsius value" << endl;
12     cin >> temp;
13     cout << temp << " degrees Celsius is " << Fahrenheit(temp) << " degrees Fahrenheit " << endl;
14     system("pause");
15     return 0;
16 }
17 
18 double Fahrenheit(int temp){
19     return 1.8*temp + 32;
20 }

运行结果

 

 

 

 1 #include "stdafx.h"
 2 #include<iostream>
 3 
 4 using namespace std;
 5 
 6 
 7 long LighYear(double temp);
 8 int _tmain(int argc, _TCHAR* argv[])
 9 {
10     double temp = 0;
11     cout << "Enter the number of light years:" << endl;
12     cin >> temp;
13     cout << temp << " light years = " << LighYear(temp) << " astronomical units " << endl;
14     system("pause");
15     return 0;
16 }
17 
18 long LighYear(double temp){
19     return temp*265608;
20 }

运行结果 

 

 

 

 1 #include "stdafx.h"
 2 #include<iostream>
 3 
 4 using namespace std;
 5 
 6 
 7 void LighYear(int hours, int minute);
 8 int _tmain(int argc, _TCHAR* argv[])
 9 {
10     int h,m;
11     cout << "Enter the number of hours:" << endl;
12     cin >> h;
13     cout << "Enter the number of minutes:" << endl;
14     cin >> m;
15     LighYear(h,m);
16     system("pause");
17     return 0;
18 }
19 
20 void LighYear(int hours, int minute){
21     cout << "Time " << hours << ":" << minute << endl;
22 }

运行结果 

posted @ 2019-10-26 11:05  大尾巴贝贝  阅读(163)  评论(0编辑  收藏  举报