第2章 开始学习C++

练习的题目:

在这里插入图片描述

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孤月小酌

o(* ̄▽ ̄*)ブ谢谢老板

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值