C++程序设计(面向对象进阶)(北京邮电大学) 中国大学慕课答案100分完整版

怀暇躬烦攫夏沮笨吩董豆存醒

第1单元:C++概览 第1单元测验

1、 第一个被称为“Modern C++”的标准是?

答案: C++11

2、 集成开发环境中不一定包括

答案: 图形界面设计工具

3、 集成开发环境的英文缩写是

答案: IDE

4、 C++ 11支持的编程范式包括

答案: 结构化编程范式;
函数式编程范式;
OO编程范式;
泛型编程范式

5、 如何学好C++?

答案: 多编程;
多调试解决程序BUG

6、 C++集成开发环境包括下面所列的哪些部分?

答案: 编辑器;
编译器;
链接器

7、 集成开发环境中一般包含

答案: 编辑器;
编译器;
链接器;
调试器

8、 本课程讨论区不建议问下列哪些问题?

答案: cout.flush()函数的参数是什么?;
如何安装Visual Studio 2019?;
谁能帮我编一段排序算法的代码?

9、 我们在C++学习过程中,选择开发工具应尽量选择简单的、问世时间比较久的工具。因为这样的工具易用且稳定。

答案: 错误

10、 C语言支持面向对象编程范式

答案: 错误

11、 编译器的英文是____
答案: compiler

第1单元:C++概览 第1单元课前测试:C语言水平评估 (英文题目;选做)

1、 The keyword “unsigned” can modify the keyword [    ]

答案: long

2、 In the following strings, the correct C identifier is [   ]

答案: _256

3、 The string “rtur”Okay?””  will occupy [    ] bytes memory.

答案: 13

4、 After executing the following statements: int i=0; for( ;++i

答案: 5

5、 The output of the statements: int a=3, b=4;  printf(“%d”, (a>=b?a:a

答案: 4

6、 The output of the following statements is [   ] ( ASCII code of ‘a’ is 97)int a = 98;char b = ‘a’;printf(“%c%d”, (char) a, (int)b);

答案: b97       

7、  In C programming language, the result of statement 5 ^ 4  is [   ]

答案: 1

8、    “x is divisible by 3 but can’t be divisible by 5” can be  written as [    ]

答案: !(x%3) && !(x%5 ==0)

9、  For the statement: int a[10],b; the correct description is[    ]

答案: a can only be rvalue, but b can be lvalue

10、   The correct description about the following program is[    ]#include 
int pPointer;
int nNumber;
void f() {
    nNumber = 25;
    pPointer = &nNumber;
}
int main() {
    f();
    printf(“Value of 
pPointer: %d”, *pPointer);
    return 0;
}

答案: no problem

11、 If compiled with a STANDARD C COMPILER (e.g. gcc), which is correct about the following function “add”? [    ]double add(int , int , int k) {
  return (double) (8+k);
}
int main() {
  int x=1, y=2,z=3;
  add(&x, &y, z);
  return 0;
}

答案: Compile error. After filling in the name of the formal parameters, the program can be compiled without errors;

12、  The following programs initialize an array. The correct one is:[     ]

答案: int a3[4]={3,2,1};

13、 The correct one about pointers is: [     ]We assume that all codes are compiled on 32-bit platform

答案: struct T{ double d; } *p;  where p occupies 4 bytes memory;

14、 The following program computes the summary of the integers that are less than n. The statements in the blank should be [     ]int sum(unsigned int n) {
    if (__) {
        return 1;
}
else {
        return n+sum(n-1);
    }
}

答案: 1==n

15、 The relationship between char array and C-style string is [     ]

答案: If a string is stored in a char array, the size of the char array must be greater than the length of the C-style string.

16、 Given the following program, when do-while loop finishes,the value of x is[     ]enum { APPLE, LEMON=6, ORANGE, BANANA=2, GRAPE};
void f ( ) {
    int x=GRAPE;
    do {
         x++;
    } while ((x-APPLE) }

答案: 8

17、 Which of the following statements are completely correct? [     ]

答案: int k, p=&k;  scanf(“%d”, p);

18、 The output of the following program is [     ]int a=0, b=3;
printf(“%d  %d”, (a

答案: 0  12

19、 Which statement satisfies the condition: If string s1 equals to strings s2, then execute ST.  [     ]

答案: if(strcmp(s2,s1)==0) ST;

20、   Given the following program#include  
int fun( ){
  static int x=1;
  x+=1;
  return x;
}
int main( ){
  int i, s=1;
  for(i=1; i     s+=fun( );
  printf(“%d”, s);
  return 0

答案: 21

21、  C language is a structured programming language. (   )

答案: 正确

22、  In standard C,int variable can be used as char variable, and vice versa. (   )

答案: 错误

23、 In standard C,”=” is a judgment of whether two numbers are equal. (   )

答案: 错误

24、  In if statement, the statement before else may omit “;”. (   )

答案: 错误

25、  In C language, there are 3 basic file access modes: read, write and append. (   )

答案: 正确

26、 In C language, when declaring a struct type, you must not omit the keyword “struct”. (   )

答案: 正确

27、 The memory address and the contents in the memory are identical. (   )

答案: 错误

28、 In standard C, local variables must be defined before any other statements in the function body. (   )

答案: 正确

29、 In standard C, all the functions except main() should be declared before being called. (   )

答案: 正确

30、 In standard C, the index of an array must be a constant, not an expression (   )

答案: 错误

第2单元:C++程序基础 第2单元测验

1、 关于C++的main()函数说法不正确的是

答案: 必须得显式地写 return 语句返回一个整型值

2、 关于名字空间,说法正确的是

答案: 程序员可以定义自己的名字空间

3、 关于编译预处理,说法正确的是

答案: #define  HELLO是定义了一个宏,名字叫 HELLO

4、 int i = 1;cout

答案: 第二行代码是一句病式。最终结果依赖于两个 i 的取值次序。这是C++标准中未定义的行为。不同编译器会输出不同的结果。

5、 char a, b;cin >> a;b = cin.get();从键盘上输入  字符 x 然后回车,那么 b中存放的是

答案: 换行符

6、 cin对象中,以下说法错误的是

答案: 也支持

7、 c++程序中的源文件扩展名包括以下:

答案: cpp;
cxx

8、 遵守编码规范有助于

答案: 提升代码的可阅读性和可维护性;
提升程序开发小组协作的效率

9、 运算符 >> 原本的含义是左移运算符

答案: 错误
分析:是右移运算符,没看到尖向右吗?

10、 int a, b;cin >> a >> b;输入 1  2则 a的值是2, b的值是1

答案: 错误

11、 编译器能帮我们检查代码的逻辑错误

答案: 错误
分析:编译器只能检查语法错误。

12、 C++程序的入口点是哪个函数?
答案: main
分析:和C语言一样,也是main()函数

13、 用于输出语句中,代表标准输出的对象是
答案: cout
分析:是cout或者 std::cout

作业第1单元:C++概览 作业1:测试你的C++编译器支持的标准

小提示:本节包含奇怪的同名章节内容

1、 在C++开发环境中创建新的项目,然后创建一个main.cpp文件,将下面的代码粘贴到该源文件中;不要改动你的C++开发环境中的默认设置。编译并且运行;截屏展示程序的输出结果。作业提交:用文字说明你所用C++开发环境的名称、版本号、操作系统及版本号(共6分);输出结果的截屏图片(4分)。代码如下:C++程序设计(面向对象进阶)(北京邮电大学) 中国大学慕课答案100分完整版第1张// 注意:由于中M系统有bug,正常录入的C++代码会出现HTML控制符。
// 如果出现该问题,请参考上面图片中的代码。
// 也可以下载附件“CompilerVersion.cpp.txt”,将文件名中的“.txt”去掉

include 

 
int main() {
  // 注意:__cplusplus 开头是连续两个下划线
  if (__cplusplus > 201703L) std::cout    else if (__cplusplus == 201703L) std::cout    else if (__cplusplus == 201402L) std::cout    else if (__cplusplus == 201103L) std::cout    else if (__cplusplus == 199711L) std::cout    else std::cout   
  std::cout    std::cin.get();
 
  return (0);
}
// 如果上面的代码无法拷贝,也可以下载附件,将扩展名改为 .cpp
评分规则:  C++开发环境的名称、版本号其中开发环境名称2分,版本号2分,操作系统名称版本号2分
截图 (2分)展示运行程序的输出结果(2分)。

2、 修改你的C++开发环境的配置,使它支持C++17标准、C++2a(C++20发布之前的实验性标准) 或者C++20标准。注意:要完成本作业,你能够使用的集成开发环境中所配置的编译器有1. Visual Studio 2017 / 2019或者更新的版本绝对不要使用VS2017之前的版本!!!2. Gcc 7.0或者更新版本3. Clang 4.0或者更新版本各种编译器对于C++新标准的支持程度可以参考http://zh.cppreference.com/w/cpp/compiler_support编译并运行 作业1 中的代码,使得程序输出 C++17或者C++2a。截屏展示程序输出结果。作业需要提交:文字说明你修改C++开发环境的步骤(2分)上传截屏图片(3分)
评分规则:  文字说明修改C++开发环境的步骤。步骤完整得2分,不完整得1分,无说明得0分
有截屏1分,输出结果为C++17或者C++2a或者C++20得2分

3、 在C++开发环境中创建新的项目,然后创建一个main.cpp文件,将下面的代码粘贴到该源文件中;修改你的C++开发环境的配置,使它支持C++17标准、C++2a(C++20发布之前的实验性标准) 、C++20或者C++23标准。编译并运行,使得程序输出 C++17、C++20或者C++23。截屏展示程序的输出结果。作业提交:用文字说明你所用C++开发环境的名称、版本号、操作系统及版本号(共6分);输出结果的截屏图片(4分)。代码如下:C++程序设计(面向对象进阶)(北京邮电大学) 中国大学慕课答案100分完整版第1张// 注意:由于中M系统有bug,正常录入的C++代码会出现HTML控制符。
// 如果出现该问题,请参考上面图片中的代码。
// 也可以下载附件“CompilerVersion.cpp.txt”,将文件名中的“.txt”去掉

include 

 
int main() {
  // 注意:__cplusplus 开头是连续两个下划线
  if (__cplusplus > 202002L) std::cout    else if (__cplusplus == 202002L) std::cout    else if (__cplusplus == 201703L) std::cout    else if (__cplusplus == 201402L) std::cout    else if (__cplusplus == 201103L) std::cout    else if (__cplusplus == 199711L) std::cout    else std::cout   
  std::cout    std::cin.get();
 
  return (0);
}
// 如果上面的代码无法拷贝,也可以下载附件,将扩展名改为 .cpp注意:要完成本作业,你能够使用的集成开发环境中所配置的编译器有1. Visual Studio 2019/2022或者更新的版本绝对不要使用VS2017之前的版本!!!2. Gcc 9.0或者更新版本3. Clang 11.0或者更新版本各种编译器对于C++新标准的支持程度可以参考http://zh.cppreference.com/w/cpp/compiler_support
评分规则:  C++开发环境的名称、版本号其中开发环境名称2分,版本号2分,操作系统名称版本号2分
截图 (2分)展示运行程序的输出结果(2分)。

作业第2单元:C++程序基础 第2单元作业2:在线编程-名字空间

1、 创建两个名字空间 NS1 和NS2;
在NS1中定义一个常量x,赋值为 1;
在NS2中定义一个常量x,赋值为 2;
在main()中输出这两个常量。
建议:本题是主观题,暂无解析

作业第2单元:C++程序基础 第2单元作业1:在线编程-输入与输出

1、 输入一个[1-9]之间的整数(假定该整数为n),输出1-n之间的整数。
建议:本题是主观题,暂无解析

作业第1单元:C++概览 作业2:选做安装Eclipse For C-C++或者Eclipse CDT版本

1、 1. 安装 JDK8或JDK 11(不建议安装JDK10或JDK12等偶数版本,因为自JDK9之后,只有奇数版JDK才是长期支持版)2. 安装Eclipse for C/C++ 或者 Eclipse CDT3. 安装 MinGW-W64或者MSys2,能够使用Gcc编译器4. 编译作业1中提供的代码。5. 截屏。屏幕中包括Eclipse以及程序运行结果作业提交:截屏图片
评分规则:  截屏图片。表明Eclipse安装成功,所需编译的程序运行成功

第3单元: C语法的增强及对应的C++11特性 第3单元测验

1、 bool x, y;
// …… 此处代码对x和y进行初始化则表达式 !(x && !y) 与下面哪个表达式等价?

答案: !x || y

2、 给定函数1void f(int a, int b = 1, int c = 2) {}和函数2void f(int x, int y = 3) {}对于下面语句f(3, , 1);来说,表述正确的是:

答案: 编译器会对函数调用语句报错

3、 char a = new char[32];对应的释放内存的语句,哪种写法最好?

答案: delete [] a;
a = nullptr;

4、 下列代码正确的是

答案: auto a {10};
decltype(a) y;

5、 对于语句int& x = y, y{0};说法正确的是

答案: 有语法错误;
正确定义方法应该是int y {0}, &x {y};

6、 char* p = new char(32);释放内存的语句是:

答案: delete [] p;;
delete p;

7、 下列代码能累加数组元素的有

答案: int x[] {3, 5, 7};
auto sum{0};
for( auto i : x )
  sum+=i;;
int x[] {3, 5, 7};
auto sum{0};
for( int i = 0; i   sum+=(x+i);

8、 对于已有代码char a[3] {‘’}, b[3] {‘a’};
char const p = a;合法的后续语句是:

答案: p[0] = ‘a’;;
b[0] = (
p)++;

9、 表达式:static_cast (3) / 2与 表达式:static_cast (3 / 2)是等价的。

答案: 错误

10、 引用在定义的时候就必须被初始化

答案: 正确

11、 auto x[] {1,2,3};编译后,x的类型是 int[]

答案: 错误

12、 int p;
p = NULL;在C++11中,这种代码写法是一种好的编程规范

答案: 错误

13、 bool x = 1 & 2;则x的值为
答案: false

14、 bool x = 1 && 2;则x的值为
答案: true

15、 代码#include 
int i = 1;
int main() {
  for (int i = 0; i      ::i += i;
  }
  std::cout    return 0;
}的输出结果是:
答案: 11

16、 声明内联函数的关键字是
答案: inline

第4单元: 对象和类(基础) 第4单元测验

1、 对于如下代码:Circle *pCircle2 = new Circle(5.9);释放内存的正确语句是:

答案: delete pCircle2;

2、 下面的代码输出结果是什么?string s{“”};
s.append(“ABCDEFG”, 3, 2); 
cout 

答案: DE

3、 对于如下代码Circle* p = new Circle[3];正确释放内存的代码是:

答案: delete [] p;

4、 对于如下代码Circle circleArray[3] = {
       Circle(3), 
       Circle(4)
};没有调用Circle类的哪些构造函数?上述代码的编译环境是 C++11或者C++14。注意:在C++17中引入了“复制消除”,会对本题的结果产生重要影响。

答案: Circle::Circle(Circle [])

5、 以下代码中,第几行有错误?class S {   int x = 7;   int n(7);    std::string s{“Hello”};  int a[] = {1,2,3};   auto b[] = {1,2,3};public:  S() { } }; 

答案: 3,5,6

6、 关于C++11引入的 std::array类,说法不正确的是

答案: std::array对象不能用基于范围的for循环遍历

7、 class Hello 的构造函数的原型可以写为

答案: inline Hello(int a);;
Hello(char p, char& q, char []);;
Hello(int a = 0);;
Hello() = default;

8、 考虑如下代码,在编译器不做任何优化的情况下,Circle circle1, circle2;
circle1 = Circle();
circle2 = Circle(5);中的匿名对象有

答案: Circle();
Circle(5)


上方为免费预览版答案,如需完整答案,请点击下方红字购买:

点击这里,购买完整答案


为了方便下次阅读,建议在浏览器添加书签收藏本网页

添加书签方法:

1.电脑按键盘的Ctrl键+D键即可收藏本网页

2.手机浏览器可以添加书签收藏本网页

C++程序设计(面向对象进阶)(北京邮电大学) 中国大学慕课答案100分完整版第3张

C++程序设计(面向对象进阶)(北京邮电大学) 中国大学慕课答案100分完整版第4张


 

欧涝涂楷归确亩欠台禽炭偏茄

搜索
登录
订单
帮助