C++ Primer Plus 编程练习题 第二章 开始学习C++

1.姓名和地址

#include 
using namespace std;
int main() 
{
	string name;
	cout << "请输入姓名:";
	cin >> name;
	string dress;
	cout << "请输入地址:";
	cin >> dress;
	cout << "您的姓名是:" << name << ";地址是:" << dress << endl;
	return 0;
}

2.距离转换

#include 
using namespace std;
int main() 
{
	int l;
	cout << "请输入以long为单位的距离:";
	cin >> l;
	int m = 220 * l;
	cout << l << "long = " << m << "码";
	return 0;
}

3.输出

#include 
using namespace std;

void mice(void)
{
	cout << "three blind mice"<

4.年龄

#include 
using namespace std;

int nianling(int age)
{
	return age * 12;
}
int main() 
{
	int age;
	cout << "请输入年龄"<> age;
	cout << "您的年龄包含" << nianling(age) << "个月" << endl;
	return 0;
}

5.温度转换

#include 
using namespace std;
double temperature(double wendu)
{
	return 1.8*wendu+32;
}
int main() 
{
	double wendu;
	cout << "请输入摄氏温度:"<> wendu;
	cout << wendu<<"摄氏度相当于" << temperature(wendu) << "华氏度" << endl;
	return 0;
}

6.光年天文单位转换

#include 
using namespace std;
double convert(double guangnian)
{
	return 63240*guangnian;
}
int main() 
{
	double guangnian;
	cout << "请输入光年:"<> guangnian;
	cout << guangnian<<"光年 =" << convert(guangnian) << "天文单位" << endl;
	return 0;
}

7.时间

#include 
using namespace std;
void xianshi(int hour,int minute)
{
	cout << "Time:" << hour << ":" << minute << endl;
}
int main() 
{
	int hour;
	cout << "请输入小时数:";
	cin >> hour;
	int minute;
	cout << "请输入分钟数:";
	cin >> minute;
	xianshi(hour, minute);
	return 0;
}

你可能感兴趣的:(C++,Primer,Plus,编程练习题,c++,开发语言,学习)