[筆記]C++ Primer Plus(第6版)第二章習題

好好學習c++,堅持編程。

#include "iostream"
using namespace std;

void fun_one();
void fun_two();
double temp(double c);
double light(double year);
void time(int h, int min);

int main()
{   
	//2.7.1
	cout << "my name is XXX" << endl;
	cout << "address:XXX" << endl;
	//2.7.2
	double distance;
	cout << "enter distance";
	cin >> distance;
	cout << distance << "(long)=";
	distance = 220 * distance;
	cout << distance << "(碼)" << endl;
    //2.7.3
	fun_one();
	fun_one();
	fun_two();
	fun_two();
	//2.7.4
	cout << "enter your age:";
	int age;
	cin >> age;
	cout << "month:" << age * 12 << endl;
	//2.7.5
	double c;
	cout << "please enter a celsius value:";
	cin >> c;
	cout << c << " degrees celsius is " << temp(c) << " degrees fahrenheit" << endl;
	//2.7.6
	double y;
	cout << "enter the number of light years:";
	cin >> y;
	cout << y << " light year = " << light(y) << " astronomical units" << endl;
	//2.7.7
	int h;
	int min;
	cin >> h;
	cin >> min;
	time(h, min);
	cin.get();
    return 0;
}

void fun_one() {
	cout << "Three blind mice " << endl;
}

void fun_two() {
	cout << "see how they run" << endl;
}

double temp(double c) {
	double f;
	f = 1.8*c + 32.0;
	return f;
}

double light(double year) {
	double a;
	a = year * 63240;
	return a;
}

void time(int h, int min) {
	cout << "enter the number of hours :" << h << endl;
	cout << "enter the number of minutes :" << min << endl;
	cout << "time :" << h << ":" << min;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章