当前位置:网站首页>The second pre class exercise
The second pre class exercise
2022-07-28 14:46:00 【Qing Ankang】
Catalog
One 、 Judgment questions
1-1
The number and type of parameters of the function are the same , It's just that the return value is different , This is not an overloaded function .(T)
1-2
The types of arguments in a function call must match the types of the corresponding parameters in the function prototype’s parameter list..(T)
1-3
stay C++ Introducing inline functions into language (inline function) The main purpose of is to reduce the spatial complexity , That is, shorten the length of object code .(F)
1-4
using namespace std; The function of this statement is to change the namespace std All identifiers in are exposed in the current scope .(T)
1-5
Functions with the same name can be distinguished by namespace (T)
Two 、 Single topic selection
2-1
About new Operator in the following description ,(D) It's wrong. .
A. It can be used to dynamically create objects and object arrays ;
B. The object or array of objects created with it can use the operator delete Delete ;
C. When you use it to create an object, you call the constructor ;
D. When using it to create an object array, you must specify the initial value ;
2-2
About delete Operator in the following description ,(C) It's wrong. .
A. It must be used for new Pointer returned ;
B. When you use it to delete an object, you call the destructor ;
C. You can use this operator more than once for a pointer ;
D. There is only one square bracket symbol in front of the pointer name , Regardless of the dimension of the deleted array .
2-3
In the following procedure ,new What did the statement do .( C)
int** num;
num = new int* [20];
A. Assigned a length of 20 Integer array space , And return the pointer of the first element to .
B. Allocated a space for an integer variable , And initialize it to 20.
C. Assigned a length of 20 Integer pointer array space , And will num[0] The pointer back to .
D. There are errors , Compilation cannot pass .
2-4
The problem with the following procedure is :( C)
void fun()
{
int *num1, *num2;
num1 = new int[10];
num2 = new int[20];
num1[0] = 100;
num2[0] = 300;
num1 = num2;
delete [] num1;
}
A.num2 You can't give num1 assignment
B.num2 The space initially pointed to is not released
C.num1 The space initially pointed to is not released
D. There is no problem with the procedure
2-5
set up void f1(int * m,long & n);int a;long b; Then the following call is legal (B).
A.f1(a,b);
B.f1(&a,b);
C.f1(a,&b);
D.f1(&a,&b);
2-7
(2020final) The function of a function is not too complex , But the request is called frequently , Optional ( A).
A. Inline function
B. overloaded function
C. Recursive function
D. Nested function
2-8
Overloaded functions are selected based on when calling , The wrong is (D).
A. The parameters of the function
B. Type of parameter
C. Function name
D. Type of function
2-9
stay ( C) It is appropriate to use inline Define inline functions .
A. The function body contains a circular statement
B. The function body contains recursive statements
C. Less function code 、 Call... Frequently
D. There are many function codes 、 Rarely call
2-11
The following statement is correct (B).
A. An inline function inserts the object code of the function into every place where the function is called at run time
B. Inline function is to insert the object code of the function into each place where the function is called at compile time
C. The inline function of a class must be defined in the class body
D. The inline function of a class must be outside the class by adding keywords inline Definition
2-12
The following requirements for defining overloaded functions ,( C) It's wrong. .
A. The number of required parameters is different
B. At least one parameter of different type is required
C. The return value of the function is required to be different
D. The same number of parameters is required , Different parameter types
2-13
Namespace applies to :(B)
A. Define the member function of the class outside the class
B. Avoid different functions 、 Name conflict of variable, etc
C. Speed up code execution
D. All the above answers are correct
2-14
To specify which namespace the identifier belongs to , You need to add... Between the identifier and the namespace name :(A)
A.::
B.->
C…
D.( )
3、 ... and 、 Function questions
6-1 Overload function absolute value
fraction 10
author Zhang Dehui
Company Xi'an University of Posts and Telecommunications
The absolute value function abs( ) Heavy load three times , To call... In the following main function .
### The calling form in the main function is :
abs(x1);
among x1 Is the parameter passed in by the user .
Sample referee test procedure :
#include"iostream"
using std::cin;
using std::cout;
using std::endl;
// The code you submit will be embedded here
int main()
{
int x1; long x2; double x3;
cin>>x1>>x2>>x3;
cout<<“x1=”<<abs(x1)<<endl;
cout<<“x2=”<<abs(x2)<<endl;
cout<<“x3=”<<abs(x3)<<endl;
return 0;
}
sample input :
8 -9 -2.7818281828
sample output :
x1=8
x2=9
x3=2.78183
int abs(int x) {
if(x < 0) x = -x;
return x;
}
long abs(long x) {
if(x < 0) x = -x;
return x;
}
double abs(double x) {
if(x < 0) x = -x;
return x;
}
6-2 Area calculator ( function overloading )
fraction 10
author He Zhenfeng
Company Fuzhou University
Implement an area calculator , It can calculate the area of a rectangle or cuboid .
Function interface definition :
int area(int x, int y);
int area(int x, int y, int z);
The first function calculates the area of a rectangle , among x and y It's length and width . The second function calculates the surface area of the box ,x,y and z It's long , Width and height .
Sample referee test procedure :
#include
#include
using namespace std;
int area(int,int);
int area(int,int,int);
int main()
{
int i, repeat, c, x, y, z;
cin>>repeat;
for(i=0;i<repeat;i++){
cin>>c;
if(c2){
cin>>x>>y;
cout<<area(x,y)<<endl;
}
if(c3){
cin>>x>>y>>z;
cout<<area(x,y,z)<<endl;
}
}
return 0;
}
/* Please fill in the answer here */
sample input :
2
2 1 2
3 2 3 4
sample output :
2
52
int area(int x, int y) {
return(x * y);
}
int area(int x, int y, int z) {
return(2 * ( x * y + x * z + y * z ) );
}
边栏推荐
- Development and definition of software testing
- How does core data save data in SQLite
- 【七夕】七夕孤寡小青蛙究极版?七夕节最终章!
- Why can the anonymous functions of JQ access the methods inside
- 分集技术简略
- Why is it reverse to convert from other formats to BMP
- Swiftui layout - alignment
- TDengine 助力西门子轻量级数字化解决方案
- 2022 low voltage electrician examination questions and answers
- [ecmascript6] other new interface features
猜你喜欢

基于 MinIO 对象存储保障 Rancher 数据

Brief introduction and use of mqtt entry level

【七夕】七夕孤寡小青蛙究极版?七夕节最终章!

35道MySQL面试必问题图解,这样也太好理解了吧

@DS('slave') 多数据源兼容事务问题解决方案

Installing MySQL on Linux

Many "double first-class" universities have launched the research guarantee and prediction name!

Career planning of Software Test Engineer
![[ecmascript6] async and await](/img/3c/c7de42ad572dc95b188243c02dd228.png)
[ecmascript6] async and await

2022年熔化焊接与热切割考题及在线模拟考试
随机推荐
分集技术简略
Recommended super easy-to-use mobile screen recording software
Iterator iterator interface
C # read INI file and key value pair operation
Node文件操作
Tdengine helps Siemens' lightweight digital solutions
Afnetworking crash course
[ecmascript6] async and await
Store and guarantee rancher data based on Minio objects
Another way of understanding the essence of Hamming code
The 35 required questions in MySQL interview are illustrated, which is too easy to understand
看了就会的 Rainbond 入门教程
多线程顺序运行有几种方法?
How long can we "eat" the dividends of domestic databases?
Swiftui layout - size (top)
围绕新市民金融聚焦差异化产品设计、智能技术提效及素养教育
用 Table 在 SwiftUI 下创建表格
聊天室功能的实现
Redis-Redis在Jedis中的使用
How to use the C language library function getchar ()