C++ Primer plus第六版 2.7编程练习

1.
#include <iostream>

int main() {
	using namespace std;
	cout << "my name " << "my address" << endl;
	return 0}
2.
#include <iostream>

int main() {
	using namespace std;
	int dis;
	cout << "请输入一个以long为单位的距离:";
	cin >> dis;
	cout << "转码结果为:" << dis * 220 << "码.";
	return 0}
3.
#include <iostream>

void state();         //标明函数头
void method();

int main() {
	state();
	state();
	method();
	method();
	return 0;
}
//函数定义
void state() {
	using namespace std;
	cout << "Three blind  mice." << endl;
}

void method() {
	using namespace std;
	cout << "See how they run." << endl;
}
4.
#include <iostream>

int agetomonth(int);

int main() {
	using namespace std;
	int age;
	cout << "Enter your age: ";
	cin >> age;
	cout << "age to month: " << agetomonth(age);
	return 0;
}

int agetomonth(int age) {
	int month;
	month = age * 12;
	return month;
}
5.
#include <iostream>

double cvalueTofvalue(double);

int main() {
	using namespace std;
	double cvalue;
	cout << "Please enter a Celsius value: ";
	cin >> cvalue;
	cout << cvalue << " degrees Celsius is " << cvalueTofvalue(cvalue) 
		<< " degrees Fahreheit.";
	return 0;
}

double cvalueTofvalue(double cvalue) {
	int fvalue;
	fvalue = cvalue * 1.8 + 32.0;
	return fvalue;
}
6.
#include <iostream>

double light_years_to_astro_units(double);

int main() {
	using namespace std;
	double light_years;
	cout << "Enter the number of light years: ";
	cin >> light_years;
	cout << light_years << " light years = " << light_years_to_astro_units(light_years) 
		<< " astronomical units.";
	return 0;
}

double light_years_to_astro_units(double light_years) {
	int astro_units;
	astro_units = light_years * 63240;
	return astro_units;
}
7.
#include <iostream>

void visualTime(int, int);

int main() {
	using namespace std;
	int hours;
	int minutes;
	cout << "Enter the number of hours: ";
	cin >> hours;
	cout << "Enter the number of minutes: ";
	cin >> minutes;
	visualTime(hours, minutes);
	return 0;
}

void visualTime(int hours, int minutes) {
	using namespace std;
	/*if (hours > 12 || hours < 0) {
		cout << "hours 数值输入错误!" << endl;
		return;
	}
	if (minutes > 60 || minutes < 0) {
		cout << "minutes 数值输入错误!" << endl;
		return;
	}*/
	cout << "Time: " << hours << ':' << minutes;

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值