第五章 c++程序的基本结构(The fifth chapter is about the basic structure of c++ program).doc
文本预览下载声明
第五章 c++程序的基本结构(The fifth chapter is about the basic structure of c++ program)
The basic structure of the fifth chapter of C++ program
5-1 what is the scope? There are several types of scope?
Solution:
The scope of discussion is the effective range of the identifier, the scope is a valid identifier in the program in the text area. The scope of C++ is divided into function prototype scope, block scope (local scope), the class scope and file scope.
5-2 what is the visibility? What is the general rule of visibility?
Solution:
Visibility is whether the identifier can refer to the problem;
The general rule is: visibility identifiers declared in front, cited in, in the same scope, identifier cannot be declared with the same name. The identifiers in the scope of the declaration of the principles are as follows: if there are two or more with a scope containing the relationship, if there is no outer identifier statement statement name identifier in the inner layer is still visible, if the statement of the same name identifier is the outer layer identifier is not visible.
What is the 5-3 following the operation of the program, the actual operation, see differ from your idea.
#include iostream.h
Void (myFunction);
Int x = 5, y = 7;
Int (main)
{
Cout x from main: X \n;
Cout Y from main: Y \n\n;
(myFunction);
The cout Back from myFunction \n\n;
Cout x from main: X \n;
Cout Y from main: Y \n;
Return 0;
}
Void (myFunction)
{
Int y = 10;
Cout x from myFunction: X \n;
Cout Y from myFunction: Y \n\n;
}
Solution:
Program output:
X from main: 5
Y from main: 7
X from myFunction: 5
Y from myFunction: 10
Back from myFunction!
X from main: 5
Y from main: 7
5-4 if there are two relationship between class Engine and Fuel, when used, how Fuel allows members to access private members and protection in Engine?
Solution:
Source program:
Class fuel;
Class Engine
{
Friend class fuel;
Private;
Int powerlevel;
Public;
(engine) {powerLevel = 0;}
Void engine_fn (fuel f);
};
Class fuel
{
Fr
显示全部