2021 Object-oriented Technology and C++ Programming Language(Dalian University of Technology) 最新满分章节测试答案
- 【作业】1 Introduction Assignment 1
- 1 Introduction Test 1
- 【作业】1 Introduction Assignment 1 (update)
- 【作业】2 Class and Object Assignment 2
- 2 Class and Object Test 2
- 【作业】3 Operator Overloading Assignment 3
- 3 Operator Overloading Test 3
- 【作业】4 Inheritance Assignment 4
- 4 Inheritance Test 4
- 【作业】5 Polymorphism Assignment 5
- 5 Polymorphism Test 5
- 6 Template Test 6
- 【作业】6 Template Assignment 6
- 7 Exception Handling Test 7
本答案对应课程为:点我自动跳转查看
本课程起止时间为:2021-03-01到2021-05-31
本篇答案更新状态:已完结
【作业】1 Introduction Assignment 1
1、 问题:Write a program with input and output stream operators. Input two numbers from the keyboard, and add, subtract, multiply and divide the two numbers respectively. Output the calculation results, such as: 23 + 123 = 146.
评分规则: 【 input numbers
output results
others
】
2、 问题:Use “new” and “delete” operators to dynamically allocate memory space. Input the data of 3X3 integer array (9 integers) from the keyboard, and calculate the sum of all elements. Print the maximum and minimum integers.
评分规则: 【 input numbers
output results
new and delete
】
3、 问题:Write C++ style program to solve the problem of “100 cents”: how many ways to change RMB 1 yuan into RMB 1,2,5 cents?
评分规则: 【 loop and condition
】
1 Introduction Test 1
小提示:本节包含奇怪的同名章节内容
1、 问题:What is the output of the following program fragment?int a = 3, b = 4;int& r = a;r = b;r = 6;std::cout << a << std::endl;
选项:
A:7
B:6
C:4
D:3
答案: 【6】
2、 问题:What is the return type of ‘new int’?
选项:
A:int
B:int &
C:int
D:void
答案: 【int 】
3、 问题:char* p = new char(65); What’s the memory release statement ?
选项:
A:delete p;
B:delete [] p;
C:free(p);
D:delete <char> p;
答案: 【delete p;】
4、 问题:char p = new char[65];What’s the memory release statement ?
选项:
A:free p;
B:free p[];
C:delete p;
D:delete [] p;
答案: 【delete [] p;】
5、 问题:Which of the following statements is true?
选项:
A:The number of parameters for multiple overloaded functions must be different.
B:There are two functions with the same parameter list and different return value types. These two functions are overloaded functions.
C:When calling a function with both the second and third parameters having default values, you can only write the third argument while not writing the second argument.
D:The purpose of using inline functions is to improve the running speed of the program.
答案: 【The purpose of using inline functions is to improve the running speed of the program.】
6、 问题:If the function declaration is void fun (char * a, int n, int & m); Which of the following statements is true ?
选项:
A:char str[10];int p, m;fun( str, m, p );
B:char p = new char[10];int n, m;fun( p, m, &n );
C:char p = new char[10];int n, m;fun( p, m, n );
D:char p = new char[10];int n;fun( p, &n, 6 );
答案: 【char *p = new char[10];int n, m;fun( p, m, n ); 】
7、 问题:The legal comments for C++ is
选项:
A:/This is a C++ program/
B:// This is a C++ program
C:“This is a C++ program”
D:/*This is a C++ program//
答案: 【// This is a C++ program】
8、 问题:The steps of developing C ++ program are
选项:
A:edit, debug, compile, connect
B:compile, debug, edit, connect
C:compile, edit, connect, run
D:edit, compile, connect, run
答案: 【edit, compile, connect, run】
9、 问题:Function overloading means
选项:
A:Two or more functions have the same function name, but the number or type of parameters are different
B:Two or more functions have the same name and the same number of parameters, but the types of parameters can be different
C:Two or more functions have different names, but the number or type of parameters are the same
D:Two or more functions have the same function name and return type
答案: 【Two or more functions have the same function name, but the number or type of parameters are different】
10、 问题:About C++ and C language, which of the following statements is wrong?
选项:
A:C is a subset of C++
B:C program can run in C++ environment
C:C++ program can run in C environment
D:C++ is object-oriented and C is process oriented
答案: 【C++ program can run in C environment】
11、 问题:About C++ and C language, which of the following statements is wrong?
选项:
A:C is a subset of C++
B:C program can run in C++ environment
C:C++ program can run in C environment
D:C++ is object-oriented and C is process-oriented
答案: 【C++ program can run in C environment】
【作业】1 Introduction Assignment 1 (update)
1、 问题:(1) Input two numbers from the keyboard. (2) Add, subtract, multiply and divide the two numbers respectively. Output the calculation results, such as: 23 + 123 = 146.
评分规则: 【 Input two numbers from the keyboard.
Add, subtract, multiply and divide the two numbers respectively.
Output the calculation results, such as: 23 + 123 = 146.
】
2、 问题:Use “new” and “delete” operators to dynamically allocate memory space. Input N integers from the keyboard. (1) Calculate and print the sum of all integers. (2) Print the maximum and the minimum of all integers.
评分规则: 【 Input N integers from the keyboard.
Calculate and print the sum of all integers.
Print the maximum and the minimum of all integers.
】
3、 问题:Write a program to swap two integers in the function void swap (int & X, int & Y) by using reference as function parameters. Print the results in the main function.
评分规则: 【 Write a program to swap two integers in the function void swap (int & X, int & Y)
main function
】
【作业】2 Class and Object Assignment 2
1、 问题:A fraction class is defined as follows. Each member function is required to be implemented, and operations such as addition, subtraction, multiplication, and division of two fractions are tested in the main function. class Rational{public:Rational(int nn=1,int mm=1); //ConstructorRational R_add(Rational & A); //AdditionRational R_sub(Rational & A); //SubtractionRational R_mul(Rational & A); //MultiplicationRational R_div(Rational & A); //Divisionvoid print(); //Contract the fraction as a simple fractionprivate:void simple( ); //Contractint m; //Denominatorint n; //Molecule};
评分规则: 【 Rational(int nn=1,int mm=1); //Constructor
Rational R_add(Rational & A); //AdditionRational R_sub(Rational & A); //SubtractionRational R_mul(Rational & A); //MultiplicationRational R_div(Rational & A); //Division
void simple( ); //Contract
】
2、 问题:The store distributes a kind of goods which are purchased and sold in boxes by weight, and the weight and price of each box varies. Therefore, the store needs to record the total weight and value of the goods currently in stock. Write a program to simulate the purchase and sale of goods in the store by defining the “Carlo” class. (The main purpose of this task is to train students to use static data members. Define private variables to store the price and weight of each item, and use static data members to store the total weight and total price of the item; define the constructor. When the definition and initialization of a new object is completed or the object is deleted, the weight and price of the corresponding object are added or subtracted from the total weight and total price.)
评分规则: 【 class of Carlo with 2 data members:price and weight
static data members to store the total weight and total price
constructor
initiation of total weight and total price
the weight and price of the corresponding object are added or subtracted from the total weight and total price
】
3、 问题:There is a “Point” class and the main function is as follows: void main(){Point p[3] ;p[2].set(1.0,2.0)p[3].set(3.0,4.0) ;p[2].show( );} After running the program, the output is as follows: Create point(0,0).Create point(0,0).Create point(0,0).point is (1.0,2.0). Please complete the declaration and implementation of the “Point” class. (Both x and y coordinates are float type)
评分规则: 【 class point with x and y coordinates
constructor of point
function set()
function show ()
】
2 Class and Object Test 2
1、 问题:What is the incorrect statement about “class” and “object”?
选项:
A:Class is a data type. It encapsulates data and functions.
B:Object is an instance of the class.
C:There is only one object for a class.
D:An object must belong to a class
答案: 【There is only one object for a class.】
2、 问题:Which of the following statements is incorrect?
选项:
A:A class can have many member functions with the same name
B:In a class, we can declare objects of another other class as its data members
C:The definition of a class should end with a semicolon.
D:The storage space allocated by the system for the class can be calculated by "sizeof"
答案: 【The storage space allocated by the system for the class can be calculated by "sizeof"】
3、 问题:A member function in class A is described as void set(A &a);,where A &a means_
选项:
A:The pointer to class A is a
B:Assign the address of a to the variable set
C:a is the object reference of class A, which is used as the parameter of function set()
D:a is an independent object of class A, which is used as the parameter of function set()
答案: 【a is the object reference of class A, which is used as the parameter of function set()】
4、 问题:Function void f() is a public member function in class A. Which of the following statements is wrong?
选项:
A:A a; a.f();
B:A a; A*a1 = &a; a1->f();
C:A a; A &a1 = a; a1->f();
D:A a; A &a1 = a; a1.f();
答案: 【A a; A &a1 = a; a1->f();】
5、 问题:In the following Time class, which of the following statements is correct?class Time { int H,M,S; public: void Time(int h,int m,int s) { }; //A } //B
选项:
A:There is an error in line A
B:There is an error in line B
C:There are errors in lines A and B
D:There is no error in lines A or B
答案: 【There are errors in lines A and B】
本文章不含期末不含主观题!!
本文章不含期末不含主观题!!
支付后可长期查看
有疑问请添加客服QQ 2356025045反馈
如遇卡顿看不了请换个浏览器即可打开
请看清楚了再购买哦,电子资源购买后不支持退款哦