homework3

advertisement
Homework2
The first question
Please answer the following questions.
1. What #include statement do you put at the top of a program that does uses
cin or cout?
Answer: # include <iostream>
2. What using statement do you always put at the top of your programs (to
get standard naming conventions)?
Answer: using namespace std ;
3. Declare an integer variable N and initialize it to 10.
Answer: int N = 10;
4. Give a statement to increase the value of variable N by 10 .
Answer: N = N + 10;
second question:
1..
True or false: Like any C++ function, a constructor may be overloaded, providing
each constructor has a unique parameter list.(T(
2.
True or false: A class may have a constructor with no parameter list, and an
overloaded constructor whose parameters.(T(
3.
True or false: Objects can be passed to functions, but they cannot be returned by
functions.(F(
4.
True or false: When an object is passed to a function, but the function is not
supposed to change it, it should be passed by value.(T)
second question
Write the output of the following code:
1
The third question
Circle the correct answer No:
1. A class's __________ is called when an object is destroyed.
a. constructor
b. destructor
c. assignment function
d. copy constructor
Answer: Option B
2. How many types of polymorphisms are supported by C?++
A. 1
B. 2
C. 3
D. 4
Answer: Option B
3.Which of the following is correct about class and structure?
A. class can have member functions while structure cannot.
B. class data members are public by default while that of structure are private.
C. Pointer to structure or classes cannot be declared.
D. class data members are private by default while that of structure are public by
default.
Answer: Option D
4. Which of the following operator is overloaded for object cout?
A. >>
B. <<
C. +
2
D. =
Answer: Option A
5. expression x.y represents as
a- member x of object y
b- member y of object x
c- member y of object pointed by x
d- all of above
Answer: Option B
6. Which type of variables can be referred from anywhere in the c++ code
a- All variables
b-Local variables
c-Universal variables
d-Global variables
Answer: Option D
7. Every class has atleast one construtor
a.True
b.False
Answer: Option A
8. C++ programs must contain
a. start)(
b. system)(
c. main)(
d. program)(
Answer: Option C
9. What is inheritance
a. Inheritance allows one class to reuse the state and behavior of another class.
b. It deals with dangling pointers
c. It deals with void pointers
d. It is type of class declaration
Answer: Option A
10. Default constructor has how many arguments
a.1
b.2
c.3
3
d. 0
Answer: Option D
11. How we mark the end of c++ statement
a. ;
b. :
c. <<
d. >>
Answer: Option A
12. Which of the following is correct about class and structure?
a. class can have member functions while structure cannot.
b. class data members are public by default while that of structure are private.
c. Pointer to structure or classes cannot be declared.
d. class data members are private by default while that of structure are public by
default.
Answer: Option D
13. What happens if the base and derived class contains definition of a function
with same prototype?
A. Compiler reports an error on compilation.
B. Only base class function will get called irrespective of object.
C. Only derived class function will get called irrespective of object.
D. Base class object will call base class function and derived class object will call
derived class function.
Answer: Option D
14. A constructor that accepts __________ parameters is called the default
constructor.
a. one
b. two
c. no
d. three
Answer: Option C
15. Can a class have virtual destructor?
A. Yes
B. No
4
Answer: Option A
16. Destructor has the same name as the constructor and it is preceded by ______
. A. !
B. ?
C. ~
D. $
Answer: Option C
17. For automatic objects, constructors and destructors are called each time the
objects
A. enter and leave scope
B. inherit parent class
C. are constructed
D. are destroyed
Answer: Option A
18. A function with the same name as the class, but preceded with a tilde character
(~) is called __________ of that class.
A. constructor
C. function
B. destructor
D. object
Answer: Option B
19.
Which of the following statement is correct?
A. Destructor destroys only integer data members of the object.
B. Destructor destroys only float data members of the object.
C. Destructor destroys only pointer data members of the object.
D. Destructor destroys the complete object.
Answer: Option D
20.
Which of the following statement is correct?
A. A constructor has the same name as the class in which it is present.
B. A constructor has a different name than the class in which it is present.
C. A constructor always returns an integer.
D. A constructor cannot be overloaded.
Answer: Option A
21. Destructors __________ for automatic objects if the program terminates with a
call to function exit or function abort.
5
a. are called
b. are inherited
c. are not called
d. are created
Answer: Option C
6
Download