第二章课后题

一 复习题

1 函数

2 将头文件内容添加到源代码中

3 using是预编译器指令,使用std命名空间

4 cout << “Hello,World!” << endl;

5 int chesses;

6 int chesses = 32;

7 cin >> chesses;

8 cout << “We have " << chesses <<” varieties of chesses," << endl;

9

​ 1)函数名叫froop 带有一个参数 参数类型是double 并且函数返回是一个整型值

​ 2)函数名是rattle 带有一个参数 参数类型是int 函数无返回值

​ 3)函数名是prune 无参数 函数返回值是整型

10 当函数没有返回值时,可以不用定义return

11

​ 1)using namespace std;

​ 2)using std::cout

​ 3)std::cout

二 编程题

1

#include <iostream>
using namespace std;
int main()
{
	cout << "姓名" << endl;
	cout << "地址" << endl;
	return 0;
}

2

#include <iostream>
using namespace std;
int main()
{
	double distance;
	cout << "Enter the distance (in long):";
	cin >> distance;
	cout << "The distance " << distance << "long" << " equals "
		<< 220 * distance << " yard." << endl;
	return 0;
}

3

#include <iostream>
using namespace std;
void hanshu1();
void hanshu2();
int main()
{
	hanshu1();
	hanshu1();
	hanshu2();
	hanshu2();
	return 0;
}

void hanshu1()
{
	cout << "Three bilnd mice" << endl;
}

void hanshu2()
{
	cout << "See how they run" << endl;
}

4

#include <iostream>
using namespace std;
int main()
{
	int age;
	cout << "Enter your age:";
	cin >> age;
	cout << "包含 " << age * 12 << " 个月" << endl;
	return 0;
}

5

#include <iostream>
using namespace std;
void huashi(double n);
int main()
{
	double sheshi;
	cin >> sheshi;
	huashi(sheshi);
	return 0;
}

void huashi(double n)
{
	cout << "华氏温度: " << 1.8 * n + 32.0 << endl;
}

6

#include <iostream>
using namespace std;
void guangnian(double n);
int main()
{
	double years;
	cout << "Enter the number of light years: ";
	cin >> years;
	guangnian(years);
	return 0;
}
void guangnian(double n)
{
	cout << n << " light years = " << n * 63240 << " astronomical units.";
}

7

#include <iostream>
using namespace std;
void time(int n, int m);
int main()
{
	int j, k;
	cout << "Enter the number of hours: ";
	cin >> j;
	cout << "Enter the number of minutes: ";
	cin >> k;
	time(j, k);
	return 0;
}

void time(int n, int m)
{
	cout << "Time: " << n << ":" << m << endl;
}
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序伍六七

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值