Chapter End Quiz
Chapter End Quiz
Chapter End Quiz
Which of the following languages is not a pure Object-Oriented language? a) Java b) Simula c) Ada d) Eiffel Which of the languages is a pure object-oriented language? a) C++ b) Smalltalk c) Object Pascal d) Objective C Which of the following statements is TRUE with respect to object-oriented programming? a) Emphasis is on algorithms rather than data. b) Data can move freely from function to function. c) Programs are divided into small programs called functions. d) Data and functions that operate on them are tied together. 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. One of the major advantages of object-oriented programming approach is: a) It can easily map real-world problems. b) Data can move freely around the system. c) Any language can be used for programming. d) Structured programming concept can be easily incorporated. The wrapping up of data and functions into a single unit is known as a) Function overloading b) Static binding c) Abstraction d) Encapsulation 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
2.
3.
4.
5.
6.
7.
8.
Which one of the following concepts enables the reusability of code? a) Dynamic binding b) Polymorphism c) Inheritance d) Encapsulation The term function over loading refers to: a) Message passing b) Dynamic binding c) Data hiding d) Polymorphism Which of the following characteristics C++ does not support? a) Persistence b) Generacity c) Garbage collection d) Late binding Encapsulation ensures that a) any function in the program can access the data b) external functions cannot access an objects nonpublic data c) external functions cannot access any data of the object d) the data of the object is never modified A rectangle notation that is used to denote an object usually show a) communication links with other objects b) only data members of the object c) data and functions of the object d) relationship with other objects
9.
10.
11.
12.
CHAPTER 2: 1.
C++ is an extension of C language. One of the new features added is: a) Structure b) Union c) Operator overloading d) Function Which of the following statements is FALSE? a) In a C++ program, the execution begins at main() function. b) Every C++ program must have a main() function. c) Every C++ statement must end with a semicolon. d) C++ does not permit the use of printf() for displaying an output. Line commands are inserted into a C++ program using a) Left and right curly brackets like {} b) Double forward slashes like //.. c) Stars and slashes like /*..*/ d) A colon like this : .. 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 // 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> Which of the following statements provide two lines of output? a) cout << VERY << GOOD; b) cout << VERY \n << GOOD \n; c) cout << VERY << GOOD \n; d) cout << \nVERY // First line << GOOD; // Second line
2.
3.
4.
5.
6.
7.
Which of the following statements is invalid in C++? a) cin >> count; b) cin >> x; >>y; c) cin >> x >> y; d) cin >> x >>y; 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); 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> 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();
8.
9.
10.
CHAPTER 3: 1.
Which one of the following is an ANSI C keyword? a) public b) operator c) export d) volatile Which one of the following is not a C++ keyword? a) constant b) false c) explicit d) throw 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 Which of the following is a valid C++ identifier? a) Total value b) 2x c) _string1 d) template Which of the following is not a valid literal constant in C++? a) ANSI C++ b) 0X5 c) 12, 345 d) 9.234L Which of the following is a user-defined data type in C++? a) array b) enumeration c) void d) function Which of the following is not a built-in data type in C++? a) structure b) void c) char d) long double
2.
3.
4.
5.
6.
7.
8.
Which of the following program segments is valid in C++? a) void *p1; char *p2; p2 = p1; b) void *p1; int *p2; *p2 = *p1; void *p1; char *p2; p2 = (char *) p1; enum colour {red, blue}; colour background; background = 1;
c)
d)
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 Which of the following declaration statements is illegal? a) const int m = 10; b) const int count; c) const m = 100; d) int const *p = &x; Which of the following statements is FALSE? a) All variables must be declared before they are used b) All variables must be given a type when they are declared c) A variable can be declared anywhere in the scope d) A variable must be initialized at the time of its declaration Identify the error, if any, in the statement: long sum = m1 + m2; a) Declaration cannot contain any expression b) Initialization at the time of declaration is not valid. c) Type specification is incomplete. d) No error
10.
11.
12.
13.
Which of the following statements is invalid? a) int p = new int ; b) int *p = new int ; c) int *p = new int [10] ; d) int *p = new int [m] [10] ; For using the manipulator setw(), we must include the header file: a) <iostream> b) <cstdio> c) <iomanip> d) <cstdlib> 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; The statement a=(b=10) 5; is an example of a) Chained assignment b) Embedded assignment c) Compound assignment d) None of the above Which one of the following expressions is an example of bitwise expression? a) x>=y b) x==10 && y<5 c) x << 10 d) x + = 10 Which of the following operators in C++ can be overloaded? a) Conditional operator (?:) b) Scope resolution operator (::) c) Member access operator (.*) d) Relational Operator (<=) 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) %, *, ->*, /=
14.
15.
16.
17
18
19.
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: 1.
FUNCTIONS IN C++
Which one of the following statements is a valid main function prototype? a) void main ( ); b) int main (int a, int b) c) main (int argc, char argv); d) int main(int argc, char* argv[ ]); Which one of the following is true about a function in a C++ program? a) A function must be called at least once. b) A function may called as and when required. c) A function can be called only by the main function. d) A function must always return a value. Which of the following function prototypes is invalid? a) void exchange (int, int); b) void exchange (int a, int b); c) void exchange (int x, y); d) void exchange (float, int); Find the error in the following function prototype double area (int) a) b) c) d) Argument name is not specified Semicolon at the end is missing Return type and argument type must be same No error
2.
3.
4.
5.
In C++, the main function returns to the operating system a) an integer value b) a floating point value c) address of the function d) none of the above The call by reference approach of invoking a function enables us to a) copy the values of arguments into the calling function b) not to alter the values of the original variables in the calling program c) change the values of the variables in the calling program d) use the function on the left-hand side of an assignment statement
6.
7.
Following is a list of function declarations with default values. Which one of them is a valid declaration? a) float mul(float a=5.0, b=10.0); b) float mul(int a, float b=10.0, int c); c) float mul(int a=5, float b); d) float mul(int a, float b=10.0); 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); a) b) c) d) int mul(int a, int b); double mul(float a, float b); double mul(int a, double b); int mul(float a, int b);
8.
9.
The usage of macros in C may be replaced in C++ by a) friend functions b) inline functions c) virtual function d) functions with default arguments The function mul(void) { return(5.5 * 3); } when executed will return a) 16 b) 16.5 c) 16.0 d) error 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.
10.
11.
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: 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. In a class definition, the members declared as private are accessible a) only to the public functions of the class b) to any function in the program c) only to functions declared as private d) to all member functions of the class By default, member functions of a class become a) private b) public c) protected d) inline In a class, a member declared as public is accessible a) only to public members of the class b) only to member functions of the class c) to any function in the program d) without using objects of the class The dot operator is used to connect a) a class and a member of that class b) a class object and a member of that class c) a class object and any function d) a class and an object of that class Declaration of members as private in C++ enables it to implement the concept a) polymorphism b) modularity c) abstraction d) encapsulation 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.
2.
3.
4.
5.
6.
7.
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 Which one of the following statements is FALSE? a) A member function defined outside can be made inline using the qualifier inline. b) An object of a class can access all its member functions whether they are declared private or public. c) A member function can be called by using its name alone inside another member function. d) A private member function can only be called by another function that is a member of its class. When called by its object, a member function declared as const a) can modify data of only const members. b) can modify data of only non-const members. c) can modify data of all members. d) cannot alter any data in the class. A member function declared as static a) can have access to only other static members of its class b) must be called using only the objects of its class c) can be called using only its class name d) can have access to all members in the same class 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. 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. 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.
9.
10.
11.
12.
13.
14.
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: 1.
Which of the following is NOT TRUE about constructors and destructors? a) They must the same names as class. b) They cannot return values. c) They can be invoked only once in a program. d) They are called automatically. 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. 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; 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 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 ( );
2.
3.
4.
5.
6.
Identify error, if any, in the following code segment: 1. class Sample 2. { 3. int m; 4. Sample ( ); 5. Sample (int); 6. }; e) f) g) h) Line 6 should not have semicolon In line 5 parameter name is missing In line 4, argument should be of type void Constructors should be declared in public section
7.
Which one of the following is TRUE about a copy constructor? a) It is used for passing address of data members b) It declares and initializes an object from another object c) It is invoked automatically when an object the class is declared d) We can pass the argument by value to it Which of the following statements is TRUE? a) A class can have only one constructor b) A constructor must be declared for each class c) A default constructor can only be supplied by the compiler d) A constructor is automatically called each time an object is created Which of the following statements is TRUE? a) A destructor must be declare for each class b) A class can have only one destructor c) A destructor can have default arguments d) Destructors are not useful when the class contains pointer data members Which of the following statements is FALSE? a) A class can have only default constructor b) A default constructor can only be supplied by the compiler c) A default constructor may be declared without any parameters d) All parameters of a default constructor can have default values
8.
9.
10.
CHAPTER 7: 1.
OPERATOR OVERLOADING
Operator overloading means a) giving new meanings to the existing C++ operators b) creating new C++ operators c) changing the precedence of operators d) non of the above Which of the following operators cannot be overloaded? a) Scope resolution operator (::) b) sizeof operator c) Member access operator (.*) d) All of the above Operator overloading is used to a) provide encapsulation b) support inheritance c) support compile-time polymorphism d) support run-time polymorphism State which of the following statements is TRUE. a) Operator functions never return a value. b) Friend functions cannot be used for operator overloading. c) An operator function must have at least one argument. d) The overloaded operator must have at least one operand that is of user-defined type. State which of the following statements is FALSE. a) Overloaded operators follow the syntax rules of the original operators. b) Friend functions can be used to overload all the over loadable operators. c) Unary operators overloaded by means of a member function take no explicit argument d) Binary arithmetic operator functions must explicitly return a value 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 When use a) b) c) d) overloading binary operators using member functions, the operator functions two explicit arguments one explicit argument one implicit and one explicit arguments one implicit argument
2.
3.
4.
5.
6.
7.
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 The casing operator function can be used to accomplish the conversion a) class type to structure type b) basic type to class type c) float type to long type d) class type to basic type The casting operator function must a) be a class member b) not specify any return type c) not have any arguments d) All of the above
9.
10.
CHAPTER 8: 1.
The concept of inheritance enables C++ a) to pass arguments to objects of classes b) to create new classes from existing classes c) to improve data hiding d) to support abstraction What is the advantage of using inheritance in C++? a) Facilitates creation of class libraries b) Enables reuse of existing code c) Enhances reliability of the code d) All the above Through inheritance, it is possible to inherit from a class a) only data members b) only members functions c) any members as we desire d) only functions declared as friend In the class definition class M : visibility-mode N { members of M }; the visibility-mode a) must be blank b) must be public c) must be private d) may be blank, public or private Consider the code segment class A { private : int a ; public : int b ; protected : int c ; }; class B : A { }; class C : public B { }; The derived class C would contain the members a) a, b and c b) b and c only c) b only d) none
2.
3.
4.
5.
6.
Which of the following statements is TRUE, when a derived class D inherits a base class B using protected specifier? a) public members of B become protected members of D b) public members of B become public members of D c) public members of B become private members of D d) public members are not inherited 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 The use of scope resolution operator in inheritance enables us a) to restrict the visibility of data members b) to determine the base class of a derived class c) to specify a particular class d) to make a private member inheritable The process of a class inheriting attributes from several classes is known as a) multilevel inheritance b) multiple inheritance c) multipath inheritance d) hybrid inheritance 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 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;
7.
8.
9.
10.
11.
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 Which one of the following statements is FALSE? a) Deriving one class from another requires fundamental changes to the base class b) If no constructors are declared for the derived class, the objects of the derived class will use the constructors in the base class c) There may be situations where we may have to define a class which will never be used to create objects d) It is legal to make objects of one class as members of another class. Consider the following class definition with inheritance: class A : public B, virtual public C { }; The order of execution of constructors will be: a) A ( ), B ( ), C ( ) b) C ( ), B ( ), A ( ) c) B ( ), C ( ), A ( ) d) A ( ), C ( ), B ( ) Consider the following class class ABC { int a; int b; public : constructor function }; We wish to define the constructor function using an initialization list. Which one of the following is the legal constructor function? a) ABC (int x, int y): a (x), b(y) { } b) ABC (int x, int y): b (x), a(x+y) { } c) ABC (int x, int y): a (x), b(a*y) { } d) All the above
13.
14.
15.
CHAPTER 9: 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 The declaration statement int* p1, p2 ; a) declares two pointer variables p1 and p2 b) declares two integer variables p1 and p2 c) declares p1 as a pointer variable and p2 as an integer variable d) is illegal because of blank space between * and p1 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 For the statement p = *m; which of the following statements is TRUE? a) The value of m is assigned to p b) The value of the variable pointed to by m is assigned to p c) p is a pointer variable d) Address of m is assigned to p Identy the error in the following code segment int *ptr, m = 100; // line 1 cout << *ptr; //line 2 a) Declaring ptr and m in one line is wrong b) In line 2, *ptr should be written as &ptr c) The address of m should be assigned to ptr before it is accessed d) No error Compile-time polymorphism is accomplished by using a) function overloading b) Operator overloading c) a and b d) neither a nor b
2.
3.
4.
5.
6.
7.
The mechanism of using virtual functions to achieve polymorphism is known as a) run-time polymorphism b) dynamic binding c) late binding d) all the above
8.
consider the following class definition: class Test { public : void show (void) {cout <<Test;} }; If x is an object of Test and ptr is a pointer to x, then which one of the following statements can correctly invoke the function show ( )? a) x.show ( ) ; b) ptr -> show ( ) ; c) (*ptr). show ( ); d) all the three 9. If x is a private data member of a class, then it is legal to assign a value to x inside a member function using a) x = 100; b) this ->x = 100; c) (*this).x = 100; d) all the above The statement return * this ; inside a member function of a class returns a) a copy of the object that invoked the function b) address of the member function c) address of this pointer d) None of the above Which of the following statements is FALSE? a) Address of a derived class object can be assigned to a base class pointer b) Teating the base class object as a derived class object is wrong c) Address of a base class object can be assigned to a derived class pointer d) A base class pointer cannot be used to access all the members of the derived class In C++, virtual functions are used to a) create functions that can never be accessed b) enable the use of the same function call to invoke functions from different classes c) to make a base class abstract d) to create an array of base class pointers that can point to different functions
10.
11.
12.
13.
Which of the following statements is TRUE about virtual functions? a) A constructor cannot be a virtual function b) A virtual function in the base class must be defined, eventhough it may not be used c) They cannot be declared static d) All the above A pure virtual function is a virtual function that a) makes the class to be abstract b) is used in derived classes c) is used to transform the base class into a virtual base class d) takes no argument and returns nothing Which of the following statements is TRUE? a) All virtual functions in an abstract base class must be declared as pure virtual functions b) A class is made abstract by declaring it virtual c) If a base class declares a pure virtual function, all derived classes must define the function d) A derived class cannot contain a pure virtual function
14.
15.
CHAPTER 10: 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 Which of the following statements is TRUE? a) The extraction operator >>always skips white space characters b) The cout stream is normally connected to the display screen c) The function write ( ) outputs an entire line of text d) All the above e) None of the above Which of the following statements is FALSE? a) The put( ) function can be used to output a line of text using a loop construct b) The get( ) can be used to read a character from keyboard including blank space and new line character c) The function getline( ) does not take any arguments d) A C++ stream is associated with a particular class Which of the following statements is illegal? a) cin.get(x); b) cin.get(x); c) x = cin.get( ); d) cout.put(x); If m and n represent integer values, which of the following statements is legal? a) cout.write(text, 10); b) cout.write(text, m); c) cout.write(text1, m).write (text2, n); d) All the above e) None of the above The ios format function precision ( ) is used to a) specify required field size b) specify the number of digits to be displayed after decimal point c) specify the number of digits to be displayed of an integer number d) display output in scientific format
2.
3.
4.
5.
6.
7.
The statements cout.width(4); cout<< 12 << 34 << \n; will produce the output in the following format a) 1 2 3 4 b) c) d) 1 2 1 1 3 e) 1 3 2 4 3 4
2 3 4 2 4
8.
Which of the following statements is TRUE? a) We need not specify the precision for each item separately b) If the specified field width is smaller than the size of the value, C++ expands the size of field to fit the value c) When displaying floating point numbers using precision function, the trailing zeros are truncated d) When the function width ( ) is used, the text is printed right justified e) All the above Which of the following is a valid statement? a) cout.setf(ios:: internal, ios:: basefield): b) cout.setf(ios:: scientific, floatfield); c) cout <<setf(ios:: hex, ios:: basefield); d) None of the above 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
9.
10.
11.
What would be the output of the following code segment? cout.setf(ios:: showpos); cout.precision(2); cout<< 345.609 a) b) c) d) e) 345.60 +345.61 +345.6 +345.609 345.61
12.
Which of the following statements are legal? (i) cout << setwidth (5); (ii) cout.setprecision (3); (iii) cout <<123.45 << setw (10); a) b) c) d) e) f) i only i and ii i and iii iii only ii and iii all the three
CHAPTER 11: 1.
All file stream classes are derived from a) filebuf b) fstream c) fstreambase d) ios Which of the following classes support simultaneous input and output file operations? a) iostream b) fstream c) filebuf d) None of the above Which of the following is TRUE? a) We must call close( ) function explicitly to close a file associated with an fstream object b) Always sequential files are updated without overwriting any data c) Any existing file can be opened for writing only purpose d) Searching all records in a random-access file to locate a record is not necessary Which of the following is FALSE? a) A file can be opened only using the constructor function of the stream class b) Some streams work with input, and some with output c) The function open ( ) can be used to open multiple files using one stream d) The open ( ) can take two arguments 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 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
2.
3.
4.
5.
6.
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 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 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 Any fatal error occurring during a file operation can be located by using the function a) fail ( ) b) bad ( ) c) eof ( ) d) good ( )
8.
9.
10.
CHAPTER 12: 1.
TEMPLATES
A template may be used to create a family of a) different types of variables b) classes c) functions d) classes and functions C++ templates provide support for designing a) modular programming b) structured programming c) generic programming d) top-down programming A class template is designed a) to generate identical objects b) to work with different data types c) to generate classes with different functions d) All of the above Which one of the following is FALSE? a) class templates are sometimes called parameterized classes b) There can be more than one template arguments c) A template argument is preceded by the keyword class d) Templates automatically create different version of the function at run-time, depending on user input 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 Given below is the definition of a function template template [class T] T mul (x, y) { return x * y; } Identify errors, if any. a) class T in the first line should be within angle brackets < and > b) The type of arguments of mul function must be declared as T c) Both a and b d) No error
2.
3.
4.
5.
6.
7.
Which of the following statements is TRUE? a) Member functions of a template class defined outside the class need not be defined as function templates b) In class templates with multiple arguments, all the arguments need not be of class T type arguments c) Template functions can not be overloaded d) All the above Consider a function template as shown below: template < class T > int find (T*array, T n, int m) { for ( int i = o; i < m; i++) if (array [i] = = n return i; return (-1); } Which one of the following prototype calls can generate a function? a) find (int*, float, int); b) find (T*, int, int); c) find (int*, int, float); d) find (float*, float, int); As we know, a macro can be used to create different versions of a function for different data type. What is then the difference between a macro and a class template? a) macros do not perform type checking b) Macros do not specify the type of the value to be returned c) Macros are suitable to functions that can written in a single statement d) All the above 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
8.
9.
10.
CHAPTER 13: 1.
EXCEPTION HANDLING
Exceptions are caused by a) logic errors b) syntax errors c) both logic and syntax errors d) anomalies that a program may encounter during execution Which of the following events could throw an exception? a) Division by zero b) Array subscripts out of bounds c) Shortage of memory space available to satisfy a new request d) All of the above Exceptions are thrown a) from throw statement to try block b) from throw statement to catch block c) from catch block to try block d) from the statement containing error to catch block State which of the following is TRUE. a) Statements that cause an exception must be in a catch block b) A statement that causes an exception should be in a try block c) Once an exception is thrown, the control cannot return to the throw point d) A program cannot continue to operate after an exception has ocurred. The catch block a) must be placed immediately after the try block b) must be placed just before the try block c) must be placed immediately after the statement throwing exception d) may be placed anywhere in the program Which of the following are legal throw statements? a) throw ( ); b) throw (exception); c) throw exception ; d) throw; e) All of the above When an exception occurs inside a catch block, what happens? a) The exception is caught by the same catch block b) The exception is caught by the next catch block in the group c) It will be passed on to the next try / catch sequence for processing d) The execution will terminate
2.
3.
4.
5.
6.
7.
8.
The statement catch () that can catch all types of exception a) can be placed anywhere in the program b) can be placed anywhere in the catch group c) must always be placed in the beginning of catch group d) must always be placed in the last in the catch group An exception thrown by a try block that is followed by a group of catch blocks, a) is caught by the first catch statement in the group b) is caught by the catch( ) whose argument matches with the type of exception thrown c) is always caught by catch () statement placed at the end d) is caught by the catch statement in the next enclosing try / catch sequence We may restrict the types of exception thrown from a function a) by placing the try block in the function itself b) by placing the try block in the main that invokes the function c) by adding a throw (type-list) to the function definition d) by adding an empty throw ( ) in the function header line
9.
10.
CHAPTER 14: 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 To implement STL components in a program, we must include a) using namespace std directive b) <cstdlib> header file c) <cstdio> header file d) <functional> header file An STL containers can be used to a) compile C++ programs that use template classes b) store objects of any data type c) process data stored in memory d) None of the above Which one of the following is FALSE? a) An iterator can be handled just like a pointer b) One purpose of an iterator in STL is to connect algorithms and containers c) STL algorithms are member functions of containers d) STL algorithms operate on container elements indirectly using iterators 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 Which one of the following is TRUE? a) Algorithms can be used only on STL containers b) An iterator can always move forward or backward through a container c) The back( ) member function removes the element at the back end of the container d) The member function end( ) returns a reference to the last element in the container Which one of the following is a sequence container? a) deque b) set c) queue d) None of them
2.
3.
4.
5.
6.
7.
8.
A vector container a) is a static array b) allows insertions and deletions fast at back c) allows insertions anywhere very fast d) does not permit direct access to any element Which one of the following is a non-mutating algorithm? a) unique ( ) b) merge ( ) c) for_each ( ) d) partition ( ) Which value? a) b) c) d) of the following algorithm is used to replace an element with a specified generate ( ) replace_copy ( ) remove_copy ( ) replace ( )
9.
10.
11.
In associative containers, a) elements are stored sequentially b) keys are used to access elements c) random access is very fast d) sort ( ) algorithm is used to sort the elements A list container a) permits the use of bidirectional iterators b) supports only forward iterator c) supports only input iterator d) allows random access A map container a) does not allow deletion of any element b) allows insertion only at the end c) stores pairs of objects (or values) d) associates multiple keys for a given value To use the function object modulus < int > ( ) in a program, we must include the header file a) <map> b) <functional> c) <list> d) <algorithm>
12.
13.
14.
15.
Consider the following code: int main ( ) { vector <int> x; for (int i = 1; i<4; i++) v.push_back(i); v.push_back(7.6); vector<int>:: iterator p = v.begin ( ); p = p + 1; v.insert (p, 5); v.erase (v.begin + 3); return 0; } When executed, the vector will contain the elements a) 1, 5, 2, 8 b) 1, 5, 3, 7 c) 1, 2, 5, 7 d) 1, 5, 2, 7 e) None of the above
CHAPTER 15: 1.
MANIPULATING STRINGS
Which one of the following is a string class constructor? a) string (void); b) string (const char * str); c) string (string & str); d) All of them Which one of the following initialization statements is illegal? a) string city1="Delhi"; b) string city1("Delhi"); c) string city2= "New" + city; d) string city3(city1); e) None of the above Identify the error in the following statement for(int i=1; i<=string1.length( );i++) cout <<string1.at(i); a) b) c) d) The second line should have opening and closing braces like {} Initial value for i should be zero The relational operator should be < and not <= string1.at(i) should be written as string1.at[i]
2.
3.
4.
What will be the output of the following code segment? int main ( ) { string s1("Hello"); string s2("123"); s1.insert(4, s2); s1.replace(2, 2, s2); cout << s1; return 0; } a) He123 b) Hel123 c) Hell123 d) H123o e) None of the above Which of the following functions is not supported by the string class? a) capacity ( ) b) empty ( ) c) assign ( ) d) count ( )
5.
6.
Which of the following operators cannot be used for string objects? a) [] b) & c) += d) << Which of the following are TRUE for the statement s1.compare(s2); (i) (ii) (iii) (iv) (v) (vi) a) b) c) d) returns 1, when s1 and s2 are equal returns 0, when s1 and s2 are equal returns 1, if s1 < s2 returns 1, if s1 > s2 returns 1, if s1 < s2 returns 1, if s1 > s2 i, ii and vi ii, iv and v ii, iii and vi i, iii and vi
7.
8.
To access individual characters, we must use the function a) find ( ) b) substr( ) c) find_first_of ( ) d) at ( ) Which of the following is TRUE? a) String objects are null terminated b) Function end ( ) returns an iterator to the invoking objects c) Elements of string objects are numbered from 0 d) String objects cannot be copied using assignment operator 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);
9.
10.
CHAPTER 16: 1.
One of the new data types introduced by ANSI C++ standard is a) new b) throw c) bool d) void 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 Consider the following code segment: int x=10, y=20; bool b1, b2; b1 = x = = y; b2 = x < y; bool b3 = 15; y = x + y + b1 + b2 + b3 cout << y; What will be the output on executing the above code? a) Error; we cannot assign integer value to a Boolean variable b) 30 c) 33 d) 32 Which of the following operators is used to obtain the type of an object? a) const_cast b) typeid c) typedef d) dynamic_cast
2.
3.
4.
5.
What will be the output of the following code, when executed? . class X { }; class Y { }; int main ( ) { X x1, x2; Y y1, y2; if (typeid(x1) = = typeid(y1)) cout <<"same types"; else cout <<Different types"; } a) Different types b) Same types c) Error; we cannot compare types of two objects d) Error; typeid( ) should be written in the form typeid(object).name( ) Consider the code segment: class Test { float x; public: explicit Test (float y) { x = y; } }; What are the changes required in the definition of the class Test, if it is to be implemented by the main ( ) as given below. int main ( ) { Test t1 = 35.65; cout << x; } a. Data member x should be declared public b. The keyword explicit should be removed c. Both a and b d. No changes required We can modify the value of a data member of an object declared constant by declaring it using the keyword a) explicit b) typeid c) typename d) mutable
6.
7.
8.
The correct format for defining a namespace is: a. namespace (namespace_name){} b. namespace namespace_name {} c. namespace namespace_name {}; d. namespace ( ) namespace_name {} 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 Given the namespace definition namespace S { int count; } How can we access the variable count outside the namespace? a) S::count = 10; b) using namespace S; count = 10 c) using namespace :: count; count = 10 d) All of the above
9.
10.
CHAPTER 17: 1.
One of the fmost frequently used second generation development tools is a) Inheritance graphs b) Object dictionary c) Data dictionary d) Yourdan charts The classic software development life cycle is usually represented by a) Fountain model b) Spiral model c) Unified model d) Water-fall model The object-oriented approach uses heavily a) structured charts b) entity relationship charts c) system flow charts d) Grid charts The fountain model of software development basically depicts a) overlap and iteration between various stages b) data flow in a system c) control logic of functions d) relationship between different modules of a system The 'is a' relationship can be illustrated by a) classification chart b) hierarchical chart c) composition chart d) inheritance chart 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 Data flow diagrams are also known as a) process charts b) bubble charts c) grid charts d) flowcharts
2.
3.
4.
5.
6.
7.
8.
Objects in a program may correspond to a) procedures for solving problems b) processes in a real_world problem c) semantics in textual description d) nouns in textual analysis Which of the following types of verbs is likely to be a good candidate for representing a member function? a) Compare verbs b) Being verbs c) Stative verbs d) Having verbs To prepare a class hierarchy, we need to know a) number of attributes in each class b) number of functions in each class c) common attributes and functions among class d) use relationship A class, in addition to service functions, may also contain a) class management functions b) class access functions c) class utility functions d) All the above 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 of the following statements is FALSE with regard to design of member Each function either accesses or modifies some data of the class it represents All functions must always be declared public They can use top-down functional decomposition technique They can use structured design techniques
9.
10.
11.
12.
The main ( ) function module known as the driver program a) cannot receive data values from users b) cannot display any output c) creates only objects from class definitions d) creates objects and establishes communication between them
15.
Let a be an object of class and b of class B. A and B have some association between them. Which of the following statements is TRUE? i) Object a can send a message to b ii) Object b can do some service to a iii) One class must be a subclass another iv) One object must be a member of another object a) b) c) d) i and ii iii and iv All the four None of the four