练习的题目:
Three blind mice
Three blind mice
See how they run
See how they run
Enter your age: 29
You have lived 348 monthes
Please enter a value: 20
20 degrees Fahrenheit is 68 degrees Celsius.
Enter the number of light years: 4.2
4.2 light year = 265608 astronomicla units.
Enter the number of hour: 9
Enter the number of minute: 28
Time: 9:28
练习的代码:
#include<iostream>
using namespace std;
string namestress(int); //1_
string BlindMice(void); //3_
string HowRun(void); //3_
double TemConvert(char,double); //5_
double LAConvert(double); //6_
string Hmt(string,string); //7_
int main()
{
int Inunm=1;
string TipInformation="请输入要使用的功能代码:";
cout << "1_Personal Information Inquire System\n2_long-Mile Convert System\n3_User Function Output System\n4_Age-Monthes Convert System\n"
<< "5_TemConvert System\n6_LightYear-AstronomicalUnit Conver System\n7_HourMinuteTime System\n0_quit\n\n";
while (Inunm > 0)
{
cout << TipInformation;
cin >> Inunm;
switch (Inunm)
{
case 1: //1_Personal Information Inquire System
{
int Qnumber=1;//定义/初始化变量Qnumber
while (Qnumber>0)
{
cout << "\nWelcome to Personal Information Inquire System\n";
cout << "1_name,2_stress: ";
cin >> Qnumber;//更新变量Qnumber
cout << namestress(Qnumber) << endl;//传递变量Qnumber,变量值不符合namestress()函数要求使会报错
cout << "1_name,2_stress,0_backspace: ";
cin >> Qnumber;
}
break;
}
case 2: //2_long-Mile Convert System
double ConvertLM;
cout << "\nWelcon to long-Mile Convert System\n";
cout << "Enter a double of long: ";
cin >> ConvertLM;
cout << endl << ConvertLM << " long equal " << ConvertLM * 220 << " miles\n\n";
break;
case 3: //3_User Function Output System
cout << "\nWelcom to User Function Output Syetem\n\n";
cout << BlindMice()<< BlindMice();
cout << HowRun() << HowRun() << endl;
break;
case 4: //4_Age-Monthes Convert System
int age;
cout << "\nWelcom to Age-Monthes Convert System\n";
cout << "Enter your age: ";
cin >> age;
cout << "\nYou have lived " << age * 12 << " monthes\n\n";
break;
case 5: //5_TemConvert System
{//初始化被“case”标签跳过:将初始化包含在块中
char Tem; double Temnum; string Temp; string Tempt;
cout << "\nWelcom to TemConvert System\n";
cout << "Celsius to Fahrenheit,Enter 'C': ";
cin >> Tem;
cout << "Please enter a value: ";
cin >> Temnum;
if (Tem == 'C')
{
Temp = "Fahrenheit";
Tempt = "Celsius";
}
if (Tem == 'F')
{
Temp = "Celsius";
Tempt = "Fahrenteit";
}
cout << Temnum << " degrees " << Temp << " is " << TemConvert(Tem,Temnum) << " degrees "<<Tempt<<".\n\n";
break;
}
case 6: //6_LightYear-AstronomicalUnit Conver System
double c;
cout << "\nWelcom to LightYear-AstronomicalUnit Conver System\n";
cout << "Enter the number of light years: ";
cin >> c;
cout << c << " light year = " << LAConvert(c) << " astronomicla units.\n\n";
break;
case 7: //7_HourMinuteTime System
string hou; string min;
cout << "\nWelcom to HourMinuteTime System\n";
cout << "Enter the number of hour: ";
cin >> hou;
cout << "Enter the number of minute: ";
cin >> min;
cout << "Time: " << Hmt(hou, min) << endl;
break;
}
cout << "\n0_quit,1_continue: ";
cin >> Inunm;
cout << endl;
}
cout << "Thanks for your conversation!\n\n";
return 0;
}
string namestress(int a)
{
string name = "name:TianlongHu\n";
string stress = "stress:01-01,BaigaVillage,QianxinTown,HuidongContry,LiangshanState,SichuanProvence,China\n";
if (a == 1)
{
return name;
}
else if (a == 2)
{
return stress;
}
}
string BlindMice(void)
{
string a = "Three blind mice\n";
return a;
}
string HowRun(void)
{
string a = "See how they run\n";
return a;
}
double TemConvert(char a,double b)
{
if (a == 'C')
{
return b * 1.8 + 32;
}
if (a == 'F')
{
return (b - 32) / 1.8;
}
}
double LAConvert(double a)
{
double b;
b = a * 63240;
return b;
}
string Hmt(string a, string b)
{
string c; string d=":";
c = a+d+b;
return c;
}