欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C Primer plus 第六版 第二章课后习题答案

程序员文章站 2024-02-29 11:57:10
...

C Primer plus 第六版 第二章课后习题答案

第一题
#include <iostream>
using std::cout;
using std::endl;
int main() {
	cout << "BeanGuohui" << endl;
	cout << "成都" << endl;
	getchar();
}
第二题
#include <iostream>
#include <Windows.h>
using std::cin;
using std::cout;
using std::endl;

int main() {
	cout << "请输入一个以long为单位的距离:";
	double distance;
	cin >> distance;
	cout << distance << " long = " << distance * 220 << " 码" << endl;
	system("pause");

}
第三题
#include <iostream>
#include <Windows.h>
using std::cout;
using std::cin;
using std::endl;

void FirstPrint(){
	cout << "Three blind mice" << endl;
}
void SecondPrint() {
	cout << "See how they run" << endl;
}

int main() {
	FirstPrint();
	FirstPrint();
	SecondPrint();
	SecondPrint();
	system("pause");
}

第四题
#include <iostream>
#include <Windows.h>
using std::cout;
using std::cin;
using std::endl;

int main() {
	cout << "Enter your age: ";
	int age = 0;
	cin >> age;
	cout << "该年龄包含" << age * 12 << "个月!" << endl;
	system("pause");

}
第五题
#include <iostream>
#include <Windows.h>
using std::cout;
using std::cin;
using std::endl;

double ChangeTemperature(double CentigradeTemperature) {
	return 1.8 * CentigradeTemperature + 32.0;

}

int main() {
	double CentigradeTemperature = 0;
	cout << "Please enter a Celsius value: ";
	cin >> CentigradeTemperature;

	cout << CentigradeTemperature << " degrees Celeius is " <<
		ChangeTemperature(CentigradeTemperature) << " degrees Fahrenheit." << endl;



	system("pause");

}
第六题
#include <iostream>
#include <Windows.h>
using std::cout;
using std::cin;
using std::endl;

double changeLightYear(double lightYear) {
	return 63240 * lightYear;
}

int main() {
	double lightYear = 0;
	cout << "Enter the number of light years: ";
	cin >> lightYear;

	cout << lightYear << " light year = " <<
		changeLightYear(lightYear) << " astronomical units." << endl;



	system("pause");

}
第七题
#include <iostream>
#include <Windows.h>
using std::cout;
using std::cin;
using std::endl;

void showData(int hour, int minute) {
	cout << "Time: " << hour << ":" << minute << endl;
}

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

	system("pause");

}
相关标签: CPrimerPlus c++