Set of C ++ test questions ...

xiaoxiao2021-03-06  20

1. (10 points, 1 point each question) Single item selection 1. For global functions INT F (Void), with its full equivalent function prototype: A. INT & f (); B. Int f (void) const; C. Const int F (); D. A, B, C are not 2. Unique non-static member functions INT F (A & One) and private data member INT X; then in this member function There can be statements in the function body: A. Return One.f (this); B. x = f (this); C. THIS-> F (X.one); D. Int * const px = & one.x; 3 The following is the following statement about the NEW and DELETE operators, which is incorrect: A. Using the New operator, you can dynamically assign memory resources in the global stack. B. If the type P has been converted to Void *, then execute the statement delete P;, the destructor of class A will not be called. C. When implementing a global function, New and Delete are usually pairs in a statement block defined by a pair of matching curly brackets. D. Execute Statement A * P = New A [100]; When the constructor of class A will only be called once. 4. Class TM and class TN are two separate classes, such as which form of data in class is not allowed: A. Tm * a; B. TN & A; C. TM A; D. TN A 5. Class B is derived from class A by public inheritance, and class A and class B have a complete implementation code, then the following statements are: A. Class B has a Pubic accessibility member The number of functions must be not less than the number of PUBLIC member functions in class A. B. Instance objects of a class B occupy a memory space that is not less than a memory space occupied by an instance object of class A. C. As long as the constructor in class B is public, the instance object of class B can be created in the main function. D. The return value type of the same name virtual function in class A and class B must be exactly the same. 6. Which of the following functions can be empty: A. Custom constructor B. Copy constructor C. Static member function D. Destructor 7. Class A has an instantiated constant object A, then the following statement Incorrect in: A. Nonstiotic data members in class A must be a constant member. B. You can directly call the constant member functions of class A. C. A cannot be used directly as a left value expression. D. A can be a static constant object. 8. In the case where the mandatory type conversion is not considered, the following statement about the constant members in the class is incorrect: A. The non-static data member in this class cannot be modified in the constant member function. B. Any static member function in this class can be called in the constant member function. C. The return value of the constant member function can only be VOID or constant. D. If the virtual function f is called in the constant member function, the function f is also a constant member function in this class. 9. Class C is inherited from class A and class B in a multi-inheritance method, class A and class B non-public base classes, then: A. The inheritance mode of class C can only be inherited by PUBLIC. B. You can change the same functionality of class C to the same manner. C. At least one of Class A and class B is an abstract class. D. At least one of class A and class B is a virtual base class. 10. Which usage does not embody a combination relationship between classes A and class B: A. Class A declared data member B; B. B. Class A declared data member B * B; C. Class A declaration data member Const B & B; D. Class A Declaration Member Function B Func (B & Obj); Second, 10 points, 2 points for each question, multiple choices, less select, wrong selection, multiple selection 1. About The correctness of the pointer variable and reference variable is: A. The pointer variable is stored in the memory address and can be set to 0. B. When defining a reference variable, you must simultaneously specify the object or variable of the specific referenced.

C. Using the address operator, you can obtain the address of the pointer variable itself, but the address of the reference variable itself cannot be removed. D. The data in the class can be a pointer variable, but it is not a reference variable. 2. A unique public member function f in class A. For an object A of class A, execute statement AF (100); success, then F function prototype can be: A. A & F (int, int = 50) B.void f (int "; C. Const a * f (const Int); D. A F (const Int &) const; 3. About the correct statement of the overloaded assignment operator in the class is: A. Compile The default assignment function provided by the device has a PUBLIC accessibility and performs a bit bit assignment. B. When the assignment operation of the heavy duty derived class, not only the value of the data member in the derived class, but also responsible for the assignment of data members in the base class. C. Only the assignment operation of the overload class is only required when including a pointer data member or reference data member. D. By modifying the declaration or definition of class A, users can prohibit any assignment operations between class A objects. 4. In the implementation of the static member function of the class, you can access or call: A. Static data member in this class B. This class is non-static constant data member C. Other static member functions in this class. Non-static member functions in this class 5. Abnormal handling mechanisms provided by exception and C are: A. If the programmer foresees the exception in the program, it must be modified by modifying the program code to avoid abnormal appearance. B. Use the Dynamic_CAST operator that may produce an exception. C. Exceptions can be captured with CATCH. D. Exception can be an object or a normal integer. Third, (a total of 20 points, 2 points for each question) Judging the wrong mistake, for the discussion of the error, explain the reasons or 1. The static variables declared in the function will only be initialized once. 2. For two non-static member functions in the same class, their function name, parameter type, parameter number, parameter order, and the type of return value cannot be identical. 3. The Inline function indicates that the compiler will definitely insert the function body directly into the place where this function is called, so that the running speed of the program can be accepted. 4. Each CPP file is compiled separately, but the compilation order of multiple CPP files in a program is not fixed. 5. Accessibility of all constructor of class A is limited to private, then the instance object of class A is not possible in the main function. 6. The namespace is a multi-layer nested; for function members and data members in class A, they all belong to a layer name space of the class name A representative. 7. If you declare an integer member variable INT x with the same name, then the same name is declared, then the value of the variable x in the base class base is not possible via the instance object of the DeriveD class. 8. If class A is a friend class of class B, class B is a class friend class, then class A is also a class of friends class C. 9. Although the destructor of the abstract class can be a pure virtual function, it is necessary to instantiate its derived class object, and a function of the abstract base class must be provided. 10. Contents in the initialization list of functions, does not affect the initialization order of the member data in the constructive object.

Fourth, (5 points) Write the results of the following procedures #include class a {public: a (int V1) (v1) {f ();} Virtual ~ a () {f (); Virtual void f () { count; x = 10; show ();} Virtual void show () const {cound << "count = << count <<" x = << x << endl;} Protected: static int count; private: int x;}; class b: public a {public: b (int V1, int V2): a (v1), y (v2) {f ();} Virtual ~ b () {f ();} Virtual void f () { count; y = 50; show ();} Virtual void show () const {cout << "count = << count <<" y = "<< y << Endl;} private: int y;}; int a :: count = 0; int main () {a * p = new b (1, 2); P-> f (); delete p; return 0 } 5 (5 points) Write the results of the following procedures #include class a {private: Friend Class B; A (int val = 0): Data (VAL), Use (1) {} INT Use, data;}; class b {public: b (int val = 0): PA (New A (VAL)) {} ~ b () {IF (- PA-> USE == 0) delete Pa; } B (const b & rhs) { rhs-> use; pa = rhs.pa;} b & operator = (const b & rhs); a * operator -> () const {return pa;} void display () const} COUT << "Data =" << PA-> Data << "USE =" << PA-> Use << Endl;} Private: a * pa;}; b & b :: operator = (CO NST B & RHS) {IF (this == & r HS) Return * this; IF (--PA-> USE == 0) delete Pa; rhs-> use; pa = rhs.pa; return * this;} int Main () {B B1 (1), B2 (b1), b3 (3); b1.display (); b2.display (); b3.display (); b3 = b1; b1.display (); b3. Display (); Return 0;} 6, (a total of 20 points) Answer the following questions 1. Instructions in the public, protected, and private member functions in the public, protected and private member functions in the derived class in the derived class in public, protected and private inheritance. .

(4 points) 2. If class A and class B have no inheritance relationship, for function Void Func (A &), at least two different methods will be used to pass a very quite B-class object to the FUNC function. (4 points) 3. When the constructor, destructive function, pure virtual function, static member function, non-static member function, and all-end functions as class friend functions, which can be a constant member function? (3 points) 4. Example of overload, redefine, and override meaning. (3 points) 5. The prototype of the copy constructor of the usual class A is written as A (Const A &); "Why must the parameter must use the reference form? What is the role in addition to preventing the modification of the constructor from being delivered to the constructor in addition to the CONST modifier? (3 points) 6. Codes such as ( i) (i ) or F ( i) or F ( i) ) are required, please do not write code like ( i) or F ( I, I ). (3 points) Seven, (a total of 8 points) Read the following section program code to complete 3 issues. #include class a {public: a (int V1) (v1) {} virtual int getdata () const {return x;} private: int x;}; Class B: public a {public: b ( INT V1, INT V2): A (V1), Y (V2) {} Virtual Int GetData () const {return y;} private: int y;}; class c: public b {public: c (int V1, int V2, INT V3): B (V1, V2), Z (V3) {} Virtual int getdata () const {return z;} private: int z;}; const a & max2 (const a & one, const a & two) { Return (One> Two? One: Two);} void main () {B (1, 2); C C (100, 10, 1); cout << max2 (b, c) .Getdata () << Endl; cout << max2 (b, 5) .getdata () << Endl;} 1) (4 points) Please add the necessary functions without changing the above-mentioned code, make the program to compile and run, And output results 2 and 5. The actual comparison is B.Y and C.Z when comparing data members defined by derivation class, such as the object C of the class B and class C, such as the object C of the comparative class B, and C.. 2) (2 points) If the function MAX2 is not changed, only the function declaration is changed to A & Max2 (Const A & One, Const A & Two). Do you do this? why? 3) (2 points) If there is statement a * p = new c (1, 2, 3) in main, and DELETE P; then, such a, class B, and class C should be modified? Eight, (a total of 10 points) Now consider writing a poker game: only use a poker, poker color (Suit) is divided into spade, heart, diamond and club, 13 small colors, face value (RANK) is 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King and ACE, each poker card should contain the following information: the only ID number (1-52), Colors, face values, numbers of back patterns, etc.

转载请注明原文地址:https://www.9cbs.com/read-67599.html

New Post(0)