当前位置:网站首页>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 ) );
}
边栏推荐
- Swiftui layout - size (top)
- UI开发中所遇到的各种坑
- 如何只降3D相机不降UI相机的分辨率
- Bulk Rename Utility
- Unittest executes runtestcase prompt <_ io. Textiowrapper name= '< stderr>' mode=W encoding=UTF-8 > solution
- 国产数据库的红利还能“吃”多久?
- [leetcode] 1331. Array sequence number conversion
- How to perform batch operations in core data
- 我正在使用中的博客创作工具
- Excel VBA 免密查看VBE加密代码
猜你喜欢

The 35 required questions in MySQL interview are illustrated, which is too easy to understand

Store and guarantee rancher data based on Minio objects

Copy excel row to specified row

如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然

TDengine 助力西门子轻量级数字化解决方案

BGP experiment

Redis-配置文件讲解

Career planning of Software Test Engineer

2022年熔化焊接与热切割考题及在线模拟考试

Interviewer: what are the usage scenarios of ThreadLocal? How to avoid memory leakage?
随机推荐
Brief introduction of diversity technology
468产品策划与推广方案(150份)
How to perform batch operations in core data
BGP experiment
Chi square distribution and gamma function
FormData对象的使用, var formdata=new FormData()
使用Weka与Excel进行简单的数据分析
&0xffffffff(0x08)
Another way of understanding the essence of Hamming code
Raspberry pie foundation | summarize and record some operations in the learning process of raspberry pie
多线程顺序运行有几种方法?
9、 Uni popup usage popup effect at the bottom of the drop-down box
Excel VBA 开发过程中遇到的一些问题,解决方案,持续更新
It's so hot that solar power can't take off? Hello, head
How long can we "eat" the dividends of domestic databases?
[线程安全问题] 多线程到底可能会带来哪些风险?
Brief introduction and use of mqtt entry level
OKR与GRAD
复制excel行到指定行
Forage QR code -- online QR code generator