C++ Primer Plus 编程练习2.7

// 2.7编程练习
#include <iostream>
using namespace std;

//1.
int main1()
{
	cout << "My name is HX, LIve in WuHan"<<endl;
	return 0;
}

//2.
double longtoma(double);
int main2()
{
	double lo;
	cout <<"Enter the long: ";
	cin >> lo;
	double m = longtoma(lo);
	cout << lo << " long="<<m <<" ma" << endl;
	return 0;
}
double longtoma(double l)
{
	return 220 * l;
}

//3.
void mice();
void see();
int main3()
{
	mice();
	mice();
	see();
	see();
	return 0;
}
void mice()
{
	cout << "Three blind mice" << endl;
} 
void see()
{
	cout << "See how they run" << endl;
}

//4.
int main4()
{
	int age;
	cout << "Enter your age: ";
	cin >> age;
	int month = 12 * age;
	cout <<age<< " years is " << month << " months. " << endl;
	return 0;
}

//5.
double C2F(double);
int main5()
{
	double Celsius = 0.0;
	cout << "Please enter a Celsius value : ";
	cin >> Celsius;
	double Fahrenheit = C2F(Celsius);
	cout << Celsius << " degrees Celsius is " << Fahrenheit << " degrees Fahrenheit." << endl;
	return 0;
}
double C2F(double t)
{
	return (1.8 * t + 32.0);
}

//6.
double convert(double);
int main6()
{
	double light_year;
	cout << "Enter the number of light years: ";
	cin >> light_year;
	double astro_units = convert(light_year);
	cout << light_year << " light years = " << astro_units << " astronomical units . " << endl;
	return 0;
}
double convert(double t)
{
	return 63240* t;
}

//7.
void time(int h, int m);
int main()
{
	int hour, minutes;
	cout << "Enter the number of hours: ";
	cin >> hour;
	cout << "Enter the number of minutes: ";
	cin >> minutes;
	time(hour,minutes);
	return 0;
}
void time(int h,int m)
{
	cout << "Time: " << h << ":" << m << endl;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值