最近开始刷书 希望别半途而废吧
第二章编程练习本人的答案如下,欢迎讨论纠错
#include <iostream>
using namespace std;
void question1();
void question2();
void question3_1();
void question3_2();
void question4();
void question5();
void question6();
void question7(int hours , int minutes);
int main()
{
/*
question3_1();
question3_1();
question3_2();
question3_2();
*/
int hours , minutes;
cout << "Enter the number of hours: ";
cin >> hours;
cout << "Enter the number of minutes: ";
cin >> minutes;
question7(hours , minutes);
return 0;
}
void question1()
{
string name , address;
cout << "Enter your name:";
cin >> name;
cout << endl;
cout << "Enter your address:";
cin >> address;
cout << endl;
cout << "My name is " << name << endl;
cout << "My address is " << address;
return;
}
void question2()
{
double dis;
cout << "enter the district in long : ";
cin >> dis;
cout << endl;
cout << "the district in ma : " << 220 * dis << endl;
return;
}
void question3_1()
{
cout << "Three blind mice" << endl;
return;
}
void question3_2()
{
cout << "See how they run" << endl;
}
void question4()
{
int age;
cout << "Enter your age: ";
cin >> age;
cout << endl;
cout << "which means " << age * 12 << " months" << endl;
return;
}
void question5()
{
double value;
cout << "Please enter a Celsius value: ";
cin >> value;
cout << endl;
cout << value << " degrees Celsius is " << 1.8 * value + 32.0 << " degrees Fahrenheit." << endl;
return;
}
void question6()
{
double value;
cout << "Enter the number of light years: ";
cin >> value;
cout << endl;
cout << value << " light years = " << 63240 * value << " astronomical units." << endl;
return;
}
void question7(int hours , int minutes)
{
cout << "Time: " << hours << ":" << minutes << endl;
}