Review Questions

Chapter I: Principles of Object-Oriented Programming

1. Which of the following languages is not a procedure-oriented programming language?
a) ALGOL
b) COBOL
c) FORTRAN
d) None of the above

2. Which of the following programming approach used functions as a key concept to perform action-oriented tasks?
a) Structured programming
b) Modular programming
c) Procedure-oriented programming
d) Object-oriented programming

3. Identify the drawback of using procedure-oriented programming, if any:
a) Data is hidden from external functions
b) New functions can be added whenever necessary
c) Does not reflect real world problems
d) All of the above

4. Which is not associated with Object-oriented programming?
a) Data abstraction
b) Automatic initialization
c) Dynamic binding
d) None

5. The term operator overloading in C++ refers to:
a) Inheritance
b) Message passing
c) Polymorphism
d) None

6. Which one of the following OOP concepts enables reusability of components?
a) Inheritance
b) Encapsulation
c) Polymorphism
d) All of the above

7. The concept of hierarchical classification is related to:
a) Abstraction
b) Inheritance
c) Function overloading
d) None

8. Object-based programming languages do not support:
i. Inheritance
ii. Dynamic binding
iii. Encapsulation
iv. All of the above
a) Both i and ii
b) iii only
c) iv only
d) i, ii, and iii

9. C++ does not support
i. Genericity
ii. Early binding
iii. Garbage collection
iv. Multiple Inheritance
a) i only
b) ii only
c) iii only
d) ii, iii and iv

10. Which of the following is an Object-oriented programming language?
i. Smalltalk
ii. Object Pascal
iii. Java
iv. All of the above
a) Both ii and iii
b) i only
c) iii only
d) iv only


Chapter I: Principles of Object-Oriented Programming

1. d) None of the above
2. c) Procedure-oriented programming
3. c) Does not reflect real world problems
4. d) None
5. c) Polymorphism
6. a) Inheritance
7. b) Inheritance
8. a) Both i and ii
9. a) i only
10. d) iv only




Chapter II: Beginning With C++

1. Which one of the following options is true on the topic of Simula67?
i. It is the first Object-oriented programming language
ii. It’s a predecessor to C++
iii. It was designed for doing simulations¬
iv. All of the above
a) Both i and ii
b) i only
c) iii only
d) iv only

2. Which of the following features that distinguish object oriented programming from other conventional programming?
i. Structural design
ii. Inheritance
iii. Modular programming
iv. bottom-up
a) i only
b) Both ii and iii
c) Both ii and iv
d) iv only

3. Comments in C++ start with _______ symbol.
a) //
b) \\
c) **
d) None of the above

4. The insertion operator is another name for
a) input operator
b) output operator
c) extraction operator
d) None of the above

5. Which header file in C++ does contain function prototypes for memory allocation?
a) < iostream.h>
b) < stdio.h>
c) < stdlib.h>
d) < limits.h>

6. What is the output of the following code?
int n=10;
while (n< 10)
cout<< “Number:”<< n+1;
a) 10
b) 11
c) No output
d) None of the above

7. Which of the following statements require the header file to be included?
a) a=b/c;
b) cout << a;
c) c=sqrt(a);
d) Both a and c

8. Identify the error, if any: char str_name ‘a‘;
a) str_name is not a valid variable name
b) Variables cannot be initialized at the time of declaration
c) Missing = sign between str_name and ‘a’
d) No error

9. Name the library that must be included while using cin.
a) < iomanip.h>
b) < iostream.h>
c) < ctype.h>
d) < stdlib.h>

10. A C++ program structure is based on the concept of
a) Client-server model
b) N-Tier model
c) Both a and b
d) None of the above


Chapter II: Beginning With C++
11. d) iv only
12. c) Both ii and iv
13. a) //
14. b) output operator
15. c)
16. c) No output
17. d) Both a and c
18. c) Missing = sign between str_name and ‘a’
19. b)
20. a) Client-server model


Chapter III: Tokens, Expressions and Control Structures
1. return is an example of a
a) Keyword
b) Function
c) Statement
d) Comment
2. Which of the following is not a keyword?
i. for
ii. friend
iii. virtual
iv. private
a) i only
b) Both ii and iii
c) Both i and iv
d) ii, iii and iv
3. Identify the valid variable name from the following:
i. char
ii. var_name
iii. _varname
iv. str_name2
a) Both i and iii
b) Both ii and iv
c) ii, iii, and iv
d) i only
4. Which of the following is not a user-defined data type?
a) array
b) structure
c) union
d) class
5. Write the equivalent C++ statement for the following expression,
X= *c/d
a) X=sqrt(a+b) *(c/d);
b) X=(squareroot(a+b)*c)/d;
c) X=( * c)/d;
d) None of the above
6. The statement int main() is a ___________.
a) function prototype
b) function call
c) function header line
d) None of the above
7. The declaration of global variables must be made
a) inside the function
b) outside the function
c) in a function header line
d) None of the above
8. Identify the error, if any:
double avg=tot/n;
a) Declaration should not contain any expression
b) Initialization cannot be done in the declaration statement
c) Dynamic initialization is not possible
d) No error
9. Which of the following is true about scope resolution operator?
a) Qualifies a namespace member to its namespace
b) Allows you to access a global variable
c) Qualifies the hidden variable
d) All of the above
10. Which of the following is not a member-dereferencing operator?
a) ::*
b) ::
c) *
d) *
11. Which of the following is true about new operator?
i. While using new operator, sizeof() operator is not needed
ii. It is also not necessary to use cast operator
iii. new operator can be overloaded
iv. All of the above
a) Both i and ii
b) Both i and iii
c) ii only
d) iv only
12. Identify the manipulators in C++:
a) endl
b) setw
c) Both a and b
d) None of the above
13. a = (b = 5); The C++ statement is an example of
a) Compound assignment
b) Embedded assignment
c) Chained assignment
d) Multiple assignment
14. Water-fall model is associated with
a) Control structures
b) Type conversions
c) Manipulators
d) None of the above
15. Selection structure is also known by
a) branching
b) straight line
c) iteration
d) None of the above
16. Consider the following code:
cout<< “Welcome”;
This is an example of
a) C++ statement
b) Return type
c) Function
d) Both a and c


Chapter III: Tokens, Expressions and Control Structures

1. a) Keyword
2. d) ii, iii and iv
3. c) ii, iii, and iv
4. a) array
5. a) X=sqrt(a+b) *(c/d);
6. c) function header line
7. b) outside the function
8. d) No error
9. d) All of the above
10. b) ::
11. d) iv only
12. c) Both a and b
13. c) Chained assignment
14. b) Type conversions
15. a) branching
16. a) C++ statement






Chapter IV: Functions in C++
1. Which of the following is true about a function call in a C++ program?
a) A function must be called atleast once
b) A function cannot be called from other functions
c) A function may be called whenever it is necessary
d) Both a and c
2. Function prototyping defines
a) The return type of the function
b) The identifier of the function
c) The number and type of arguments
d) All of the above
3. Find if the following function prototype contains any error:
double area(int )
a) No error
b) Variable name is not included in the argument list
c) Semicolon is not found
d) None of the above
4. Identify which function prototype exhibits the following: Name of the function is sample_calc, which receives two values of type double and returns no value;
a) sample_calc(double, double);
b) void sample_calc(double, double);
c) double sample_calc(void);
d) void sample_calc(double, double)
5. When you call a function by passing the address of a data variable, it is called ________.
a) Call by reference
b) Call by value
c) Call by two directions
d) Both b and c
6. Which of the following function calls is correct while providing default arguments:
I. double calc(int a, float b=12.0);
II. double calc(int a=3, float b=12.0, int c);
III. double calc(int a=3, float b, int c=8);
IV. double calc(int a, float b=12.0, int c=8);
a) I only
b) II only
c) Both I and IV
d) Both II, and III
7. Which function call does invoke the following function prototype?
float sub1(int a, float b);
a) X=sub1(5.0,6.5);
b) X=sub1(5,6.5);
c) X=sub1(5,6);
d) Both b and c
8. Identify the variables, which are local to the following function:
int calc(int p, int n)
{
int q;
q=pow(p,n);
return(q);
}
a) p and n
b) p,n, and q
c) q
d) Cannot be determined without the main() function
9. Which of the following statements is true about the function that contains the const argument?
a) The function should not modify the const argument
b) Const declaration is necessary only when the arguments are passed by reference
c) Both b and c
d) None of the above
10. Which of the following functions in C++ replace the usage of macros in C?
a) friend function
b) virtual function
c) inline function
d) All of the above


Chapter IV: Functions in C++

1. c) A function may be called whenever it is necessary
2. d) All of the above
3. c) Semicolon is not found
4. b) void sample_calc(double, double);
5. a) Call by reference
6. c) Both I and IV
7. b) X=sub1(5,6.5);
8. b) p,n, and q
9. c) Both b and c
10. c) inline function


Chapter V: Classes and Objects
1. The declaration of a class includes
a) Declaration of data members
b) Declaration of function prototype
c) Return statements of functions
d) Both a and b
2. By default, the members of a class are
a) private
b) public
c) protected
d) static
3. Which OOP feature can be enabled by using private declaration for the class members?
a) Data abstraction
b) Polymorphism
c) Encapsulation
d) Modularity
4. Which of the following will assign the value to the class member variable num?
void getnum(int a)
a) {num=a};
b) {num=a;}
c) {a=num};
d) {a=num;}
5. Which of the following is not true about member functions?
a) Can access private data variables
b) Can call another function directly without using dot operator
c) Both a and b
d) None of the above
6. Identify all the members of the following class xyz:
class xyz
{
int x,y;
public:
xyz();
void calc(int a, int b);
void output_calc(void);
};
a) Data members x and y
b) Data members x and y, Constructor, and member functions calc() and output_calc()
c) Data members x and y, and member functions calc() and output_calc()
d) Constructor and member functions calc() and output_calc()
7. Which of the following is not true about static member variable?
a) Only one instance of static member can be created
b) Visible only within the class
c) It can be initialized whenever necessary
d) Both a and b
8. What is the general format of calling a static member function using a class name?
a) class-name :: function-name
b) function-name :: class-name
c) class-name :: function-name;
d) function-name :: class-name;
9. Which of the following is true while passing objects as function arguments? It is possible
a) to pass copy of the entire object to the function
b) to pass only the address of the object to the function
c) to pass the objects to a non-member function
d) All of the above
10. A friend function
I. Can be invoked similar to other functions without using objects
II. Cannot access to other member functions directly
III. Cannot be called using the object of the class to which it has been declared as friend
IV. Can be declared only in the public part of a class
a) I, II and III
b) I, II and IV
c) I, II, III and IV
d) IV only


Chapter V: Classes and Objects

1. d) Both a and b
2. a) private
3. c) Encapsulation
4. b) {num=a;}
5. d) None of the above
6. b) Data members x and y, Constructor, and member functions calc() and
output_calc()
7. c) It can be initialized whenever necessary
8. c) class-name :: function-name;
9. d) All of the above
10. c) I, II, III and IV

Chapter VI: Constructors and Destructors

1. Which of the following is not true about constructors and destructors?
a) They must have the same name as class
b) They cannot return values
c) They cannot be called more than once in a program
d) They are called automatically
2. The default constructor for class A is
a) A :: A()
b) A :: A(int)
c) A :: A(int);
d) A :: A();
3. Which of the following statements do correctly describe the characteristics of constructors?
I. They cannot be inherited
II. They cannot be virtual
III. They need not be declared in the public section
IV. We cannot refer to their addresses
a) Both I and II
b) I, II, and IV
c) Both II and III
d) I, III and IV
4. Which of the following is called an implicit constructor for the class xyz?
a) xyz(){ }
b) xyz(int){}
c) xyz(){ };
d) None of the above
5. Consider the following code segment:
class simple
{
int a,b;
public:
simple();
simple(char[]);
};
Which of the following would assigns the string “welcome” to the second constructor?
a) simple s(“welcome”);
b) simple s(welcome);
c) simple s=”welcome”;
d) None of the above
6. Identify if any error in the following code segment
1. class example
2. {
3. float x;
4. public:
5. void example();
6. example(int, float);
7. };
a) Line 7 should not include the semicolon
b) Line 6 is an incorrect statement
c) Line 5 cannot include void
d) No error
7. Which of the following statements are true about copy constructors?
I. It declares and initializes an object from another object
II. It will not be useful when arguments are passed by value
III. It can be used to pass arguments by reference
IV. The compiler provides its own copy constructor, if it is not defined.
a) I, II, IV
b) All are correct
c) Both II and III
d) III only
8. The following statement creates a constant object of a class simple:
const simple m(a,b);
Which the following is true regarding the above statement?
a) The compiler generates compile-time error if you try to change the values of ‘a’ and ‘b’
b) Const member is a function prototype
c) The compiler generates an error if m tries to invoke non-const member functions
d) All of the above
9. Which of the following statements do incorrectly describe the characteristics of destructors?
I. A destructor is a member function, which has the same name as class name
II. A destructor receives only one argument
III. A destructor does not return any value
IV. Usage of destructors in a program clean up memory space that is not used
a) Both I and II
b) All are incorrect
c) Both II and III
d) I, II and IV
10. Which of the following is a correct description of the destructor ‘sample’ and includes output statements (if possible)?
a) sample :: ~sample() {cout << “Welcome”; }
b) sample :: ~sample() { };
c) void ~sample() { }
d) ~sample() { };




Chapter VI: Constructors and Destructors

1. c) They cannot be called more than once in a program
2. a) A :: A()
3. b) I, II, and IV
4. a) xyz(){ }
5. a) simple s(“welcome”);
6. c) Line 5 cannot include void
7. b) All are correct
8. d) All of the above
9. a) Both I and II
10. a) sample :: ~sample() {cout << “Welcome”; }


Chapter VII: Operator Overloading and Type Conversions

1. Which of the following operators cannot be overloaded?
a) ?:
b) ::
c) .*
d) All of the above
2. Operator Overloading is also known by the term
a) runtime polymorphism
b) compile-time polymorphism
c) Both a and b
d) None of the above
3. Operator overloading is necessary because
a) C++ attempts to make the user-defined classes act like built-in types
b) To provide new definitions for most of the C++ operators
c) To add user-defined data type like basic data types
d) All of the above
4. Which of the following is required to overload an operator in C++?
a) operator function
b) built-in function
c) Both a and b
d) None of the above
5. Identify the correct definition of an operator function for the class sample, which overloads a unary minus operator and returns no values.
a) sample :: oper-() { };
b) void sample :: operator-() { }
c) void sample :: operator-() { };
d) sample :: operator-() { }
6. Which of the following is not true about the code segment given below?
float sample :: operator +(float x) {// code }
a) It receives only one float type argument explicitly
b) It returns a float type value
c) It is a member function of sample
d) None of the above
7. Which of the following operators cannot use friend functions for overloading?
I. ==
II. ( )
III. [ ]
IV. ->
a) I only
b) II only
c) II, III and IV
d) I, II and III
8. Which of the following is not true about operator overloading?
a) Only existing operators can be overloaded
b) Binary arithmetic operators (+,-,*,/) need not return a value
c) It is impossible to redefine an operator
d) All of the above
9. Which of the following code segments will convert a class object namely sample to type double?
a) sample :: operator double() { }
b) operator double() { }
c) sample :: operator double();
d) operator double();
10. Which of the following statements does correctly describe the casting operator function?
a) It must not specify return type
b) It must be a class member
c) It must not have any arguments
d) All of the above


Chapter VII: Operator Overloading and Type Conversions

1. d) All of the above
2. b) compile-time polymorphism
3. d) All of the above
4. a) operator function
5. b) void sample : : operator-() { }
6. d) None of the above
7. c) II, III and IV
8. b) Binary arithmetic operators (+,-,*,/) need not return a value
9. a) sample :: operator double() { }
10. d) All of the above



Chapter VIII: Inheritance: Extending Classes

1. Which of the following OOP concepts is supported by Inheritance?
a) Abstraction
b) Encapsulation
c) Reusability
d) None of the above
2. Which of the following does a derived class inherit from a base class?
a) public and protected class members
b) public and private class members
c) only public data
d) Everything
3. Which of the following statement(s) is true, if a derived class is publicly inherited from a base class?
I. The public members of the base class become public members of the derived class
II. The public members of the base class become private members of the derived class
III. The public members of the base class are inaccessible to the objects of the derived class
IV. All of the above
a) I only
b) Both I and II
c) Both I and III
d) IV only
4. Consider the following code segment:
class A
{
int a;
public:
int b;
void inp();
}
class B : A
{
// members of B
}
Which of the following statement(s) is NOT true regarding the above code?
a) The public members, namely ‘b’ and inp() of class A become private members of class B
b) The public members, namely ‘b’ and inp() of class A can be accessed by the member functions of class B
c) The public members, namely ‘b’ and inp() of class A are inaccessible to the objects of class B
d) None of the above
5. According to the following code, which of the following class members does the derived class inherit from the base class?
class base
{
float x;
int y;
public:
int a;
void get_a();
void put_a();
}
class derived : public base
{
// members of B
}
a) float x
b) int y
c) get_a(), void put_a()
d) All of the above
6. Which of the following statement(s) is true about the visibility of inherited members?
a) When a class is inherited in protected mode, the private members of the base class become protected members of the derived class
b) When a class is inherited in private mode, only the public members of the base class can be inherited to the derived class
c) When a class is inherited in public mode, the private members of the base class cannot be inherited
d) None of the above
7. What are the visibility modifiers available in C++?
a) public
b) private
c) protected
d) All of the above
8. Which of the following functions can have access to the private and protected members of a class?
a) A member function of a class that is a friend of the class
b) A member function of a derived class
c) A function that is a friend of the class
d) All of the above
9. Consider the following code segment:
class B : public A
{
int a;
public:
int b;
void a_inp();
void a_out();
}
class C : public A
{
private:
float x;
public:
double get_calc();
double put_calc();
}
Which of the following statement(s) is true regarding the above code?
a) Class A is the parent class of both the classes B and C; and class B inherits get_calc() from class C
b) Class A is the parent class of both the classes B and C, which do not have any relationship between them
c) Two classes cannot be the child classes of the same base class
d) Class A is the parent class of both the classes B and C; and class C inherits a_out() from class B
10. Consider the following code segment:
class Book {……..};
class Prose : public Book {……….};
class Poetry : public Prose {……….};
The above code is an example of
a) Multiple Inheritance
b) Multilevel Inheritance
c) Hierarchical Inheritance
d) Hybrid Inheritance
11. Consider a class D, which is inherited from two classes B and C. The classes B and C inherited the members from class A. Which feature of C++ does allow you to handle such kind of mulitpath inheritance?
a) Abstract class
b) Virtual base class
c) Duplicate class
d) None of the above
12. If a class contains the objects of another class as its members, then it is known as
a) Containership
b) Private inheritance
c) Dynamic notation
d) None of the above

Chapter VIII: Inheritance: Extending Classes

1. c) Reusability
2. a) public and protected class members
3. a) I only
4. d) None of the above
5. c) get_a(), void put_a()
6. c) When a class is inherited in public mode, the private members of the base class cannot be inherited
7. d) All of the above
8. d) All of the above
9. b) Class A is the parent class of both the classes B and C, which do not have any relationship between them
10. b) Multilevel Inheritance
11. b) Virtual base class
12. a) Containership

Chapter IX: Pointers, Virtual Functions and Polymorphism
1. Which of the following is true about pointers?
a) A pointer is a data type
b) A pointer is a keyword
c) A special type of integer variable
d) None of the above
2. Which of the following statement(s) is true according to the following statement?
p=*ptr;
a) p must be a pointer variable
b) The value of ptr is assigned to the variable p
c) The address of the pointer ptr is assigned to the variable p
d) The value of the variable that the pointer ptr is pointing to is assigned to the variable p
3. Compile time polymorphism is also known as
a) early binding
b) static binding
c) static linking
d) All of the above
4. C++ supports a mechanism virtual function to achieve
a) compile time polymorphism
b) function overloading
c) run time polymorphism
d) operator overloading
5. Which of the following is NOT true about virtual functions?
I. They cannot be static members
II. A virtual function can be a friend of another class
III. We can have virtual constructors, but we cannot have virtual destructors
IV. They are accessed by using object pointers
a) II only
b) III only
c) Both II and III
d) I, II and IV
6. Consider the following code segment:
int main()
{
int x, *x_ptr=&x;
x=5;
x_ptr=NULL;
cout<< x << “ “ << *x_ptr;
return 0;
}
What is the output of the above code?
a) 0
b) but addresses are same
c) but having different addresses
d) 5
7. Consider the following code segment:
int main()
{
double f, *f_ptr=&f;
f=5.25;
f_ptr=4.5;
cout<< “Value of f is:” << “ “ << f;
return 0;
}
What is the output of the above code?
a) Value of f is: 5.25
b) Value of f is:
c) Value of f is: 4.5
d) Compiler error
8. How will you assign value ‘5’ to the variable ‘x’ inside a member function using this pointer?
a) this->x=5;
b) this.x=5;
c) x=5;
d) None of the above
9. Consider a class X, which includes a virtual function called X_output. The virtual function receives a float value and returns nothing. Find out the function prototype for the same.
a) virtual void X_output(float );
b) X:: virtual void X_output(float );
c) virtual X:: void X_output(float );
d) virtual :: void X_output(float );
10. What would be the output of the following code?
#include< iostream.h>
#include< conio.h>
class A
{
public:
virtual void disp()
{
cout<<"This is from class A";
}
};

class B : public A
{
public:
void disp()
{
cout<<"This is from class B";
}
};
void main()
{
clrscr();
A *s;
s = new B();
s->disp();
}
a) This is from class A
b) This is from class B
c) This is from class A This is from class B
d) None of the above
11. Which of the following is NOT true about pure virtual function?
a) It is also called do-nothing function
b) It cannot declare its own objects
c) A virtual function, which is not equated to zero is called a pure virtual function
d) None of the above

Chapter IX: Pointers, Virtual Functions and Polymorphism

1. a) A pointer is a data type
2. d) The value of the variable that the pointer ptr is pointing to is assigned to the variable p
3. d) All of the above
4. c) run time polymorphism
5. b) III only
6. a) < hexadecimal address> 0
7. d) Compiler error
8. a) this->x=5;
9. a) virtual void X_output(float );
10. b) This is from class B
11. c) A virtual function, which is not equated to zero is called a pure virtual function

Chapter X: Managing Console I/O Operations

1. Which of the following is not an input/output stream class?
a) ios
b) istream
c) ostream
d) None of the above
2. Which class does define the member function put()?
a) istream
b) ostream
c) streambuf
d) None of the above
3. Which of the following code would read a line of text from char type variable, book[20]?
a) cin.getline(book,20);
b) cin.getline(book[20]);
c) cin.getln(book,20);
d) None of the above
4. What would be the output of the following code?
char *str= “Managing Console I/O Operations”;
cout.write(str,15);
a) Managing Console I/O Operations
b) Managing C
c) Managing Consol
d) None of the above
5. Which of the following feature does allow you to format the output in C++?
a) Manipulators
b) ios class functions and flags
c) User-defined output functions
d) All of the above
6. Which of the following functions allow you clear the specified flags?
a) fill()
b) unsetf()
c) cflag()
d) None of the above
7. What would be the output of the following code?
cout.width(5);
cout.precision(2);
cout<< 846.209;
a) 846.20
b) 846.21
c) 846.209
d) 846.2
8. Identify the equivalent ios function for the manipulator ‘setw’.
a) width()
b) setwidth()
c) swidth()
d) None of the above
9. What would be the output of the following code?
cout.fill(‘$’);
cout.setf(ios::left, ios:: adjustfield);
cout.width(20);
cout<< “I/O Operations”;
a) Operations$$$
b) I/O Operations
c) I/O Operations$$$$$$
d) I/O Operations$$$$$$$
10. Which of the following flags do not have any bit fields?
a) showpoint
b) showpos
c) showbase
d) Both a and b

Chapter X: Managing Console I/O Operations

1. d) None of the above
2. b) ostream
3. a) cin.getline(book,20);
4. c) Managing Consol
5. d) All of the above
6. b) unsetf()
7. b) 846.21
8. a) width()
9. c) I/O Operations$$$$$$
10. d) Both a and b


Chapter XI: Working with Files

1. All file stream classes are derived from
a) ifstream
b) fstreambase
c) ifstreambase
d) ofstreambase
2. Which of the following stream classes provide support for simultaneous input and output operations?
a) ifstream
b) ofstream
c) fstream
d) None of the above
3. Which of the following statement(s) creates an output stream object called out_strobj and opens a file named “sample”?
a) ofstream out_strobj(“sample”);
b) ofstream out_strobj(sample);
c) ostream out_strobj(sample);
d) ostream out_strobj(“sample”);
4. Which of the following function(s) opens a file named “sample” for writing only?
a) ofstream_object.open(“sample”, ios::app);
b) ifstream_object.open(sample, ios::out);
c) ofstream_object.open(“sample”, ios::out);
d) ifstream_object.open(sample, ios::app);
5. Consider the following code segment:
1: void main()
2: {
3: char line[80],str[80];
4: str = "Working with C++ files";
5: ofstream fout;
6: fout.open("sample.txt",ios::out);
7: fout << str ;
8: fout.close();
9: }
The above code will not compile. Assume that all the header files are included in the program. Identify which line should be changed to fix the error?
a) Line 6 & Line 7
b) Line 4
c) Line 3
d) Line 8
6. Consider a file named ‘sample.txt’ contains the string “Working with C++ files”. Now the following code attempts to read the file.
void main()
{
char line[80];
ifstream fin;
fin.open(“sample.txt”,ios::in);
fin>>line;
cout<< line;
fin.close();
}
What would be the output of the following code?
a) Working with C++ files
b) Working
c) Working w
d) None of the above
7. Consider the following code segment:
void main()
{
char c,line[50];
clrscr();
fstream fout;
fout.open("sample.txt",ios::out|ios::in);
fout <<"Working with C++ Files";
fout.seekg(0,ios::beg);
fout.seekg(5,ios::cur);
fout.get(c);
cout<< c;
fout.close();
}
What would be the output of the above code?
a) g
b) i
c) n
d) Working
8. Assume that the file pointer points to the byte number 22. Now consider the following code segment:
fout.seekg(2,ios::beg);
fout.seekg(-4,ios::beg);
int k=fout.tellg();
cout<< k;
What would be the value of k?
a) 24
b) 20
c) 22
d) None of the above
9. Which of the following function(s) does allow you to read data in binary form?
a) write()
b) read()
c) get()
d) Both a and b
10. Which of the following input function reads the variable ‘aval’ of type float with input file stream object ‘file_obj’?
a) file_obj.read((float *) & aval, sizeof (aval));
b) file_obj.read((char *) & aval, sizeof (aval));
c) file_obj.read(& aval, sizeof (aval));
d) file_obj.read(float aval, &aval);

Chapter XI: Working with Files

1. b) fstreambase
2. c) fstream
3. a) ofstream out_strobj(“sample”);
4. c) ofstream_object.open(“sample”, ios::out);
5. c) Line 3
6. b) Working
7. c) n
8. b) 20
9. d) Both a and b
10. b) file_obj.read((char *) & aval, sizeof (aval));

Chapter XII: Templates

1. C++ Templates support the concept of
I. modular programming
II. generic programming
III. structural programming
IV. None of the above
2. Which of the following is NOT true about Templates?
I. They allow you to define generic classes
II. Template type can be substituted by any data-type
III. They eliminate code duplication for different data types
IV. None of the above
3. Consider the following code segment:
template < class temp >
class sample
{
……..//code
};
Identify the correct syntax for declaring a dynamic array of characters using the above template.
I. sample < char> characterArray;
II. sample < datatype> characterArray;
III. temp < char> characterArray;
IV. temp < datatype> characterArray;
4. Which of the following statement(s) defines more than one generic data type in a class template?
I. template < class temp1, class temp2…>
II. template < class temp1; class temp2…>
III. template < class temp1, temp2…>
IV. template < class temp1; temp2…>
5. Consider the following code segment:
template < class temp>
void sample(temp &x)
{
…….//code
};
Which of the following is true about the above code?
I. Declares a sample() class template that receives the given data type for a single value and returns no value
II. Declares a temp function template that receives the given data type for a single value
III. Declares a sample() function template that receives a value of given data type and returns no value
IV. None of the above
6. Which of the following are not the advantages of class templates in C++?
I. One C++ class template can handle different types of parameters
II. Testing and debugging efforts are reduced
III. It allows the process of instantiation
IV. None of the above
7. Consider the following code segment:
1: template
2: void show(temp1 a, temp2 b)
3: {
4: cout<<”a”;
5: }
Assume that there is no logic error. Identify if there is any declaration error:
a) Line1
b) Line 4
c) Both a and b
d) No error
8. Consider the following code segment:
#include< iostream>
template< class temp>
int powerofTwo(temp &x)
{
return(!(x-1)&x);
}
void main()
{
int b=powerofTwo(100);
cout<< b;
}
What is the output of the above code?
a) 0
b) 1
c) 100
d) None of the above
9. Which of the following statement(s) is similar to the declaration of non-type template parameters?
a) Pointer to member
b) Pointer to object or pointer to function
c) Reference to object or reference to function
d) All of the above
10. Consider the declaration of a template non-type argument in the following code snippet:
template < class temp, int max> class sample
{
temp a[max];
static int b=50;
// ………
}
Which of the following statement(s) does not invoke the above template correctly?
I. sample< float, 10*10> x;
II. sample< float, 30>20> x;
III. sample< float, (30>20)> x;
IV. sample< float, 10.0> x;
a) I only
b) III only
c) Both II and IV
d) Both I and III


Chapter XII: Templates

1. b) generic programming
2. d) None of the above
3. a) sample < char> characterArray;
4. a) template < class temp1, class temp2…>
5. c) Declares a sample() function template that receives a value of given data type and
returns no value
6. d) None of the above
7. a) Line1
8. a) 0
9. d) All of the above
10. c) Both II and IV


Chapter XIII: Exception Handling

13. Which of the following error occur due to poor understanding of the language?
a) Logical error
b) Run-Time error
c) Syntax error
d) Program error
14. Which block handles the exception?
a) Finally block
b) Catch block
c) Try block
d) None of the above
15. Which of the following statement(s) is true about try block?
I. The try block is immediately followed by the catch block.
II. Try statement can have only one catch statement.
III. A program segment can have more than one catch statement with a try statement.
IV. All of the above
a) I only
e) Both I and II
f) Both I and III
g) IV only
16. What happens when the try block does not throw any exception?
e) The program is aborted
f) Normal execution is completed
g) Cannot be predicted
h) None of the above
17. What will be the output of the following code segment?

void function();
int main()
{
try
{
function();
}
catch (char)
{
cout<<"Caught a Char<< endl";
}
return 0;
}
void function()
{
throw 2;
}
}
a) Error in execution
b) Caught a Char
c) Abort() function is invoked
d) None of the above
18. Which of the following statement(s) is NOT true about catch (…) statement?
I. All the throws are not caught by catch (…) statement
II. Catch (…) statement should always be placed last in the list of handlers. Placing it before other catch blocks would prevent those blocks from catching exceptions
III. All the throws are caught by catch (…) statement
IV. Catch (…) statement should always be placed first in the list of handlers. Placing it before other catch blocks would prevent those blocks from catching exceptions
a) I only
b) Both II and III
b) Both III and IV
c) Both I and IV
19. Which of the following statement(s) is used to rethrow an exception?
a) throw(exception);
b) throw exception;
c) throw;
d) None of the above
20. Consider the following code segment:
void divide(int x, int y)
{
try
{
if(y==0)
throw y;
else
cout<< endl<<"Division result is: " << x/y<< endl;
}
catch(int)
{
throw;
cout<< endl<<"Caught Divide by zero error inside function";
}
}
int main()
{
try
{
divide(20,0);
}
catch(int)
{
cout<< endl<<"Caught Divide by zero error inside main";
}
return 0;
}
What will be the output of the above code?
e) Caught Divide by zero error inside main
f) Caught Divide by zero error inside main
Caught Divide by zero error inside function
g) Caught Divide by zero error inside function
h) None of the above
21. Which of the following is the general form of using an exception specification?
a) type function(arg-list) throw(type-list)
{
........
........ Function body
........
}
b) type function(arg-list) throw(arg-list)
{
........
........ Function body
........
}
c) type function(type-list) throw(type-list)
{
........
........ Function body
........
}
d) None of the above
22. What will happen if an error is not handled?
a) Error in compilation
b) Abrupt program termination
c) Error in execution
d) None of the above

Chapter XIII: Exception Handling

11. c) Syntax error
12. b) Catch block
13. c) Both I and III
14. b) Normal Execution is completed
15. c) Abort() function is invoked
16. d) Both I and IV
17. c) throw;
18. a) Caught Divide by zero error inside main
19. a) type function(arg-list) throw(type-list)
{
........
........ Function body
........
}
20. b) Abrupt program termination


Chapter XIV: Introduction to the Standard Template Library

1. Which of the following is not a sequence container available in STL?
a) vector
b) deque
c) array
d) list
2. Consider the following code snippet:
int main()
{
vector < int> v1(10);
vector < int> v2(10);
v1.at(0)=24;
v1.at(1)=20;
v1.at(2)=38;
for(int i=0;i <3; i++)
{
cout<< v1[i]<<" ";
}
v2=v1;
cout<< v2[0];
return 0;
}
What is the output of the above program?
a) Error as vectors cannot be copied
b) 24 20 38 24
c) 24 20 38
d) No output
3. Identify the correct combination for the following data:
I. Associative container : A. Random
II. Derived container : B. multiset
III. Sequence container : C. priority_queue
IV. STL iterator : D. deque

a) I-D, II-A, III-C, IV-B
b) I-D, II-C, III-A, IV-B
c) I-B, II-D, III-C, IV-A
d) I-B, II-C, III-D, IV-A
4. Consider the following code segment:
void main()
{
list < int> l1;
list < int> l2;
l1.push_front(6);
l1.push_back(8);
l1.push_front(4);
l1.push_back(5);
l1.push_front(3);
l1.reverse();
l1.front()=l1.front()*5;
l2=l1;
cout<< l1.front()<<" ";
cout<< l2.back();
}
What will be the output of the above code if there is no compile error?
a) 25 3
b) 16 4
c) 9 8
d) 36 5
5. Which of the following is true about Iterators in C++?
a) The functioning of Iterators is similar to pointers
b) Only the derived containers are traversable with iterators
c) The input and output iterators support the most functions of iterators
d) None of the above
6. Consider the following code segment:
1. void main()
2. {
3. list < char> l;
4. list < char>:: iterator i;
5. l.push_back('k');
6. l.push_back('i');
7. l.push_back('n');
8. i=l.end();
9. cout<< i;
10.}
The above code will not compile. Identify which line should be changed to fix the error.
a) Line 4
b) Line 3 & Line 4
c) Line 8
d) Line 9
7. Pick out the correct usage of the list function called, splice().
a) Deletes a list from the invoking list
b) Arranges the list elements as specified
c) Inserts a list into the invoking list
d) Gives the size of the list
8. If map_test is a map,
map k = map_test;
Which of the following statement(s) does illustrate the above code correctly?
I. It will create a new map k whose elements are logical copies of the elements of map_test.
II. It is equivalent to: mapmap_test(k);
III. It will create a new map map_test whose elements are logical copies of the elements of k.
IV. It is equivalent to: mapk(map_test);
a) I only
b) IV only
c) Both II and III
d) Both I and IV
9. Consider ‘i’ is an iterator that accesses the elements of a map. Which of the following will be used to access the two entries, namely key and value of the map?
a) i.first, i.second
b) (*i).first, (*i).second
c) *i.first, *i.second
d) *i.first, (*i).second
10. Which of the following is NOT true about function objects?
a) The class, which creates a function object, contains only one overloaded operator() function.
b) Function objects can be used to perform arithmetic and logical operations.
c) For using function objects, header file is needed.
d) None of the above

Chapter XIV: Introduction to the Standard Template Library

1. c) array
2. b) 24 20 38 24
3. d) I-B, II-C, III-D, IV-A
4. a) 25 3
5. a) The functioning of Iterators is similar to pointers
6. d) Line 9
7. c) Inserts a list into the invoking list
8. d) Both I and IV
9. b) (*i).first, (*i).second
10. d) None of the above


Chapter XV: Manipulating Strings

23. string is a
a) data-type
b) class
c) namespace
d) function
24. Which of the following function is used to read a line of text with blanks?
a) inputline( )
b) getline( )
c) putline( )
d) None the above
25. Which of the following function is not supported by the string class?
a) count( )
b) Assign( )
c) resize( )
d) empty( )
26. Consider the following code segment:
void main()
{
string s1("example");
string s2("2468");
s1.insert(2,s2);
s1.erase(3,5);
s1.replace(2,3,s2);
cout<< s1;
cout<< endl;
}
What will be the output of the above code?

h) ex2468ample
i) ex2ple
j) ex2468e
k) None of the above
27. Consider the following code segment:
void main()
{
int a,b;
string s1("aabbcc");
string s2("bbccaa");
a = s1.compare(4,2,s2,2,2);
b = s1.compare(0,2,s2,0,2);
if(a == 0)
cout<<"Equal , ";
else
cout<< "Not equal ,";
if(b ==0)
cout<<"Equal";
else
cout<<"Not Equal";
}
What will be the output of the above code?
i) Not Equal , Equal
j) Not Equal , Not Equal
k) Equal , Equal
l) Equal , Not Equal
28. Which of the following function does exchange the contents of two strings?
a) exchange( )
b) change( )
c) swap( )
d) None of the above
29. Which of the following function can retrieve the character stored at a specified location?
a) at( )
b) find_first_of( )
c) find( )
d) find_last_of( )
30. Consider the following code segment:
void main()
{
string s1("Time and tide wait for none");
int f;
f=s1.find("t");
cout<< endl<< f;
f=s1.find_first_of("t");
cout<<"\t"<< f;
f=s1.find_last_of("t");
cout<<"\t"<< f;
f=s1.find_first_not_of("t");
cout<<"\t"<< f;
f=s1.find_last_not_of("t");
cout<<"\t"<< f;
}
What will be the output of the above code?

a) 0 0 17 1 26
b) 0 9 17 0 26
c) 9 0 17 0 26
d) 9 9 17 0 26
31. Consider the following statement:
s1.compare (s2);
Which of the following statement is true about compare( ) function?
I. Returns 0 if s1 and s2 are equal
II. Returns -1 if s1 is greater
III. Returns -1 if s2 is greater
IV. Returns 1 if s1 and s2 are equal
a) Both I and III
b) Both III and IV
c) Both I and II
d) I only
32. Which of the following operator does represent concatenation assignment?
i) &=
j) +
k) +=
l) =

Chapter XV: Manipulating Strings

21. b) class
22. b) getline( )
23. a) count( )
24. c) ex2468e
25. d) Equal , Not Equal
26. c) swap( )
27. a) at( )
28. d) 9 9 17 0 26
29. a) Both I and III
30. c) +=


Chapter XVI: New Features of ANSI C++ Standard

1. Which of the following data type(s) is introduced by ANSI C++?
a) bool
b) wchar_t
c) char_t
d) Both a and b
2. Consider the following code snippet:

……………………………..
int p;
string s("Pass");
bool k;
if(s=="pass")
{
k=true;
}
p=true+50+false;
cout<< p;
……………………………..
What will be the output on executing the above code?
a) Error as the Boolean values cannot be added
b) 51
c) 52
d) No output
3. Which of the following character literal(s) does use two bytes of memory?
a) wide_character literal
b) byte_character literal
c) new_character literal
d) None of the above
4. Which of the following casting operator can cast a pointer to any other type of pointer in ANSI C++?
a) const_cast
b) dynamic_cast
c) reinterpret_cast
d) static_cast
5. Consider the following code snippet:
……………….
char *a,b;
if(typeid(a)==typeid(b))
cout<<"a";
else
cout<<"b";
………………….
What will be the output of the above code?
a) b
b) a
c) Compilation error
d) No output
6. Consider the following code snippet:
1. class sample
2. {
3. public:
4. explicit sample(float);
5. int a;………………
5. }

6. sample x=10.5;
………..
The code will not compile. Which of the following option will solve the problem?
a) Line 6 should be changed to sample x(10.5);
b) In line 4, explicit keyword should be removed
c) Both a and b
d) Either a or b
7. Which of the following keyword is used to modify a const object?
a) explicit
b) typeid
c) mutable
d) typename
8. Which of the following option will create a user-defined namespace in ANSI C++?
a) namespace namespace_name{….};
b) namespace(){namespace_name}
c) namespace namespace_name{….}
d) namespace(){namespace_name}
9. Let us define a namespace called ‘samplespace’, which includes a member variable, namely ‘p’. How will you access this member variable from outside the namespace?
I. using namespace samplespace;
II. using samplespace :: p;
III. samplespace.p;
IV. p :: samplespace();
a) I only
b) II only
c) Both III and IV
d) Both I and II
10. Write the equivalent expression using operator keywords for the following.
(a!=b) > (~(a & b)&=(a^b))
a) (a not_eq b) gt (not( a bitand b) and_eq (a xor b))
b) (a not_eq b) > (compl( a bitand b) and_eq (a xor b))
c) (a not_eq b) gt (not( a bitand b) not_eq (a exor b))
d) (a not_eq b) > (compl( a bitand b) not_eq (a exor b))

Chapter XVI: New Features of ANSI C++ Standard

1. d) Both a and b
2. b) 51
3. a) wide_character 2literal
4. c) reinterpret_cast
5. a) b
6. d) Either a or b
7. c) mutable
8. c) namespace namespace_name{….}
9. d) Both I and II
10. b) (a not_eq b) > (compl( a bitand b) and_eq (a xor b))

Chapter XVII: Object-Oriented Systems Development

1. Which model of object-oriented paradigm replaces the classic “water-fall” model of procedure-oriented development?
a) Fountain model
b) Spiral model
c) Throwaway prototyping model
d) None of the above
2. Functional decomposition technique can be used to implement _________.
a) Spiral model
b) Water-fall model
c) Reuse model
d) Fountain model
3. Which of the following is true about object-oriented analysis (OOA) approach?
a) Identifies the objects and their attributes
b) Identifies the services that each object is expected to provide
c) Establishes interconnections between the objects
d) All of the above
4. Data flow diagram is also known as________.
a) Bubble chart
b) Data flow graph
c) Both a and b
d) None of the above
5. Which of the following can be used to identify the services provided and received by objects?
a) Information Flow Diagram
b) Entity-Relationship Diagram
c) Either a or b
d) Neither a nor b
6. Which relationship defines ‘is_a’ relationship in object-oriented design?
a) Containment relationship
b) Inheritance relationship
c) Use relationship
d) None of the above
7. Let us assume that there are two classes, namely M and N. Consider the following statement:
M calls a member of N
Which object-oriented relationship can provide this information?
a) Use relationship
b) Containment relationship
c) Inheritance relationship
d) None of the above
8. Which of the following is associated with the process of a class organization?
a) Single-tree model
b) Forest model
c) Both a and b
d) None of the above
9. Which of the following is NOT true about prototyping process?
a) It is the process of building and testing a working model of the proposed system
b) It is the process of time consuming and expensive
c) Both a and b
d) None of the above
10. Which of the following can be used to identify the objects in object-oriented design?
a) Textual analysis
b) Data flow diagram
c) Both a and b
d) None of the above

Chapter XVII: Object-Oriented Systems Development

1. a) Fountain model
2. b) Water-fall model
3. d) All of the above
4. c) Both a and b
5. c) Either a or b
6. b) Inheritance relationship
7. a) Use relationship
8. c) Both a and b
9. b) It is the process of time consuming and expensive
10. c) Both a and b

Post a Comment

0 Comments