/***********************************
2017年9月23日13:12:16
Athor:xiyuan255
Course:C++
Contain:myfirst.cpp
Reference: C++ Primer plus
說明:C++ Primer plus第二章的練習題(選取部分)
【 P35 】
*************************************/
// review2.cpp -- C++ Primer plus 第二章練習題
#include <iostream>
void ageToMonth(void);
void temperatureFunc(void);
void timeFunc(void);
using namespace std;
int main(void)
{
//ageToMonth(); // test 1
//temperatureFunc(); // test 2
timeFunc(); // test 3
return 0;
}
void ageToMonth(void)
{
cout << "Enter your age: ";
int age;
cin >> age;
cout << age << " age = " << (age*12) << " month." << endl;
}
/**
輸出結果:
Enter your age: 29
29 age = 348 month.
*/
int celsiusToFahrenheit(int celsius)
{
return (int)(celsius * 1.8 + 32.0);
}
void temperatureFunc(void)
{
cout << "Please enter a Celsius value: ";
int celsius;
cin >> celsius;
int fahrenheit;
fahrenheit = celsiusToFahrenheit(celsius);
cout << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit.\n";
}
/**
輸出結果:
Please enter a Celsius value: 20
20 degrees Celsius is 68 degrees Fahrenheit.
*/
void hoursAndMinutesToTime(int hours, int minutes)
{
cout << "Time: " << hours << ":" << minutes << endl;
}
void timeFunc(void)
{
cout << "Enter the number of hours: ";
int hours;
cin >> hours;
cout << "Enter the number of minutes: ";
int minutes;
cin >> minutes;
hoursAndMinutesToTime(hours, minutes);
}
/**
輸出結果:
Enter the number of hours: 9
Enter the number of minutes: 28
Time: 9:28
*/
【第二章】C++ Primer plus 的編程練習題(選取部分)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.