4. Which of the following issues is considered as the major drawback of the procedure –
oriented programming?
a) Employs tap-down approach in program design.
b) Emphasis is an algorithms.
c) Most of the functions share global data.
d) Large programs are divided into functions.
7. The process by which objects of one class can acquire the attributes of objects of
another class is known as
a) Attribute passing
b) Inheritance
c) Abstraction
d) Polymorphism
8. Which one of the following concepts enables the reusability of code?
a) Dynamic binding
b) Polymorphism
c) Inheritance
d) Encapsulation
4. For declaring the variables a and b, which of the following declaration statements is
incorrect?
a) int a, b; // Declaration
b) int a, /* Declaration*/ b;
c) int a, // Declaration // b;
d) int a, b; // Declaration //
5. For using functions that convert numbers to text and text to numbers, we must include
the following header file:
a) <cstdlib>
b) <iostream>
c) <cstdio>
d) <cmath>
8. Which of the following statements requires the header file <math.h> to be included?
a) cout <<x/y;
b) x + = 10;
c) x = m*n+1;
d) x = sqrt(y);
9. Name the header file that is to be used in the #include directive when we use cout for
displaying outputs.
a) <cstdio>
b) <cstdlib>
c) <iostrean>
d) <cassert>
10. If a is an object of the class B and void print (void) is a member function of B, then
which one of the following statements will invoke the function?
a) a::print();
b) a.voidprint();
c) B.print();
d) a.print();
CHAPTER 3: TOKENS, EXPRESSIONS AND CONTRAL STRUCTURES
3. Which of the following statements is TRUE with regard to naming C++ identifiers?
a) A name can start with any letter or digit.
b) No special characters are permitted.
c) Uppercase and lowercase letters are distinct.
d) A name cannot have more than 32 characters
b) void *p1;
int *p2;
*p2 = *p1;
c) void *p1;
char *p2;
p2 = (char *) p1;
9. Assumming that we are working an a 16-bit word machine, which of the following
takes a size of 8 bytes
a) signed long int
b) long int
c) long double
d) double
14. For using the manipulator setw(), we must include the header file:
a) <iostream>
b) <cstdio>
c) <iomanip>
d) <cstdlib>
15. The following statements implement type cast operation. Which one of them is illegal?
a) x = y/(float)m;
b) x = y/float(m);
c) x = float(y)/(float)m;
d) x = y/float m;
19. In which of the following groups all the operators are in the same level of
precedence?
a) <<, < =, = =, << =
b) new, sizeaf, typeid, !
c) new, delete, ->, ::
d) %, *, ->*, /=
20 Which of the following loop structures is known as an exit-controlled loop?
a) do… while loop
b) while loop
c) for loop
d) None of the above
CHAPTER 4: FUNCTIONS IN C++
8. The following is the list of function declarations. Which one of them will be invoked
by the function call statement
cout <<mul(10.5, 10);
11. Which of the following statements is true in respect of a function containing const
arguments?
a) The function cannot return a value.
b) The function cannot change the value of const arguments.
c) const should be used for the argument passed by reference.
d) const argument cannot be used in any expression.
12. Which of the following will return the value –8.0 given the value of x to be –8.5?
a) fabs(x)
b) ceil(x)
c) floor(x)
d) all the above
CHAPTER 5: CLASSES AND OBJECTS
1. C++ supports both classes and structures. Which of the following statements is
FALSE in respect of both of them?
a) Both can have variables and functions as members.
b) In both, the members are private by default.
c) They support inheritance.
d) Their names can be used like any other types names.
7. Listed below are some of the possible characteristics of member functions. Which
one of them is NOT TRUE?
a) All the member functions should be defined within the class itself
b) Several different classes can use the same function name
c) Member functions can access the private members of the class.
d) A member function can call another member function directly without using
the dot operator.
8. State which of the following is false with respect to classes:
a) They permit data to be hidden from other parts of the program
b) They can directly map objects in the real world
c) They bring together all attributes of an entity in one place
d) They are removed from memory when not in use
12. Which one of the following statements is not true for a member function declared as
friend?
a) It can be invoked like a normal function without help of any object.
b) It cannot access the members of the class directly.
c) It cannot have objects as arguments.
d) It cannot be called using the objects of its class.
13. Which of the following is TRUE about static member variable of a calss?
a) Each object creates its own copy.
b) It is visible only within the class.
c) It can be initialized whenever necessary.
d) It cannot be assigned any initial value at the time of definition.
14. Which one of the following is TRUE while passing objects as function arguments?
a) A copy of the entire objects can be passed.
b) Only the address of the object can be passed.
c) A nonmember function can use objects as its arguments.
d) All of the above.
15. Which one of the following is FALSE?
a) The address of a class member can be assigned to a pointer variable.
b) When making a member function const, the qualifier const must be used in
both declaration and definition.
c) A class can be defined inside a function.
d) None of the above.
CHAPTER 6: CONSTRUCTORS AND DESTRUCTORS
2. Which one of the following statements does correctly describe one of the many
characteristics of constructors?
a) They can be inherited.
b) They can return values, like other functions.
c) They can be declared anywhere in the class.
d) They can have default arguments.
3. A constructor for the class Area having two data members length and breadth is
declared as follows:
Area (int length = 15, int breadth = 10);
Which one of the following object declarations is illegal?
a) Area A(20, 10);
b) Area A();
c) Area A = Area (20, 10);
d) Area A;
4. Which one of the following is an implicit constructor for the class ROOM having a
data member area?
a) Room ( ) { }
b) Room (int a) {area = a}
c) Room (Room & a) {area = a.area}
d) None of the above
5. Which one of the following declations represents the legal copy constructor for the
class X?
a) X (X);
b) X (&X);
c) X (X&);
d) X ( );
6. Identify error, if any, in the following code segment:
1. class Sample
2. {
3. int m;
4. Sample ( );
5. Sample (int);
6. };
6. When overloading binary operators using friend functions, the operator function uses
a) two explicit arguments
b) one implicit and one explicit arguments
c) one explicit argument
d) no arguments
7. When overloading binary operators using member functions, the operator functions
use
a) two explicit arguments
b) one explicit argument
c) one implicit and one explicit arguments
d) one implicit argument
8. We can use a constructor function for accomplishing
a) conversion from class type to class type.
b) conversion from basic type to class type
c) conversion from class type to basic type
d) non of the above
7. Which of the following functions can have access to the protected data of a class?
a) A function that is friend of the class
b) A member function of a class declared friend of the class
c) A member function of a derived class
d) All the above
10. A class D is privately derived from class B. An object of D in the main function can
access
a) public members of B
b) private members of D
c) protected members of B
d) public members of D
11. The following examples show that the class C is derived from classes A and B.
Which one of them is legal?
a) class C : private A, public B
b) class C :: private A, public B
c) class C : public A : public B
d) class C: class A, B
e) class C: private A, public B;
12. Consider the following code:
class A { };
class B : A { };
What happens when we compile this code?
a) Will not compile because the body of A is empty
b) Will not compile because the body of B is empty.
c) Will not compile because the visibility mode for A is not specified
d) Will compile successfully
1. A pointer is
a) the data type of an address variable
b) a variable for storing addresses
c) a special type of integer variable
d) a special type of operator
3. The statement
int * p ;
can be interpreted as
a) the variable whose address is stored in p is an integer
b) the variable pointed to by p is an integer
c) p points to an integer
d) All the above
1. Functions that are necessary for handling formatted input and output operations are
declared in the class
a) iostream
b) ios
c) istream
d) ostream
b) 1 2 3 4
c) 1 2 3 4
d) 1 2
3 4
e) 1 2
3 4
10. For displaying plus sign and trailing zeros for printing positive floating point
numbers, we must use the flag
a) ios:: showbase only
b) ios:: showpos only
c) ios:: showpoint only
d) both a and b
e) both b and c
11. What would be the output of the following code segment?
cout.setf(ios:: showpos);
cout.precision(2);
cout<< 345.609
a) 345.60
b) +345.61
c) +345.6
d) +345.609
e) 345.61
a) i only
b) i and ii
c) i and iii
d) iii only
e) ii and iii
f) all the three
CHAPTER 11: WORKING WITH FILES
2. Which of the following classes support simultaneous input and output file operations?
a) iostream
b) fstream
c) filebuf
d) None of the above
5. When reading a file that is connected to the input stream fin of ifstream, we can
detect the end-of-file condition using
a) while (fin) statement
b) if (fin.eof ( )!= 0) statement
c) either of them
d) neither of them
6. To open an existing file to add data to the end of the file or to modify the existing
data anywhere in the file, the second argument of open ( ) must be
a) ios :: ate
b) ios :: app
c) ios :: trunc
d) ios :: noreplace
7. To write floating point data to a file, we must use
a) put ( ) function
b) write ( ) function
c) the insertion operator
d) seekp ( ) function
8. The statement
file1.write ((char*) &M, sizeof (M));
writes
a) the address of M to file1
b) the functions of M to file1
c) all the members of M to file1
d) data in object M to file1
9. Assuming that the length of the file f1 is 100 bytes, what will be the output of the
following code segment?
f1.seekg(0, ios::end);
f1.seekg(-10, ios::cur);
cout << f1.tellg ( );
a) 0
b) 100
c) 90
d) Error; no output
10. Any fatal error occurring during a file operation can be located by using the function
a) fail ( )
b) bad ( )
c) eof ( )
d) good ( )
CHAPTER 12: TEMPLATES
5. When we use the concept of templates, when does the program generate actual code
for a template function?
a) At the time of invoking the function
b) At the time of declaration of the function
c) When the function definition is made
d) When the function is executed at run-time
10. The following is a list of header lines for creating function templates. Which of them
is legal?
a) template < class T > swap ( T & x, T & y)
b) template < T > void swap (T & x, T & y)
c) class < template T> void swap (T & x, T & y)
d) None of the above
CHAPTER 13: EXCEPTION HANDLING
1. Majority of template classes and functions contained in STL were originally developed
by
a) Bjarne stroustrup
b) ANSI standards committee
c) International standards organization (ISO)
d) Alexander Stepanov and Meng Lee
5. An STL algorithm is
a) a friend function of a container class
b) a member function a container class
c) a standalone function designed to operate on containers
d) None of the above
10. Which of the following algorithm is used to replace an element with a specified
value?
a) generate ( )
b) replace_copy ( )
c) remove_copy ( )
d) replace ( )
a) The second line should have opening and closing braces like {……}
b) Initial value for i should be zero
c) The relational operator should be < and not <=
d) string1.at(i) should be written as string1.at[i]
a) i, ii and vi
b) ii, iv and v
c) ii, iii and vi
d) i, iii and vi
10. To replace the contents of string s1 with that of s2 and contents of s2 with that of s1,
we can use the statement
a) s1.swap(s2);
b) swap(s1, s2);
c) s1.replace(s2)
d) replace(s1, s2);
CHAPTER 16: NEW FEATURES ANSI C++ STANDARD
2. Which of the following operators is normally used to change a pointer type object to
integer type object
a) static_cast operator
b) reinterpret_cast operator
c) typeid operator
d) const_cast operator
9. We use namespaces to
a) divide a long program into different modules
b) divide a program into separate files
c) restrict the scope of program elements
d) prevent any modification in data members
6. The process of one object calling a member of another object may be represented by
a) hierarchical relationship
b) composition relationship
c) use relationship
d) inheritance relationship
12. Which of the following statements is TRUE with regard to design of classes?
a) Interaction between two classes must be explicit
b) An object of one class should not send any message directly to a member of
another class
c) A class should be dependent on as few classes as possible
d) None of the above
e) All of the above
13. Which of the following statements is FALSE with regard to design of member
functions?
a) Each function either accesses or modifies some data of the class it represents
b) All functions must always be declared public
c) They can use top-down functional decomposition technique
d) They can use structured design techniques
a) i and ii
b) iii and iv
c) All the four
d) None of the four