Bài tập Lý Thuyết Lập Trình C++
Mình đang có 1 số tư liệu về lập trình C++ và đây là những câu hỏi lý thuyết lập trình C++ cho các bạn tham khảo thêm(bằng tiếng anh), mọi người cùng giải với mình nghen.
1/ Which of these statement about advantages of C++ are true?
a. Clean for teaching of the basic of OOP
b. Can focus on distinct object
c. None of the others
d. A multi-paradigm language
e. Complex enough for teaching the advanced concepts
f. All of the others
g. Realistic, efficient and flexible
h. a subset of C
2/ What’s object?
a. State
b. Chunk
c. Behavior
d. state & behavior
e. None of the other
i. An abstraction of one important aspect of the problem domain
j. All of the others
3/ Which of these statement about feature of object are true?
a. Crisp boundary
b. Can’t share a common structure
c. An application must contain at least object
d. All of the others
e. The values stored in each object may vary from object to object
f. None of the others
g. Integrity
4/ Class is an instantiation of object ?
FALSE
5/ Which of these statements about encapsulation are not true?
a. A well-encapsulated object has all of its implementation details hidden within the object
b. If an object is well-encapsulated, a programmer can’t change the object’s internal structure
c. All of the others
d. None of the others
e. Encapsulation separates the implementation details of an object from its external appearance
k. Encapsulation focuses on the interior of an object, combining the data that describes the object’s behavior and the algorithms that define its state
6/ Inheritance is
a. Ability that allows a class receiving method prototypes only from another class
b. Ability that allows a class receiving data and codes from another class.
c. None of the others
d. Ability that allows a class receiving codes only from another class.
e. Ability that allows a class receive data only from another class.
7/ Which of the following is not a valid comment in C++
a. /** comment /
b. / comment
c. / comment /
d. All of the others
e. // comment
8/ Advantages of inheritace are
a. A techniques that help programmers reducing cost when implementing and testing code
b. A techniques that cause unnecessary complications in coding for programmers.
9/ Select correct statements
a. A software object’s behavior is exposed through methods
b. A software object’s state is stored in fields
c. A blueprint for a software object is called frame
d. Real-world objects contain state and behaviors
10/ Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as data …
a. Encapsulation
b. Grouping
c. Preventing
d. Packaging
e. Hiding
11/ Which of these statements about const return value are true?
a. All of the others
b. The pointer may not hold the address of an unmodifiable array
c. A function can’t return a constants pointer as well as a data value
d. None of the others
e. A function can’t return a pointer as well as a data value
f. Using of the const keyword can improve type safety by qualifying such return values as read-only values
12/ The const char const str = str1; statement is reference
a. Unmodifiable variable
b. None of the others
c. Unmodifiable pointer
d. All of the others
e. The incorrect statement
f. Unmodifiable arrays
13/ We can’t define program constants using const instead of #define
a. True
b. False
11/ Which of these statements about derived type are true?
a. All of the others
b. We refer to data described by a derived type as an object of that type
c. A member of a derived type may be of primitive type
d. A collection of types that describes that rules for interpreting the information stored in a region of memory
e. Cannot redefine these sets or introduce new primitive types
f. None of the others
g. A member of a derived type may be of other derived types
h. Array identifies a derived type
12/ Which of these statement about accessing struct member are true?
a. Access the address of an element of an array member (&instance.member[index])
b. None of the others
c. Access a member of an instance of a derived type ( member)
d. All of the others
e. Access the address of a non-array member using the address of operator (*instance.member)
f. Access a member of an instance of a derived type using dot notation. (&instance.member)
g. Access an element of an array member using index notation (instance.member[index])
13/ Study the following code segment:
Struct Employee {int code; char name[30]};
Const Employee emp = {12, “James Bond”};
Choose one answer
a. The above codes cause an error.
b. The above codes cause an error because we can not initialize a structure.
c. The above codes cause an error because we can not declare a constant structure.
d. The above codes are valid
e. The above codes cause an error because we need to declare a structure as: const struct Employee emp = {12, “James Bond”};
14/ Select incorrect statement
a. We should not use structure pointer as a parameter of a function because such functions need more memory that value parameter ones
b. We should use structure pointer as a parameter of a funtion because such functions need not to copy original structure when they are called
c. We should use structure pointer as a parameter of a function because such functions need less memory than value-parameter ones.
d. We should not use structure pointer as a parameter of a function because such functions need a structure-copy operation when they are called.
15/ Signature of a function consist of
a. Function prototype
b. Function body
c. Function name
d. Parameter types
e. Order of parameter types
16/ Overloading is
a. Ability that allows programmers implementing functions have the same name but have distinct parameter type orders
b. Ability that allows programmers declare variables that have the same name .
c. Ability that allows programmers implementing functions have the different name but have the same parameter type orders
d. Ability that allows programmers implementing functions in the same program.
17/ Select correct statement
a. Alias is another name of a variable.
b. Alias is a pointer of a variable.
c. Both variable name and its alias represent the same data
d. Alias is a function that will act on the variable.
18/ A simple program has … memory block
a. 2
b. 1
c. 4
d. 5
e. 3
19/ A variable can be put at one of … memory blocks of the program
a. 5
b. 2
c. 3
d. 4
20/ The operator & can get the address of
a. software
f. Funtion
g. Variable
h. Program
21/ Select incorrect statements
a. The operator delete is used when one dynamic data is de-allocated.
b. The operator new is used when one dynamic data is needed.
c. The operator delete[] is used when one dynamic data is de-allocated.
d. The operator new[] is used when one dynamic data is needed.
22/ As default, a member of a structure is
a. Internal
b. Private
c. Static
d. Public
23/ The access modifier private is used to …
a. Hide a member of a structure and the outside can access it by means of a public function only.
b. Hide a member of a structure and the outside can access it by means of a private function only.
c. Hide a member of a structure and the outside can access it by means of other tools.
d. Hide a member of a structure and the outside can access it by means of another program.
24/ Select incorrect statement
a. The operator >>, << of the istream and ostream objects are usually used for entering/displaying structure from/to console
b. << is called extraction operator and >> is called insertion operator
c. The operators >> , << of the istream and ostream objects are usually used for entering/displaying basic data from/to console .
d. The operators >> , << of the istream and ostream objects support automatically converting over simple data types .
e. As default, the operator >> of the istream object does not support for entering a string that contains blank characters.
25/ Which of the ostream object: cout, cerr, clog, is (are) buffered stream?
a. cout, cerr
b. cout, cerr, clog
c. All of the others
d. cerr, clog
e. cout, clog
f. None of the others
26/ To enter a string that con contain blank characters. We should use … of the istream object
a. The operator <<
b. The operator >>
f. The function getline(…)
g. The function get(…)
h. The function peek()
27/ Which of these statements about get() in istream objects are true
a. None of the others
b. should not call get() twice without removing the delimiting character, if there is one
c. get() gets a line of characters from the stream
d. get() skips leading whitespace with numeric, string and character data types
e. get() does not skip leading whitespace and leaves the delimiting character in the stream
f. All of the others
g. get() appends a null byte to the sequence of characters removed from the stream
h. get() treats whitespace as a delimiter for numeric and string data types
28/ Which of these statements about cin are not true?
a. cin is the istream object defined for buffered input in the standard library
b. cin skips leading whitespace with numeric, string and character data types
c. None or the others
d. All of the others
e. cin extracts a stream of text characters from directly standard input
f. cin uses << as the extraction operator
g. cin treats whitespace as a delimiter for numeric and string data types
29/ Which of these statements about privacy are true ?
a. None of the others
b. To make a member of an object inaccessible from the outside, the public keyword is used
c. To make a member of an object inaccessible from the outside, the protected keyword is used
d. To make a member of an object accessible from the outside, the protected keyword is used
e. To make a member of an object accessible from the outside, the private keyword is used
f. All of the others
30/ When do the memory leak occur?
a. The pointer point address before the memory has been deallocated
b. A pointer to the static memory goes out of scope before the memory has been deallocated
c. A pointer to the dynamic memory goes out of scope before the memory has been deallocated
d. None of the others
e. The pointer changes value before the memory has been deallocated
f. All of the others
31/ Select correct statements
a. In practical, modifiers of a class are usually implemented as set-methods
b. In practical, modifiers of a class are usually implemented as get-methods
c. In practical, queries of a class are usually implemented as set-methods
d. In practical, queries of a class are usually implemented as get-methods
32/ In C++, we can overload
a. All of the others
b. Constructors and some operators
c. None of the others
d. Fields, methods and all operators
e. Constructors, destructors, methods, some operators
f. Destructor and some operators
g. Constructors, methods, some operator
33/ What operators can be overloaded in C++?
a. None of the others
b. +, - , . , ++, –
c. +, -, /, &&, ||, ++, –
d. All of the others
e. +, -, #
f. +, -. *, /, ++, --, &&, ||, |, &, ::
34/ The following codes are seen in an implementation of a class’method. Select incorrect statement
a. (*this).empCode=12;
b. this -> empCode=12;
e. (*this) -> empCode = 12;
f. this.empCode = 12;
35/ Friend function can access…members of a class in which it is declared
a. None of the others
a. Protected
b. Public
c. Private
36/ Friend function can not access … members of a class in which it is declared
a. Public
b. None of the others
c. Private
d. Protected
37/ Select incorrect statement(s)
a. When a friend function is implemented, the keyword friend must be let at the beginning of function.
b. Destructor of a class may be accept a parameter
c. We can use a class in which no constructor is implemented.
d. We can not use a class in which no constructor is implemented.
e. Constructor of a class may accept parameters.
38/ Select the best proposal when studying the following class:
class Array
{ int *a,n;
Public: Array() {n = 100; a = new int[n]; }
};
Choose one answer:
a. More constructors should be implemented.
b. No thing is proposed.
c. More meaningful methods should be implemented.
d. Destructors should be implemented
39/ Select incorrect statement(s)
a. Constructor of a class may have parameters.
e. Destructor of a class should have parameters
f. Constructor of a class must have at least a parameter
g. Destructor of a class must have paramets
40/ Give necessary proposals
a. No modification is proposed.
b. The body of constructor need to be modified.
c. Remove [] in the body of the destructor.
d. Let the keyword private at the front of data members.
e. The parameter of the destructor need to be removed.
41/ Select incorrect statement
a. The lifetime of an object begins at the time this object is created and ends when all program executed.
b. The lifetime of an object extends all the duration in which the program executes.
c. None of the others
d. The lifetime of an object begins at the time this object is created and ends when the code block, that contains it, executed.
42/ Select correct statements
a. Friend function implementations must begin with the keyword friend.
f. Friend functions and helpers usually accept objects as parameters
g. Friend functions and helpers are treated as non-member functions of a class
h. Friend function prototypes must begin with the keyword friend
i. Friend functions and helpers are implemented as global functions
43/ If the class B is declared as a friend of the class A then
a. B can access all members of A.
b. A can access private members of B only.
c. A and B are friend of each other.
d. B can access private members of A only.
e. A can access all members of B.
44/ With respect to functionality, …
a. An operator is similar with a return method but they are declared differently
b. An operator is similar with a return method but they are used with differently syntaxes
c. An operator is different from a return method
d. None of others
45/ Select correct statement
a. Asymmetric syntax is usually used when an operator accepts at least two parameters.
b. Symmetric syntax is usually used when an operator accepts two parameters and it is declared as class-operator.
c. Symmetric syntax is usually used when an operator accepts two parameters and it is declared as a friend operator of a class.
d. Asymmetric syntax is usually used when an operator accepts one parameter.
46/ Which of these statements about instance of classes are true?
a. The program accesses the code in function calls from all instances of the class
b. We call the data members of an object its instance class
c. Instance classes may be of built-in data type, derived data type
d. None of the others
e. An instance of a class is called object
f. The declaration of an instance allocates memory for the object
g. The instances of a class do not share the member function code with all other instances of that class
h. All of the others
47/ Which of these statements about UML are not true?
a. The mid compartment contains the names and data types of the instance variables
b. The member names are suffixed with a colon ( : ) followed by the data type
c. The bottom compartment contains the names and return data types of the member functions
d. The top compartment contains the name of the class
e. All of the others
f. None of the others
g. UML includes graphical representations for various design components
48/ Which of these statements about constructors are true?
a. Single argument constructors play a special role
b. Object construction proceeds in the following order execute the constructor code, then allocate memory for each instance variable in the order listed in the class declaration
c. All of the others
d. A constructor should return a value and have a return data type
e. None of the others
f. A constructor is a special member function that is called during the creation of an object
g. If a class declaration includes a constructor that takes arguments but does not include a no-arguments constructor, the compiler DOES NOT insert an empty body no-argument constructor
49/ Which of these statements about destructors are not true?
a. All of the others
b. A destructor return a value with a data type
c. A destructor take any parameters
d. None of the others
e. The destructor takes its name from any name that is named by developer
f. Object destruction takes the following order deallocate memory for each instance variable in opposite order to that listed in the class declaration, then execute the destructor code
g. A destructor is called just after an object goes out of scope
50/ 1. Each member function has direct access to all members of its class, including private members
2. There is no need to pass the values of these instance variables through a function’s parameter list
Both 1 and 2 true
51/ Which of these statements about this keyword are true ?
a. The keyword this holds the values of the current object
b. Refer to the entire set of instance variables of an object, rather than to one particular instance variable
c. None of the others
d. Can use this from any where in program
e. To refer to the entire set of instance variables this
f. The keyword this holds the address of the current object
g. All of the others
52/ Which of these statements about overloaded function are not true?
a. The signature of a member function consists of the const status of the function
b. The signature of a member function consists of the function name
c. The signature of a member function consists of the order of the parameters and possibly
e. The signature of a member function consists of the return data type
f. The signature of a member function consists of the data types of its parameters
g. None of the others
h. All of the others
53/ We may overload the ternary operator (?:), the member selection operator (.)
False
54/ Which of these statements about overloaded operator are true?
a. None of the others
b. The signature of a member function consists of the return data type
c. All of the others
d. The signature of a member function consists of the keyword operator
e. The signature of a member function consists of the operator symbol
f. The signature of a member function consists of the operands as parameters
55/ Which of these statements about friend functions are true?
a. All of the others
b. That we apply the keyword friend to the function declaration within the class declaration, but not to the function definition itself
c. Friend functions can grant access to its private members
d. For symmetry, let us overload the operator for identical operand types but in reverse order
e. None of the others
f. To adding more queries, we can explicitly grant a non-member function access to the private members of the class
56/ Which of these statements about friend class are true?
a. A is a friend of B, B is a friend of C, A is not necessarily a friend of C
b. A is a friend of B, B is a friend of C, A is necessarily a friend of C
c. All of the others
d. Friendship is neither associative nor transitive
e. B is a friend of A, but the A is necessarily a friend of B
57/ Choose at least one answer
a. Right order of execution: Base class constructor, Subclass constructor
b. Right order of execution: Subclass destructor, base class destructor
c. None of the others
d. Right order of memory de-allocation: Subclass data, Base class data
e. Right order of memory allocation: Base class data, Subclass data
58/ Subclass can inherit … of the base class
a. Destructor
b. Constructors
c. None of the others
d. Operator =
59/ Select correct statement(s). Choose at least one answer
a. The term interface refers to an abstract class that contains no data members
b. Subclass should have its own copy constructor
c. Abstract class as a class which has at least one abstract method
d. Syntax for abstract class declaration: abstract class ClassName
e. Derive a new class from its abstract class and use it in the derived class
f. Holds the form of objects that are to implement the concept
g. A class that includes at least one pure virtual function
h. None of the orther
i. All of the others
60/ Select incorrect statement(s). Choose at least one answer
a. Abstract void M1(); is an abstract method
b. Virtual void M1() = 0 { } is an abstract method
c. Virtual void M1() { } is an abstract method
d. Virtual int M1() = 0; is an abstract method
e. Virtual void M1() = 0; is an abstract method
61/ Select incorrect statement(s). Choose at least one answer
a. virtual int M1() =0 { } is a pure virtual method
b. virtual int M1() =0; is a pure virtual method .
c. virtual void M1() =0; is a pure virtual method
d. virtual void M1() =0 { } is a pure virtual method.
e. virtual double M1()=0; is a pure virtual method
62/ Select incorrect statement(s). Choose at least one answer
a. We can declare a pointer of an abstract class.
b. We can not declare a pointer of an abstract class.
c. We can not instantiate an object of an abstract class.
d. We can instantiate an object of a concrete class only.
e. We can instantiate an object of an abstract class
63/ Select incorrect statement(s). Choose at least one answer
a. Syntax for abstract method: virtual ReturnType Name () =0;
b. Syntax for abstract method: virtual ReturnType Name ();
c. Syntax for abstract method: virtual ReturnType Name () {}
d. Syntax for abstract method: abstract ReturnType Name () {}
e. Syntax for abstract method: abstract ReturnType Name () ;
64/ The standard ISO/IEC 14882, 1998, for C++ language contains some new features:
a. stream library is rewritten
b. None of the others
c. String library is rewritten
d. Namespace
65/ Namespace is
a. Used to prevent conflicts in identifiers used by an application
b. May contain declarations of local identifiers
c. A string contains some names
d. d. A named scope
e. None of the others
66/ Concepts associated with the chunking information
a. Abstraction
b. Description
c. Hierarchy
d. Encapsulation
e. Activities
67/ Select correct statements. Choose at least one answer
a. Abstraction increases the complexity of a problem domain
b. Behaviors of an object are outside of the object
c. Abstraction reduces the complexity of a problem domain
d. The objects that make up the solution ignore the non-essential features of the problem
68/ Select correct statements. Choose at least one answer
a. Aggregation describes a “has a” relationship between two objects.
b. Encapsulation exposes the implementation details of an object to the outside.
c. Association between two objects can be an aggregation or a shared structure and behavior relationship.
d. Aggregation describes a “is a” relationship between two objects.
e. Encapsulation helps hiding detail implementations of an object.
69/ Select correct statements. Choose at least one answer
a. An instance of a class needs a block memory that will store its state.
b. A class is a blueprint for creating instances.
c. State of an instance is a set of behaviors that it has.
d. A class is an instance.
70/ Select correct statements. Choose at least one answer
a. The default modifier of a member in a C++ class is public
b. The default modifier of a member in a C++ structure is public
c. The default modifier of a member in a C++ class is private
d. The default modifier of a member in a C++ structure is private
71/ Study the C++ declaration: int*a ;
a. It is a pointer that can point to an integer
b. It is a pointer that can point to an array of integers
c. It is a pointer that can point to an array of integers only
d. It is a pointer that will point to an integer only
72/ When do the memory leaks occur?
a. The pointer point address before the memory has been deallocated
b. A pointer to the dynamic memory goes out of scope before the memory has been deallocated
c. None of the others
d. A pointer to the static memory goes out of scope before the memory has been deallocated
e. All of the others
f. The pointer changes value before the memory has been deallocated
73/ Polymorphism means
a. Refers to the flexibility of associating different data types with objects and functions
b. Means many forms
c. Finds its most powerful application in inheritance hierarchies
d. All of the others
e. None of the others
74/ Which of these statements about coercion in polymorphism are not true?
a. Automatic type conversions invoked by the compiler to change one type to another as a result of the compiler’s attempts to match a function definition to the argument types in a function call
b. Coercion is implemented at runtime
c. Coercion may be further subdivided into overloading and widening
d. Coercion is implemented at compile time
e. None of the others
f. All of the others
75/ Which of these statements about function binding are true?
a. Have 2 forms: middle and late binding
b. An early binding is a binding between a function call and a function definition that is defined at runtime
c. A late binding is a binding between a function call and a function definition that is defined at compile time
d. None of the others
e. All of the others
76/ Inclusion polymorphism is extremely useful in minimizing the amount of code written
a. True
b. False
77/ To implement late binding, the compiler inserts … that holds the information needed to select the appropriate function at run time
a. The virtual table
b. The instance of class
c. The address table
d. The object’s code
78/ The first step in OO design is ……
a. Identifying all key concepts in the problem.
b. Identifying vocabulary of the problem.
c. Identifying functions of the problem
d. Identifying the directory that will store all result of the solution
79/ In the description of the problem,
a. Nouns can be classes that may be implemented.
b. Verbs can be classes that may be declared.
c. Nouns can be operations that may be implemented.
d. Verbs can be methods that may be implemented.
80/ Select correct statements. Choose at least one answer.
a. A way that helps the invariant of a class is making necessary validations in constructors and setters(modifiers).
b. A way that helps the invariant of a class is creating a getter (query) and a setter(modifier) for each data member of the class…
c. A simple way to implement methods of a class is supporting a getter and a setter for every data member of the class.
d. The invariant of an object is that property that makes the state of an object well-defined.
81/ Select correct statements. Choose at least one answer.
a. There may be an association relationship between two classes
b. A class hierarchy is a group of simple classes.
c. A class can be an isolating and simple class.
d. A class hierarchy is based on aggregation relationship between classes
82/ Select correct statements. Choose at least one answer.
a. Two isolating and simple classes can have a inheritance between them.
b. An association between two classes is a semantic connection between classes
c. There may be an aggregation relationship between two classes.
d. A class hierarchy is based on inheritance relationship between classes.
e. In a class hierarchy, the base class is a member of a derived class.
83/ Select correct statements
a. Java is a hybrid language
b. C++ is a pure OO language
c. C++ contains almost all of C as a subset
d. C is not an OO language
84/ Select correct statements
a. Class is description for a group of objects
b. Class contains function members only
c. Class contains data members only
d. Abstraction helps identifying classes that will be created
85/ Select incorrect guidelines and statements
a. The set of modules should be loosely coupled
b. Each module must contains the main function
c. Each module should be a highly cohesive unit
d. A software should be created from only the module
e. A module is a physical unit of a program
86/ Select correct statements
a. C++ allows group data and functions into a structure
b. C++ allows group data and functions into a structure only
c. C++ allows group data and functions into a class only
d. In C++, the main function can be implemented in a class
e. C++ allows group data and functions into a class
87/ Select incorrect statements
a. C++ allows encapsulating data and function into a class only
b. A structure in C++ can not contains functions
c. C++ allows a class including data members and function members
d. C++ allows a structure including data members and function members
88/ Compilers convert array subscript notation into the equivalent … notation
a. Pointer
b. By value
c. Variable
d. None of the others
89/ Signature of a function includes:
a. Number of parameters
b. Name of the function
c. Body of the function
d. Order of types of parameters
e. Names of parameters
90/ Deep copy is usually implemented by …
a. Assignment operator
b. Copy constructor
c. All methods of a class
d. A custom method of copying
91/ Select correct statements
a. A class can have one constructor only
b. A class can have one destructor only
c. A class can have many destructors
d. A class can have many constructors
92/ Which of these statements about inheritance are true?
a. An inheritance is a relationship where objects share a common information/contents
b. Inherited classes share a common structure
c. The derived class inherits the structure of a base class
d. In object-oriented programming, we describe inheritance in terms of instance
e. None of the others
f. All of the others
93/ Select correct statements
a. Inheritance is a relationship where objects share a common structure
b. The class A is father of the class B. So, the class A contains all members of the class B
c. The class B inherits the class A. We can say that B is an A
d. The base class inherits the structure of the derived class
e. The father class of some concrete classes will be identified and contains the common members of these concrete classes
94/ The derived class does not inherit … of the base class
a. Modifiers
b. Queries
c. Constructor
d. Destructor
e. Assignment operator
95/ How many type checking?
a. 1
b. 2
c. 3
d. 4
e. 5
f. None of the others
96/ Polymorphism following Cardelli and Wegner include
a. Ad-hoc
b. Universal
c. Overloading
d. Coercion
e. All of the others
f. None of the others
97/ Ad-hoc polymorphism includes
a. Overloading
b. Parametric
c. Coercion
d. Inclusion
98/ An object fully declared at compile time is …
a. Monomorphic
b. Polymorphic
c. Monotonic
d. None of the others
99/ An invoice can contain some products and a product can be contained in some invoices. So, the relationship between the class for an invoice and the class for a product is an …
a. None of the others
b. Aggregation
c. Association
d. Inheritance
100/ An invoice is issued to a customer only. So, the relationship between the class for an invoice and the class for a customer is an …
a. Association
b. Inheritance
c. Aggregation
d. None of the others
101/ A project can be carried out by some employees and an employee can join to some projects. So, the relationship between the class for a project and the class for a employee is an
a. Aggregation
b. Association
c. None of the others
d. Inheritance
102/ An association relationship describes a … relation between two classes
a. 1-1
b. n-n
c. None of the others
d. 1-n
103/ Select correct statements
a. Basic function members of a class are: queries, modifiers
b. A scenario that we expect the application to process in called ‘use-case’
c. Queries of a class are used to be implemented as setters
d. Modifiers of a class are used to be implemented as setters
e. An application can have one use-case only