当前位置:网站首页>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 ) );
}
边栏推荐
- unittest执行runTestCase提示<_io.TextIOWrapper name=‘<stderr>‘ mode=‘w‘ encoding=‘utf-8‘>解决方案
- Chi square distribution and gamma function
- 2022 melting welding and thermal cutting examination questions and online simulation examination
- Pointers and arrays (7)
- 468产品策划与推广方案(150份)
- How to perform batch operations in core data
- These three online PS tools should be tried
- C语言中浮点数据类型(你学废了吗)
- How to use the C language library function getchar ()
- 9、 Uni popup usage popup effect at the bottom of the drop-down box
猜你喜欢

Hcip day 11

Another way of understanding the essence of Hamming code

Forage QR code -- online QR code generator

Digital transformation security issues occur frequently, and Shanshi Netcom helps build a digital government

Installing redis in Linux

Redis redis use in jedis
![[ecmascript6] other new interface features](/img/da/377f93d83b6722bf250d270e4eea28.png)
[ecmascript6] other new interface features

数字化转型安全问题频发,山石网科助力数字政府建设

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

Brief introduction and use of mqtt entry level
随机推荐
为 @CloudStorage 添加了类 @Published 的能力
It's so hot that solar power can't take off? Hello, head
I am using a blog creation tool
【七夕】七夕孤寡小青蛙究极版?七夕节最终章!
Brief introduction of diversity technology
(function(global,factory){
Redis-配置文件讲解
Several methods of opening URL in swiftui view
2022年熔化焊接与热切割考题及在线模拟考试
C# 读取ini文件、键值对操作
Excel VBA 免密查看VBE加密代码
Metersphere -- Open Source continuous testing platform
Another way of understanding the essence of Hamming code
Swiftui layout - size (bottom)
工厂模式和构造函数模式
多所“双一流”大学,保研预报名启动!
SwiftUI 布局 —— 尺寸( 上 )
2022 safety officer-a certificate operation certificate examination question bank simulated examination platform operation
Excel VBA password free view VBE encryption code
ScottPlot入门教程:获取和显示鼠标处的数值