当前位置:网站首页>Second class exercise
Second class exercise
2022-07-28 14:46:00 【Qing Ankang】
Catalog
One 、 Judgment questions
1. Overloaded functions can have default values and arguments , But pay attention to ambiguity .(T)
2. Functions with the same name can be distinguished by namespace (T)
3. Functions with the same name can be distinguished by namespace (T)
4. Symbolic constants must be initialized when they are defined .(T)
Two 、 Single topic selection
2-1
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-2
If the local variable defined in the function has the same name as the variable in the namespace ,(B) Be hidden .
A. Variables in functions
B. Variables in namespace
C. Both variables
D. Neither of these variables
2-3
If used in the program using The command references multiple namespaces at the same time , And the same function exists in the namespace , Will appear :(A)
A. Compile error
B. Grammar mistakes
C. Logic error
D. The error type cannot be determined
2-4
To specify which namespace the identifier belongs to , You need to add... Between the identifier and the namespace name :(A)
A.::
B.->
C…
D.( )
2-5
If the function of the default parameter is declared as “ void fun(int a,int b=1,char c=‘a’,float d=3.2);”,
The correct way to call the following is (B ).
A.fun();
B.fun(2,3);
C.fun(2, ,‘c’,3.14)
D.fun(int a=1);
3、 ... and 、 Completion
1.(6 branch )A pointer allows us to pass potentially large amounts of data around at low cost: instead of copying the data we simply pass its address as a pointer value. The type of the pointer determines what can be done to the data through the pointer.
2.(8 branch )Like a pointer, a reference is an alias for an object, is usually implemented to hold a machine address of an object, and does not impose performance overhead compared to pointers, but it differs from a pointer in that:You access a reference with exactly the same syntax as the name of an object. A reference always refers to the object to which it was initialized There is no “null reference,” and we may assume that a reference refers to an object.
3.(6 branch )A reference is an alternative name for an object, an alias. The main use of references is for specifying arguments and return values for functions in general and for overloaded operators in particular.
Four 、 Fill in the blanks in the program
5-1
Use dynamic memory 1
fraction 10
author Zhang Dehui
Company Xi'an University of Posts and Telecommunications
Fill in the blanks to make the following procedures complete and run correctly .
#include
using namespace std;
int main ( )
{
double* pDouble = NULL; // initialized with null
pDouble =
new double
; // Request memory for the variable
char* pChar =
NULL
; // initialized with null
pChar = new char[20]; // Request memory for the array
cin>>*pDouble >>pChar; // Store value at allocated address
cout << *pDouble<<endl << pChar<<endl ;
delete pDouble; // free up the memory.
delete [] pChar
; // free the memory pointed to by pChar
return 0;
}
5、 ... and 、 Function questions
6-1 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 (x*y+x*z+z*y)*2;
}
6-2 Find the maximum and minimum
fraction 10
author Zhang Dehui
Company Xi'an University of Posts and Telecommunications
This question requests to realize a function f, We can find out 10 The maximum of integers max Minimum value min.
Function interface definition :
Call this function in the main function as follows
f(a,10,max,min);
for example : among a It's an array name ,max Used to save the maximum value ,min Used to save the minimum value .
Sample referee test procedure :
#include
using namespace std;
/* The code you submit will be embedded here */
int main( )
{
int a[10];
int max,min,i;
for(i=0;i<10;i++){
cin>>a[i];
}
f(a,10,max,min);
cout<<"Max: "<<max<<endl;
cout<<"Min: "<<min<<endl;
return 0;
}
sample input :
2 5 8 1 4 7 3 6 9 0
sample output :
Max: 9
Min: 0
void f(int * a,int b,int &max,int &min)
{
max = min = a[0];
for(int i=1;i<10;i++)
{
if(max<a[i])
{
max = a[i];
}
if(min>a[i])
{
min = a[i];
}
}
}
边栏推荐
- Create a table under swiftui with table
- Brief introduction of diversity technology
- [ecmascript6] modularization
- 为自定义属性包装类型添加类 @Published 的能力
- How to make the characters in the photos laugh? HMS core video editing service one click smile function makes people smile more naturally
- 在 SwiftUI 视图中打开 URL 的若干方法
- UI开发中所遇到的各种坑
- 卡方分布和伽马函数(Chi-Square Distribution)
- 围绕新市民金融聚焦差异化产品设计、智能技术提效及素养教育
- How to perform batch operations in core data
猜你喜欢

9、 Uni popup usage popup effect at the bottom of the drop-down box

2022 low voltage electrician examination questions and answers

C语言实现简单学生成绩管理系统的方法

多商户商城系统功能拆解17讲-平台端订单列表

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

Floating point data type in C language (did you learn to waste it)

Thoughts on the construction of some enterprise data platforms
C # read INI file and key value pair operation
C# 获取当前路径7种方法

BGP experiment
随机推荐
Development and definition of software testing
2022 low voltage electrician examination questions and answers
2022 safety officer-a certificate operation certificate examination question bank simulated examination platform operation
How to perform batch operations in core data
Swiftui layout - size (top)
TDengine 助力西门子轻量级数字化解决方案
468 product planning and promotion plan (150 copies)
八、picker用法 下拉框选择效果
数字化转型安全问题频发,山石网科助力数字政府建设
How to use the C language library function getchar ()
I am using a blog creation tool
Why can the anonymous functions of JQ access the methods inside
String转为long 类型报错原因:要转为long必须是int、double、float型[通俗易懂]
为什么jq的匿名函数 外部可以访问到里面的方法
文件批量重命名工具Bulk Rename Utility
pix2pix
爆肝整理JVM十大模块知识点总结,不信你还不懂
Error reason for converting string to long type: to convert to long type, it must be int, double, float type [easy to understand]
Hcip day 11
Excel VBA 开发过程中遇到的一些问题,解决方案,持续更新