C++PrimerPlus第二章课后习题自编2

2.7.1

#include <iostream>
using namespace std;

int main()
{
	cout << "姓名:张三" << endl;
	cout << "地址:武汉" << endl;

	return 0;
}

2.7.2

#include <iostream>
using namespace std;

int main()
{
	int distance; //以long为单位
	cin >> distance;
	cout << distance << " long = " << distance * 220 << "码" << endl;

	return 0;
}

2.7.3

#include <iostream>

void func1();
void func2();

int main()
{
	func1();
	func1();
	func2();
	func2();

	return 0;
}

void func1()
{
	std::cout << "Three blind mice" << std::endl;
}

void func2()
{
	std::cout << "See how they run " << std::endl;
}

2.7.4

#include <iostream>
using namespace std;

int main()
{
	int age;
	cout << "Enter your age: ";
	cin >> age;
	cout << "It is " << age * 12 << " months" << endl;

	return 0;
}

2.7.5

void convert(double n);

int main()
{
	double celsius;
	cout << "Please enter a Celsius value: ";
	cin >> celsius;
	convert(celsius);

	return 0;
}

void convert(double n)
{
	cout << n << " degrees Celsius is " << n * 1.8 + 32.0 << " degrees Fahrenheit." << endl;
}

2.7.6

#include <iostream>
using namespace std;

void convert(double n);

int main()
{
	double lightyear;
	cout << "Enter the number of light years: ";
	cin >> lightyear;
	convert(lightyear);

	return 0;
}

void convert(double n)
{
	cout << n << " light years = " << n * 63240 << " astronomical units." << endl;
}

2.7.7

#include <iostream>
using namespace std;

void showInfo(int hour, int minute);

int main()
{
	int hour;
	int minute;
	cout << "Enter the number of hours: ";
	cin >> hour;
	cout << "Enter the number of minutes: ";
	cin >> minute;
	showInfo(hour, minute);

	return 0;
}

void showInfo(int hour, int minute)
{
	cout << "Time: " << hour << ":" << minute << endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值