- What is static Association? What is dynamic Association?
Static concatenation means that the system determines how to implement an action during compilation.
Dynamic association means that the system dynamically implements an action at runtime.
- What is the difference between the polymorphism at compilation and the polymorphism at runtime? What are their implementation methods?
The polymorphism supported by static Association is known as compile-time polymorphism, also known as static polymorphism. During compilation, polymorphism is implemented through function overloading and templates.
The polymorphism supported by dynamic Association is known as Runtime polymorphism, also known as dynamic polymorphism. It is implemented through virtual functions.
- This section briefly describes the operator overload rules.
A) The vast majority of operators in C ++ allow overloading.
B) C ++ can only overload existing C ++ operators.
C) Operator Overloading is an actual need for new types of data, and the original operators are transformed as appropriate. It should be similar to the original functions.
D) The number of operation objects of the operator cannot be changed during the overload operation.
E) Reload does not change the original operator priority.
F) The original characteristics of integration cannot be changed.
G) at least one parameter should be a class object.
H) The overload function can be a common function, a member function of the class, or a friend function of the class.
I) generally, all operators used for Object-like operations must be overloaded except the value assignment operator.
- What is the difference between a youyuan operator function and a member operator function?
A) For binary operators, the member operator overload contains a parameter, and the friend element overload contains two parameters. For single-object operators, the member overload does not have a parameter, and the friend element overload has a parameter.
B) binary operators can be overloaded as friends or members. However, if you perform an object and a common type operation, you must reload it to youyuan.
C) The call method is different.
D) generally, binary operators are used as friends, and single-object operators are used as members. If the operand has implicit type conversion, you must use a friend.
- What is a virtual function? What are the similarities and differences between virtual functions and function overloading?
Virtual functions are defined by the keyword virtual in the base class and are redefined in the derived class.
Function names are the same.
The number or type of parameters of the overload function must be different. The virtual function requires the function name, return type, number of parameters, and the type and sequence of the parameters are exactly the same as that of the virtual function prototype in the base class.
- What is a pure virtual function? What is an abstract class?
A pure virtual function is a virtual function described in the base class. It is not defined in the base class, but must be defined in its derived class as needed, or it is still a pure virtual function.
If a class has at least one pure virtual function, it is called an abstract class.
7-12 daadcc
13.
No. The number of parameters must be the same.
14.
7
6
15.
This is C ++ book.
The first character: T
16th characters :.
26th characters: the array subscript is exclusive!
16.
M = 1.5 km
17.
# Include <iostream> Using Namespace STD; Class Twodarray { Int A [ 2 ] [ 3 ]; Public : Twodarray (){ For ( Int I = 0 ; I < 2 ; I ++ ) For ( Int J = 0 ; J < 3 ; J ++ ) A [I] [J] = 5 ;} Twodarray ( Int B [] [ 3 ]) { For ( Int I = 0 ; I < 2 ; I ++ ) For ( Int J = 0 ; J < 3 ; J ++ ) A [I] [J] = B [I] [J];} Void Show (); twodarray Operator + (Twodarray N); twodarray Operator - (Twodarray N );}; Void Twodarray: Show (){ For ( Int I = 0 ; I < 2 ; I ++ ){ For ( Int J = 0 ; J < 3 ; J ++ ) Cout < A [I] [J]; cout < Endl ;}} twodarray :: Operator + (Twodarray N) {twodarray temp; For ( Int I = 0 ; I < 2 ; I ++ ) For ( Int J = 0 ; J < 3 ; J ++ ) Temp. A [I] [J] = A [I] [J] + N. a [I] [J]; Return Temp;} twodarray :: Operator - (Twodarray N) {twodarray temp; For ( Int I = 0 ; I < 2 ; I ++ ) For ( Int J =0 ; J < 3 ; J ++ ) Temp. A [I] [J] = A [I] [J]- N. a [I] [J]; Return Temp ;} Int Main (){ Int A [ 2 ] [ 3 ]; For ( Int I = 0 ; I < 2 ; I ++ ) For ( Int J = 0 ; J < 3 ; J ++ ) CIN > A [I] [J]; twodarray A1, A2 (A), Total, sub; Total = A1 + A2; sub = A1- A2; total. Show (); sub. Show (); Return 0 ;}
18.
# Include <iostream> Using Namespace STD; Class Twodarray { Int A [ 2 ] [ 3 ]; Public : Twodarray (){ For ( Int I =0 ; I < 2 ; I ++ ) For ( Int J = 0 ; J < 3 ; J ++ ) A [I] [J] = 5 ;} Twodarray ( Int B [] [ 3 ]) { For (Int I = 0 ; I < 2 ; I ++ ) For ( Int J = 0 ; J < 3 ; J ++ ) A [I] [J] = B [I] [J];} Void Show (); friend twodarray Operator +(Twodarray M, twodarray N); friend twodarray Operator - (Twodarray M, twodarray N );}; Void Twodarray: Show (){ For ( Int I = 0 ; I < 2 ; I ++ ){ For ( Int J = 0 ; J <3 ; J ++ ) Cout < A [I] [J]; cout < Endl ;}} twodarray Operator + (Twodarray M, twodarray N) {twodarray temp; For ( Int I = 0 ; I < 2 ; I ++ ) For ( Int J = 0 ; J < 3 ; J ++ ) Temp. A [I] [J] = M. A [I] [J] + N. a [I] [J]; Return Temp;} twodarray Operator - (Twodarray M, twodarray N) {twodarray temp; For ( Int I = 0 ; I < 2 ; I ++ ) For ( Int J = 0 ; J < 3 ; J ++ ) Temp. A [I] [J] = M. A [I] [J]- N. a [I] [J]; Return Temp ;} Int Main (){ Int A [ 2 ] [ 3 ]; For ( Int I = 0 ; I < 2 ; I ++ ) For ( Int J = 0 ; J < 3 ; J ++ ) CIN > A [I] [J]; twodarray A1, A2 (A), Total, sub; Total = A1 + A2; sub = A1-A2; total. Show (); sub. Show (); Return 0 ;}
19.
# Include <iostream> Using Namespace STD; Class Complex { Double Real, imag; Public : Complex ( Double Re,Double Im) {real = Re; imag = Im;} friend Complex Operator + (Complex A, complex B ); Void Print () ;}; Complex Operator + (Complex A, complex B ){ Return Complex (A. Real + B. Real, A. imag + B. IMAG );} Void Complex: Print () {cout < " ( " <Real < " , " <Imag < " ) " < Endl ;} Int Main () {complex C1 ( 2.5 , 3.7 ); Complex C2 ( 4.2 , 6.5 ); Complex total = C1 + C2; total. Print (); Return 0 ;}
20.
# Include <iostream> Using Namespace STD; Const Double Pi = 3.14 ; Class Container { Protected : Double R, D; // If it is spherical, r is the radius, D is 0. If it is a cylinder, r is the bottom radius, and D is high. If it is a cube, r indicates the side length, and D indicates 0. Public : Container ( Double A, Double B = 0 ) {R = A; d = B ;} Virtual Double Serface () = 0 ; // Calculated surface area Virtual Double Volume () = 0 ; // Volume Calculation }; Class Sphere: Public Container { Public : Sphere ( Double R): container (r ){} Double Serface (); Double Volume ();}; Double Sphere: serface (){ Return 4 * PI * r * R ;} Double Sphere: volume (){ Return PI * r * R ;} Class Cylinder: Public Container { Public : Cylinder ( Double A, Double B): container (a, B ){} Double Serface (); Double Volume ();}; Double Cylinder: serface (){ Return 2 * PI * r * D + pI * r * R ;} Double Cylinder: volume (){ Return PI * r * D ;} Class Cube: Public Container { Public : Cube ( Double A): container (){} Double Serface (); Double Volume ();} Double Cube: serface (){ Return 6 * R * R ;} Double Cube: volume (){ Return R * r * R ;}