C ++ test questions

xiaoxiao2021-03-06  35

First, fill in the blanket (25 small questions, a total of 1 point for each of the following questions, a total of 10 points) 1. In C , the parameters of the function have two transmission methods, they are values ​​pass and ________. 2. When a member function is called, the member function's ______ is pointing to the object called it. 3. In the base class and derived class, the derived class can define the data and operations not available in its base class. When accessing two data with the same name, if there is no ____________, an access to this data member will appear ambiguous. 4. Copy constructor uses ________ as an object in which the parameter initialization is created. 5. In the case of public inheritance, the access rights of the base class data in the derived class ____________________. 6. Description The expression "A smaller than B or less C" is _________. 7. When using a new application object array a dynamic class, in this class must be able to match ______________________ constructor, or the application will generate a compile error. 8. Static data members are initialized outside the class, and a copy of the static data member is classified all objects ________. 9. In order to avoid possible ambiguity, C pairs of rules for IF ... ELSE statements are specified as: ELSE is always paired with ________________. 10. Set "INT A = 3, B = 4, C = 5;" ", Expression" (A B)> C && B == C "is ____.

(2 points per small question, a total of 20 points) 11. Object-oriented programming has four characteristics, they are abstract, package, _______________. 12. In Visual C , when defining the overload function, at least the number of parameters or parameter type ___________________________________________________________________________________________________________________________________. 13. The constructor is different from the designer, in the definition form, the difference is also the same as the constructor name is the same as the class name, and the destructor name is added to one ~, ____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

14. Dynamic connection should meet two conditions, they are ______________________________________________. 15. In the C class, there is a class that cannot be defined objects, such a class can only be inherited, referred to as _________, define that the class has at least one ____________. 16. In the C class, the const keyword can modify the object and member function, the const object cannot ______________, the Const member function cannot _____________. 17. Call two user-defined data types in C : _______, _______. 18. There is no string type in C , and the string is represented by __________, each character string has an end character _____. 19. There is no input statement in C , and the input output is implemented by _________________________ 20, which is written to a print integer variable N: ___________ 20. Ways of two code multiplexes in C : ____________________. (4 points per small question, a total of 20 points) 21. The result of the following procedures is. #include void main () {char A = 'a', b = 'j'; float x; x = (ba) / ('f' - 'a'); Printf ("% D / n ", (int) (3.14 * x));} 22. The result of the following procedures is. #include "iostream.h" void main () {INT i = 1; while (i <= 15) {i ; if (i% 3! = 2) Continue; Else Cout << "i =" << i <

Test :: test () {cout << "initalizing default" << endl; Num = 0; fl = 0.0;}

Test :: ~ test () {cout << "desdtructor is active" << endl;}

Void main () {test array [2]; cout << array [1] .Getint () << "<< array [1] .Getfloat () endl;}

twenty four. The result of the following procedures is ________. #include Class a {public: a () {cout << "A:: a () Called./N";} Virtual ~ a () {cout << "A :: ~ a () Called./N ";}}; Class B: public a {public: b (int i) {cout <<" b :: b () Called./N "; buf = new char [i];} Virtual ~ B () {delete [] buf; cout << "b :: ~ b () Called./N";} private: char * buf;

Void Fun (a * a) {delete a;}

Void main () {a * a = new b (15); fun (a);

25. The result of the following procedures is ________. #include int a [] = {1, 3, 5, 7, 9}; int * p [] = {a, a 1, a 2, a 3, a 4}; Void main () {Printf ("% D / T% D / T% D / N", A [4], * (A 2), * p [1]); Printf ("% D / T% D / T% D / N ", ** (p 1) a [2], * (p 4) - * (p 0), * (A 3)% a [4]);}

Second, ask questions (5 points for each small question, a total of 20 points) 1. If the programmer does not define a copy constructor, the compiler automatically generates a default copy constructor, what can it be? 2. Brief description of the difference between member functions, global functions and friend functions. 3. Briefly describe the structural programming, the basic idea of ​​object-oriented programming. 4. What is the similarity of structures and class classs?

Third, find the syntax errors in the following programs (or blocks), and correct (4 points per small question, a total of 8 points) (1) The program function is inverted output a given string. #include void main () {char str [5] [] = {"first", "second", "third", "forth", "fiffh"}; char * cp [] = {STR [4], STR [3], STR [2], STR [1], STR [0]}; INT I;

While (i <= 5) {Printf ("% C", * (CP I)); i ;}} (2) The program function is to place each square root value into an array. #Include void main () {int MAX, A, I; Scanf ("% D% D", Max, A); Double X [MAX];

For (i = 0; i

Fourth, (8 points) The following SHAPE class is an abstract class representing a shape, and Area () is a function of graphic area, and Total () is a common function for the sum of graphical area of ​​different shapes. Please give a triangular shape (Rectangle), a rectangle (Rectangle), and give specific area functions Class Shape {public: Virtual float area () = 0;}; float total (Shape * s [], int n) {float sum = 0.0; for (int i = 0; i area (); return sum;} 5, (6 points) Complete order lookup function f_seq () . The process is: starting from the beginning, according to the given mode, the elements in the table are compared to the table. If you find the desired element, look for success and print out the sequence number it in the table. If you look for the entire table, you still have not found the required object, then find the failed #include void f_seq (char * list [], char * Object, int LEN) // list pointer array, pointing to string // Object mode The length of the string // LEN table {char ** p; int standardmp (char * s, char * t);

P = list; while (_____ 1 ______) // if (strcmp (* p, object) == 0) Break; ELSE ______ 2 _______; // IF (P

Sixth, (8 points) Complete the latch table inversion function Reverse, if there is a list: The structure of the list of linked list is as follows: struct node {int Num; struct node * next;} struct node * reverse // HEAD Link table head knot {struct node * p, * temp1, * temp2; if (head == null ___ 1 ____) return head; // p = head-> next; head-> next = null; while (____ 2 ____) // {TEMP1 = head; ____ 3 ____; // Temp2 = P; P = P-> Next; ____ 4 ____; //} // match while statenment return head; // Return the head of the inverse linked list}

Address or pointer or reference delivery

THIS pointer

Schend

Quote

constant

A

No point parameter or default parameters

shared

With recent IF

0

Inheritance, polymorphism

Different, the derived class member function is the same as the member function name, parameter number, parameter type, and return value types that are covered by the base class.

The destructor does not have a parameters, and the destructor can be defined as a virtual function. The called member function is a virtual function, call the virtual function abstract class with a pointer or reference, pure virtual function

Modified, modify class data member

Class, enumeration

Characters, / 0

Input and output library, cout << n;

Inherit, multiplexed

21.3

22. 2 5 8 11 14

23. Inital Qing Default Initalizing Default 0 0 Desdtructor is Active Desdtructor is ACTIVE

24. A :: A () Called. B :: b () Called. B :: ~ b () Called. A :: ~ a () Called.

25. 9 5 3 8 4 7

26. Solution Point: When the object contains a pointer data member, and uses it to initialize another object of the same type, the default copy constructor can only copy the data member of the object to another object, and cannot put the object in the object. The pointer to the memory cell is also copied. In this way, the same memory unit can be released twice, causing the program to run an error.

27. Solution Point: The following must be clear: The member function is inside the class, the scope is inside the class, the member function can access the class data member (public, protected and private data members), can call this class Other member functions (public, protected and private member functions), can call global functions. If the friend's function is another class's public member function, the member function of the class can only call the object of the object, and cannot call the protection of that class and private member functions. Non-book-based members (other class member functions or global functions) can access the public data members of this class and the public member functions of the class through this class. Not the member function defined in the class is a global function. If a function (global function or class member function) is defined as another class friend function, you need to use Friend keywords in that class, and the friend function is not a member of the class, and its definition is naturally in that. Outside of the class.

28. Signification Point: Structured Program Design Separates the data and the operation of the data, the program is composed of one function, and the object-oriented programming will be packaged together, and the program is composed of one object. Communication between the objects is communicated between the objects, which can better support the multiplexing of the program code.

29. Significant points: struct and classes can define classes, but the default access permission description, the members of the Struct are public, while the members of the Class are private. In C , Struct can be replaced by Class.

three

1

1 "char STR [5] [] = {" first "," second "," third "," forth "," fiffh "};" should be "char STR [5] [10] = {" first ", "SECOND", "Third", "Forth", "fiffh"}; "2" While (i <= 5) "should be" While (i <5) "3" Printf ("% C", * (CP i)); "should be" Printf ("% s", * (CP I))); "4" INT i; "should be" int i = 0; "

2

1 increase "#include " 2 "scanf ("% D% D ", max, a);" should be "scanf ("% D% D ", & max, & a);" 3 "Double X [MAX]; "change to:" Double * x = new double [max]; "..." delete [] x; "four

Class Triangle: Public Shape {public: triangle (double h, double w) {h = h; w = W;} double area () const {return h * w * 0.5;} private: double h, w;};

Class Rectangle: Public Shape {public: Rectangle (double h, double w) {h = h; w = W;} Double area () const {return h * w;} private: double h, w;}

Fives

P

P S-T or * S- * T or 1

six

|| Head-> Next == NULL

P! = null or P

HEAD = P;

Temp2-> Next = TEMP1; or Head-> next = TEMP1;

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

New Post(0)