工作日记20170628

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/github_37856429/article/details/73835947

2017年6月28日 周三

C++第二章复习题

1,C++程序的模块叫什么?

  叫作函数

2,下面的预处理器编译指令是做什么用的?

#include <iostream>

  这将导致在最终的编译之前,使用iostream文件的内容替换该编译指令。

3,下面的语句是做什么用的?

sing namespace std;

   它使得程序可以使用std名称空间的定义。

4,什么语句可以用来打印短语“Hello,world“,然后开始新的一行?

cout << "Hello, world\n"; 或者
cout << "Hello, world" << endl;

5,什么语句可以创建名为cheeses的整数变量?

int cheses;

6,什么语句可以用来将值32赋给变量cheeses?

cheeses=32;

7,什么语句可以用来将键盘输入的值读入变量cheeses中?

cin >> cheeses;

8,什么语句可以用来打印”We have X varieties of cheeses,”,其中X为变量cheses的当前值。

cout << "We have "<<cheeses<<" varieties of cheeses"<<endl;

9,下面的函数原型指出了关于函数的哪些信息?

int froop(double t);
void rattle(int n);
int prune(void);

froop表示输入一个类型为double的参数,返回一个类型为int的值,可以这样使用:int gval = froop(3.1415);
rattle表示接受一个类型为int的参数而不返回值,可以这样使用:rattle(37)
prune表示不接受任何参数且返回一个int值,可以这样使用:int residue = prune();

10,定义函数时,在什么情况下不必使用关键字return?

当函数的返回类型为viod时。若不提供返回值也可以用return;

11,假设您编写的main()函数包含如下代码:

cout << "Please enter your PIN: ";

而编译器指出cout是一个未知标志符。导致这种原因很可能是什么?指出3种修复这种问题的方法。

(1) 没有使用#include <iostream>;
(2) 没有将cout命名包括进来:using namespace std;
(3) 输入格式不对.可以使用std ::cout

12,编一个程序,要求用户输入小时数和分钟数。在main()函数中,将这两个值传递给一个void函数,后者以下面这样的格式显示这两个值:

Enter the number of hours: 9
Enter the number of minutes: 28
Time: 9:28
#include <iostream>
using namespace std;
void time(int, int);
int main()
{
    int a, b;
    cout << "Enter the number of hours: ";
    cin >> a;
    cout << "Enter the number of minutes: ";
    cin >> b;
    time(a, b);
    return 0;
}
void time(int a, int b)
{
    cout << "Time: " << a << " : " << b << endl;
}

猜你喜欢

转载自blog.csdn.net/github_37856429/article/details/73835947