chapter end quiz

44
CHAPTER 1: PRINCIPLES OF OBJECT – ORIENTED PROGRAMMING 1. Which of the following languages is not a pure Object-Oriented language? a) Java b) Simula c) Ada d) Eiffel 2. Which of the languages is a pure object-oriented language? a) C++ b) Smalltalk c) Object Pascal d) Objective C 3. 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. 4. Which of the following issues is considered as the major drawback of the procedure – oriented programming? a) Employs tap-down approach in program design. b) Emphasis is an algorithms. c) Most of the functions share global data. d) Large programs are divided into functions. 5. 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. 6. The wrapping up of data and functions into a single unit is known as a) Function overloading b) Static binding c) Abstraction d) Encapsulation 7. The process by which objects of one class can acquire the attributes of objects of another class is known as a) Attribute passing b) Inheritance c) Abstraction d) Polymorphism

Upload: keyan-karthi

Post on 12-Oct-2014

104 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Chapter End Quiz

CHAPTER 1: PRINCIPLES OF OBJECT – ORIENTED PROGRAMMING

1. Which of the following languages is not a pure Object-Oriented language?a) Javab) Simulac) Adad) Eiffel

2. Which of the languages is a pure object-oriented language?a) C++b) Smalltalkc) Object Pascald) Objective C

3. Which of the following statements is TRUE with respect to object-orientedprogramming?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.

4. Which of the following issues is considered as the major drawback of the procedure –oriented programming?a) Employs tap-down approach in program design.b) Emphasis is an algorithms.c) Most of the functions share global data.d) Large programs are divided into functions.

5. 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.

6. The wrapping up of data and functions into a single unit is known asa) Function overloadingb) Static bindingc) Abstractiond) Encapsulation

7. The process by which objects of one class can acquire the attributes of objects ofanother class is known asa) Attribute passingb) Inheritancec) Abstractiond) Polymorphism

Page 2: Chapter End Quiz

8. Which one of the following concepts enables the reusability of code?a) Dynamic bindingb) Polymorphismc) Inheritanced) Encapsulation

9. The term function over loading refers to:a) Message passingb) Dynamic bindingc) Data hidingd) Polymorphism

10. Which of the following characteristics C++ does not support?a) Persistenceb) Generacityc) Garbage collectiond) Late binding

11. Encapsulation ensures thata) any function in the program can access the datab) external functions cannot access an object’s nonpublic datac) external functions cannot access any data of the objectd) the data of the object is never modified

12. A rectangle notation that is used to denote an object usually showa) communication links with other objectsb) only data members of the objectc) data and functions of the objectd) relationship with other objects

Page 3: Chapter End Quiz

CHAPTER 2: BEGINNING WITH C++

1. C++ is an extension of C language. One of the new features added is:a) Structureb) Unionc) Operator overloadingd) Function

2. 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.

3. Line commands are inserted into a C++ program usinga) Left and right curly brackets like {…}b) Double forward slashes like //…..c) Stars and slashes like /*..…*/d) A colon like this : …..

4. For declaring the variables a and b, which of the following declaration statements isincorrect?a) int a, b; // Declarationb) int a, /* Declaration*/ b;c) int a, // Declaration // b;d) int a, b; // Declaration //

5. For using functions that convert numbers to text and text to numbers, we must includethe following header file:a) <cstdlib>b) <iostream>c) <cstdio>d) <cmath>

6. 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

Page 4: Chapter End Quiz

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;

8. Which of the following statements requires the header file <math.h> to be included?a) cout <<x/y;b) x + = 10;c) x = m*n+1;d) x = sqrt(y);

9. Name the header file that is to be used in the #include directive when we use cout fordisplaying outputs.a) <cstdio>b) <cstdlib>c) <iostrean>d) <cassert>

10. If a is an object of the class B and void print (void) is a member function of B, thenwhich one of the following statements will invoke the function?a) a::print();b) a.voidprint();c) B.print();d) a.print();

Page 5: Chapter End Quiz

CHAPTER 3: TOKENS, EXPRESSIONS AND CONTRAL STRUCTURES

1. Which one of the following is an ANSI C keyword?a) publicb) operatorc) exportd) volatile

2. Which one of the following is not a C++ keyword?a) constantb) falsec) explicitd) throw

3. Which of the following statements is TRUE with regard to naming C++ identifiers?a) A name can start with any letter or digit.b) No special characters are permitted.c) Uppercase and lowercase letters are distinct.d) A name cannot have more than 32 characters

4. Which of the following is a valid C++ identifier?a) Total valueb) 2 xc) _string1d) template

5. Which of the following is not a valid literal constant in C++?a) “ANSI C++”b) 0X5c) 12, 345d) 9.234L

6. Which of the following is a user-defined data type in C++?a) arrayb) enumerationc) voidd) function

7. Which of the following is not a built-in data type in C++?a) structureb) voidc) chard) long double

Page 6: Chapter End Quiz

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;

c) void *p1;char *p2;p2 = (char *) p1;

d) enum colour {red, blue};colour background;background = 1;

9. Assumming that we are working an a 16-bit word machine, which of the followingtakes a size of 8 bytesa) signed long intb) long intc) long doubled) double

10. 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;

11. Which of the following statements is FALSE?a) All variables must be declared before they are usedb) All variables must be given a type when they are declaredc) A variable can be declared anywhere in the scoped) A variable must be initialized at the time of its declaration

12. Identify the error, if any, in the statement:long sum = m1 + m2;

a) Declaration cannot contain any expressionb) Initialization at the time of declaration is not valid.c) Type specification is incomplete.d) No error

Page 7: Chapter End Quiz

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] ;

14. For using the manipulator setw(), we must include the header file:a) <iostream>b) <cstdio>c) <iomanip>d) <cstdlib>

15. The following statements implement type cast operation. Which one of them is illegal?a) x = y/(float)m;b) x = y/float(m);c) x = float(y)/(float)m;d) x = y/float m;

16. The statementa=(b=10) – 5;

is an example ofa) Chained assignmentb) Embedded assignmentc) Compound assignmentd) None of the above

17 Which one of the following expressions is an example of bitwise expression?a) x>=yb) x==10 && y<5c) x << 10d) x + = 10

18 Which of the following operators in C++ can be overloaded?a) Conditional operator (?:)b) Scope resolution operator (::)c) Member access operator (.*)d) Relational Operator (<=)

19. In which of the following groups all the operators are in the same level ofprecedence?a) <<, < =, = =, << =b) new, sizeaf, typeid, !c) new, delete, ->, ::d) %, *, ->*, /=

Page 8: Chapter End Quiz

20 Which of the following loop structures is known as an exit-controlled loop?a) do… while loopb) while loopc) for loopd) None of the above

Page 9: Chapter End Quiz

CHAPTER 4: FUNCTIONS IN C++

1. 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[ ]);

2. 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.

3. 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);

4. Find the error in the following function prototypedouble area (int)

a) Argument name is not specifiedb) Semicolon at the end is missingc) Return type and argument type must be samed) No error

5. In C++, the main function returns to the operating systema) an integer valueb) a floating point valuec) address of the functiond) none of the above

6. The ‘call by reference’ approach of invoking a function enables us toa) copy the values of arguments into the calling functionb) not to alter the values of the original variables in the calling programc) change the values of the variables in the calling programd) use the function on the left-hand side of an assignment statement

Page 10: Chapter End Quiz

7. Following is a list of function declarations with default values. Which one of them isa 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);

8. The following is the list of function declarations. Which one of them will be invokedby the function call statement

cout <<mul(10.5, 10);

a) int mul(int a, int b);b) double mul(float a, float b);c) double mul(int a, double b);d) int mul(float a, int b);

9. The usage of macros in C may be replaced in C++ bya) friend functionsb) inline functionsc) virtual functiond) functions with default arguments

10. The functionmul(void){

return(5.5 * 3);}

when executed will returna) 16b) 16.5c) 16.0d) error

11. Which of the following statements is true in respect of a function containing constarguments?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.

Page 11: Chapter End Quiz

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

Page 12: Chapter End Quiz

CHAPTER 5: CLASSES AND OBJECTS

1. C++ supports both classes and structures. Which of the following statements isFALSE 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.

2. In a class definition, the members declared as private are accessiblea) only to the public functions of the classb) to any function in the programc) only to functions declared as privated) to all member functions of the class

3. By default, member functions of a class becomea) privateb) publicc) protectedd) inline

4. In a class, a member declared as public is accessiblea) only to public members of the classb) only to member functions of the classc) to any function in the programd) without using objects of the class

5. The dot operator is used to connecta) a class and a member of that classb) a class object and a member of that classc) a class object and any functiond) a class and an object of that class

6. Declaration of members as private in C++ enables it to implement the concepta) polymorphismb) modularityc) abstractiond) encapsulation

7. Listed below are some of the possible characteristics of member functions. Whichone of them is NOT TRUE?a) All the member functions should be defined within the class itselfb) Several different classes can use the same function namec) 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.

Page 13: Chapter End Quiz

8. State which of the following is false with respect to classes:a) They permit data to be hidden from other parts of the programb) They can directly map objects in the real worldc) They bring together all attributes of an entity in one placed) They are removed from memory when not in use

9. 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.

10. When called by its object, a member function declared as consta) 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.

11. A member function declared as statica) can have access to only other static members of its classb) must be called using only the objects of its classc) can be called using only its class named) can have access to all members in the same class

12. Which one of the following statements is not true for a member function declared asfriend?a) It can be invoked like a normal function without help of any object.b) It cannot access the members of the class directly.c) It cannot have objects as arguments.d) It cannot be called using the objects of its class.

13. Which of the following is TRUE about static member variable of a calss?a) Each object creates its own copy.b) It is visible only within the class.c) It can be initialized whenever necessary.d) It cannot be assigned any initial value at the time of definition.

14. Which one of the following is TRUE while passing objects as function arguments?a) A copy of the entire objects can be passed.b) Only the address of the object can be passed.c) A nonmember function can use objects as its arguments.d) All of the above.

Page 14: Chapter End Quiz

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.

Page 15: Chapter End Quiz

CHAPTER 6: CONSTRUCTORS AND DESTRUCTORS

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.

2. Which one of the following statements does correctly describe one of the manycharacteristics of constructors?a) They can be inherited.b) They can return values, like other functions.c) They can be declared anywhere in the class.d) They can have default arguments.

3. A constructor for the class Area having two data members length and breadth isdeclared as follows:

Area (int length = 15, int breadth = 10);Which one of the following object declarations is illegal?a) Area A(20, 10);b) Area A();c) Area A = Area (20, 10);d) Area A;

4. Which one of the following is an implicit constructor for the class ROOM having adata member area?a) Room ( ) { }b) Room (int a) {area = a}c) Room (Room & a) {area = a.area}d) None of the above

5. Which one of the following declations represents the legal copy constructor for theclass X?a) X (X);b) X (&X);c) X (X&);d) X ( );

Page 16: Chapter End Quiz

6. Identify error, if any, in the following code segment:1. class Sample2. {3. int m;4. Sample ( );5. Sample (int);6. };

e) Line 6 should not have semicolonf) In line 5 parameter name is missingg) In line 4, argument should be of type voidh) 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 membersb) It declares and initializes an object from another objectc) It is invoked automatically when an object the class is declaredd) We can pass the argument by value to it

8. Which of the following statements is TRUE?a) A class can have only one constructorb) A constructor must be declared for each classc) A default constructor can only be supplied by the compilerd) A constructor is automatically called each time an object is created

9. Which of the following statements is TRUE?a) A destructor must be declare for each classb) A class can have only one destructorc) A destructor can have default argumentsd) Destructors are not useful when the class contains pointer data members

10. Which of the following statements is FALSE?a) A class can have only default constructorb) A default constructor can only be supplied by the compilerc) A default constructor may be declared without any parametersd) All parameters of a default constructor can have default values

Page 17: Chapter End Quiz

CHAPTER 7: OPERATOR OVERLOADING

1. Operator overloading meansa) giving new meanings to the existing C++ operatorsb) creating new C++ operatorsc) changing the precedence of operatorsd) non of the above

2. Which of the following operators cannot be overloaded?a) Scope resolution operator (::)b) sizeof operatorc) Member access operator (.*)d) All of the above

3. Operator overloading is used toa) provide encapsulationb) support inheritancec) support compile-time polymorphismd) support run-time polymorphism

4. 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.

5. 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

argumentd) Binary arithmetic operator functions must explicitly return a value

6. When overloading binary operators using friend functions, the operator function usesa) two explicit argumentsb) one implicit and one explicit argumentsc) one explicit argumentd) no arguments

7. When overloading binary operators using member functions, the operator functionsusea) two explicit argumentsb) one explicit argumentc) one implicit and one explicit arguments d) one implicit argument

Page 18: Chapter End Quiz

8. We can use a constructor function for accomplishinga) conversion from class type to class type.b) conversion from basic type to class typec) conversion from class type to basic typed) non of the above

9. The casing operator function can be used to accomplish the conversiona) class type to structure typeb) basic type to class typec) float type to long typed) class type to basic type

10. The casting operator function musta) be a class memberb) not specify any return typec) not have any argumentsd) All of the above

Page 19: Chapter End Quiz

CHAPTER 8: INHERITANCE : EXTENDING CLASSES

1. The concept of inheritance enables C++a) to pass arguments to objects of classesb) to create new classes from existing classesc) to improve data hidingd) to support abstraction

2. What is the advantage of using inheritance in C++?a) Facilitates creation of class librariesb) Enables reuse of existing codec) Enhances reliability of the coded) All the above

3. Through inheritance, it is possible to inherit from a classa) only data members b) only members functionsc) any members as we desired) only functions declared as friend

4. In the class definitionclass M : visibility-mode N{

members of M};

the visibility-modea) must be blankb) must be publicc) must be privated) may be blank, public or private

5. Consider the code segmentclass A{

private : int a ;public : int b ;protected : int c ;

};class B : A { };class C : public B { };

The derived class C would contain the membersa) a, b and cb) b and c onlyc) b onlyd) none

Page 20: Chapter End Quiz

6. Which of the following statements is TRUE, when a derived class D inherits a baseclass B using protected specifier?a) public members of B become protected members of Db) public members of B become public members of Dc) public members of B become private members of Dd) public members are not inherited

7. Which of the following functions can have access to the protected data of a class?a) A function that is friend of the classb) A member function of a class declared friend of the classc) A member function of a derived classd) All the above

8. The use of scope resolution operator in inheritance enables usa) to restrict the visibility of data membersb) to determine the base class of a derived classc) to specify a particular classd) to make a private member inheritable

9. The process of a class inheriting attributes from several classes is known asa) multilevel inheritanceb) multiple inheritancec) multipath inheritanced) hybrid inheritance

10. A class D is privately derived from class B. An object of D in the main function canaccessa) public members of Bb) private members of Dc) protected members of Bd) public members of D

11. The following examples show that the class C is derived from classes A and B.Which one of them is legal?a) class C : private A, public Bb) class C :: private A, public Bc) class C : public A : public Bd) class C: class A, Be) class C: private A, public B;

Page 21: Chapter End Quiz

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 emptyb) Will not compile because the body of B is empty.c) Will not compile because the visibility mode for A is not specifiedd) Will compile successfully

13. Which one of the following statements is FALSE?a) Deriving one class from another requires fundamental changes to the base

classb) If no constructors are declared for the derived class, the objects of the derived

class will use the constructors in the base classc) There may be situations where we may have to define a class which will never

be used to create objectsd) It is legal to make objects of one class as members of another class.

14. 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 ( )

15. Consider the following classclass ABC{

int a;int b;public : constructor function

};We wish to define the constructor function using an initialization list. Which one ofthe 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

Page 22: Chapter End Quiz

CHAPTER 9: POINTERS, VIRTUAL FUNCTIONS AND POLYMORPHISM

1. A pointer isa) the data type of an address variableb) a variable for storing addressesc) a special type of integer variabled) a special type of operator

2. The declaration statementint* p1, p2 ;

a) declares two pointer variables p1 and p2b) declares two integer variables p1 and p2c) declares p1 as a pointer variable and p2 as an integer variabled) is illegal because of blank space between * and p1

3. The statementint * p ;

can be interpreted asa) the variable whose address is stored in p is an integerb) the variable pointed to by p is an integerc) p points to an integerd) All the above

4. For the statementp = *m;

which of the following statements is TRUE?a) The value of m is assigned to pb) The value of the variable pointed to by m is assigned to pc) p is a pointer variabled) Address of m is assigned to p

5. Identy the error in the following code segmentint *ptr, m = 100; // line 1cout << *ptr; //line 2

a) Declaring ptr and m in one line is wrongb) In line 2, *ptr should be written as &ptrc) The address of m should be assigned to ptr before it is accessedd) No error

6. Compile-time polymorphism is accomplished by usinga) function overloadingb) Operator overloadingc) a and bd) neither a nor b

Page 23: Chapter End Quiz

7. The mechanism of using virtual functions to achieve polymorphism is known asa) run-time polymorphismb) dynamic bindingc) late bindingd) 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 followingstatements 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 amember function usinga) x = 100;b) this ->x = 100;c) (*this).x = 100;d) all the above

10. The statementreturn * this ;

inside a member function of a class returnsa) a copy of the object that invoked the functionb) address of the member functionc) address of this pointerd) None of the above

11. Which of the following statements is FALSE?a) Address of a derived class object can be assigned to a base class pointerb) Teating the base class object as a derived class object is wrongc) Address of a base class object can be assigned to a derived class pointerd) A base class pointer cannot be used to access all the members of the derived class

12. In C++, virtual functions are used toa) create functions that can never be accessedb) enable the use of the same function call to invoke functions from different

classesc) to make a base class abstractd) to create an array of base class pointers that can point to different functions

Page 24: Chapter End Quiz

13. Which of the following statements is TRUE about virtual functions?a) A constructor cannot be a virtual functionb) A virtual function in the base class must be defined, eventhough it may not be

usedc) They cannot be declared staticd) All the above

14. A pure virtual function is a virtual function thata) makes the class to be abstractb) is used in derived classesc) is used to transform the base class into a virtual base classd) takes no argument and returns nothing

15. Which of the following statements is TRUE?a) All virtual functions in an abstract base class must be declared as pure virtual

functionsb) A class is made abstract by declaring it virtualc) If a base class declares a pure virtual function, all derived classes must define

the functiond) A derived class cannot contain a pure virtual function

Page 25: Chapter End Quiz

CHAPTER 10: MANAGING CONSOLE I/O OPERATIONS

1. Functions that are necessary for handling formatted input and output operations aredeclared in the classa) iostreamb) iosc) istreamd) ostream

2. Which of the following statements is TRUE?a) The extraction operator >>always skips white space charactersb) The cout stream is normally connected to the display screenc) The function write ( ) outputs an entire line of textd) All the abovee) None of the above

3. Which of the following statements is FALSE?a) The put( ) function can be used to output a line of text using a loop constructb) The get( ) can be used to read a character from keyboard including blank

space and new line characterc) The function getline( ) does not take any argumentsd) A C++ stream is associated with a particular class

4. Which of the following statements is illegal?a) cin.get(‘x’);b) cin.get(x);c) x = cin.get( );d) cout.put(‘x’);

5. 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 abovee) None of the above

6. The ios format function precision ( ) is used to a) specify required field sizeb) specify the number of digits to be displayed after decimal pointc) specify the number of digits to be displayed of an integer numberd) display output in scientific format

Page 26: Chapter End Quiz

7. The statementscout.width(4);cout<< 12 << 34 << “\n”;

will produce the output in the following formata)

b)

c)

d)

e)

8. Which of the following statements is TRUE?a) We need not specify the precision for each item separatelyb) If the specified field width is smaller than the size of the value, C++ expands

the size of field to fit the valuec) When displaying floating point numbers using precision function, the trailing

zeros are truncatedd) When the function width ( ) is used, the text is printed right – justifiede) All the above

9. 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

10. For displaying plus sign and trailing zeros for printing positive floating pointnumbers, we must use the flaga) ios:: showbase onlyb) ios:: showpos onlyc) ios:: showpoint onlyd) both a and be) both b and c

1 2 3 4

1 2 3 4

1 2 3 4

1 2

3 4

1 2

3 4

Page 27: Chapter End Quiz

11. What would be the output of the following code segment?cout.setf(ios:: showpos);cout.precision(2);cout<< 345.609

a) 345.60b) +345.61c) +345.6d) +345.609e) 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) i onlyb) i and iic) i and iiid) iii onlye) ii and iiif) all the three

Page 28: Chapter End Quiz

CHAPTER 11: WORKING WITH FILES

1. All file stream classes are derived froma) filebufb) fstreamc) fstreambased) ios

2. Which of the following classes support simultaneous input and output file operations?a) iostreamb) fstreamc) filebufd) None of the above

3. Which of the following is TRUE?a) We must call close( ) function explicitly to close a file associated with an

fstream objectb) Always sequential files are updated without overwriting any datac) Any existing file can be opened for writing only purposed) Searching all records in a random-access file to locate a record is not

necessary

4. Which of the following is FALSE?a) A file can be opened only using the constructor function of the stream classb) Some streams work with input, and some with outputc) The function open ( ) can be used to open multiple files using one streamd) The open ( ) can take two arguments

5. When reading a file that is connected to the input stream fin of ifstream, we candetect the end-of-file condition usinga) while (fin) statementb) if (fin.eof ( )!= 0) statementc) either of themd) neither of them

6. To open an existing file to add data to the end of the file or to modify the existingdata anywhere in the file, the second argument of open ( ) must bea) ios :: ateb) ios :: appc) ios :: truncd) ios :: noreplace

Page 29: Chapter End Quiz

7. To write floating point data to a file, we must usea) put ( ) functionb) write ( ) functionc) the insertion operatord) seekp ( ) function

8. The statementfile1.write ((char*) &M, sizeof (M));

writesa) the address of M to file1b) the functions of M to file1c) all the members of M to file1d) data in object M to file1

9. Assuming that the length of the file f1 is 100 bytes, what will be the output of thefollowing code segment?

f1.seekg(0, ios::end);f1.seekg(-10, ios::cur);cout << f1.tellg ( );

a) 0b) 100c) 90d) Error; no output

10. Any fatal error occurring during a file operation can be located by using the functiona) fail ( )b) bad ( )c) eof ( )d) good ( )

Page 30: Chapter End Quiz

CHAPTER 12: TEMPLATES

1. A template may be used to create a family ofa) different types of variablesb) classesc) functionsd) classes and functions

2. C++ templates provide support for designinga) modular programmingb) structured programmingc) generic programmingd) top-down programming

3. A class template is designed a) to generate identical objectsb) to work with different data typesc) to generate classes with different functionsd) All of the above

4. Which one of the following is FALSE?a) class templates are sometimes called parameterized classesb) There can be more than one template argumentsc) A template argument is preceded by the keyword classd) Templates automatically create different version of the function at run-time,

depending on user input

5. When we use the concept of templates, when does the program generate actual codefor a template function?a) At the time of invoking the functionb) At the time of declaration of the functionc) When the function definition is maded) When the function is executed at run-time

6. Given below is the definition of a function templatetemplate [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 Tc) Both a and bd) No error

Page 31: Chapter End Quiz

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 templatesb) In class templates with multiple arguments, all the arguments need not be of

class T type argumentsc) Template functions can not be overloadedd) All the above

8. 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);

9. As we know, a macro can be used to create different versions of a function fordifferent data type. What is then the difference between a macro and a classtemplate?a) macros do not perform type checkingb) Macros do not specify the type of the value to be returnedc) Macros are suitable to functions that can written in a single statementd) All the above

10. The following is a list of header lines for creating function templates. Which of themis 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

Page 32: Chapter End Quiz

CHAPTER 13: EXCEPTION HANDLING

1. Exceptions are caused bya) logic errorsb) syntax errorsc) both logic and syntax errorsd) anomalies that a program may encounter during execution

2. Which of the following events could throw an exception?a) Division by zerob) Array subscripts out of boundsc) Shortage of memory space available to satisfy a new requestd) All of the above

3. Exceptions are throwna) from throw statement to try blockb) from throw statement to catch blockc) from catch block to try blockd) from the statement containing error to catch block

4. State which of the following is TRUE.a) Statements that cause an exception must be in a catch blockb) A statement that causes an exception should be in a try blockc) Once an exception is thrown, the control cannot return to the throw pointd) A program cannot continue to operate after an exception has ocurred.

5. The catch blocka) must be placed immediately after the try blockb) must be placed just before the try blockc) must be placed immediately after the statement throwing exceptiond) may be placed anywhere in the program

6. Which of the following are legal throw statements?a) throw ( );b) throw (exception);c) throw exception ;d) throw;e) All of the above

7. When an exception occurs inside a catch block, what happens?a) The exception is caught by the same catch blockb) The exception is caught by the next catch block in the groupc) It will be passed on to the next try / catch sequence for processingd) The execution will terminate

Page 33: Chapter End Quiz

8. The statement catch (…) that can catch all types of exceptiona) can be placed anywhere in the programb) can be placed anywhere in the catch groupc) must always be placed in the beginning of catch groupd) must always be placed in the last in the catch group

9. 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 groupb) is caught by the catch( ) whose argument matches with the type of exception

thrownc) is always caught by catch (…) statement placed at the endd) is caught by the catch statement in the next enclosing try / catch sequence

10. We may restrict the types of exception thrown from a functiona) by placing the try block in the function itselfb) by placing the try block in the main that invokes the functionc) by adding a throw (type-list) to the function definitiond) by adding an empty throw ( ) in the function header line

Page 34: Chapter End Quiz

CHAPTER 14: STANDARD TEMPLATE LIBRARY

1. Majority of template classes and functions contained in STL were originally developedbya) Bjarne stroustrupb) ANSI standards committeec) International standards organization (ISO)d) Alexander Stepanov and Meng Lee

2. To implement STL components in a program, we must includea) using namespace std directiveb) <cstdlib> header filec) <cstdio> header filed) <functional> header file

3. An STL containers can be used to a) compile C++ programs that use template classesb) store objects of any data typec) process data stored in memoryd) None of the above

4. Which one of the following is FALSE?a) An iterator can be handled just like a pointerb) One purpose of an iterator in STL is to connect algorithms and containersc) STL algorithms are member functions of containersd) STL algorithms operate on container elements indirectly using iterators

5. An STL algorithm isa) a friend function of a container classb) a member function a container classc) a standalone function designed to operate on containersd) None of the above

6. Which one of the following is TRUE?a) Algorithms can be used only on STL containersb) An iterator can always move forward or backward through a containerc) The back( ) member function removes the element at the back end of the

containerd) The member function end( ) returns a reference to the last element in the

container

7. Which one of the following is a sequence container?a) dequeb) setc) queued) None of them

Page 35: Chapter End Quiz

8. A vector containera) is a static arrayb) allows insertions and deletions fast at backc) allows insertions anywhere very fastd) does not permit direct access to any element

9. Which one of the following is a non-mutating algorithm?a) unique ( )b) merge ( )c) for_each ( )d) partition ( )

10. Which of the following algorithm is used to replace an element with a specifiedvalue?a) generate ( )b) replace_copy ( )c) remove_copy ( )d) replace ( )

11. In associative containers,a) elements are stored sequentiallyb) keys are used to access elementsc) random access is very fastd) sort ( ) algorithm is used to sort the elements

12. A list containera) permits the use of bidirectional iteratorsb) supports only forward iteratorc) supports only input iteratord) allows random access

13. A map containera) does not allow deletion of any elementb) allows insertion only at the endc) stores pairs of objects (or values)d) associates multiple keys for a given value

14. To use the function objectmodulus < int > ( )

in a program, we must include the header filea) <map>b) <functional>c) <list>d) <algorithm>

Page 36: Chapter End Quiz

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 elementsa) 1, 5, 2, 8b) 1, 5, 3, 7c) 1, 2, 5, 7d) 1, 5, 2, 7e) None of the above

Page 37: Chapter End Quiz

CHAPTER 15: MANIPULATING STRINGS

1. 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

2. 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

3. Identify the error in the following statementfor(int i=1; i<=string1.length( );i++)

cout <<string1.at(i);

a) The second line should have opening and closing braces like {……}b) Initial value for i should be zeroc) The relational operator should be < and not <=d) string1.at(i) should be written as string1.at[i]

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) He123b) Hel123c) Hell123d) H123oe) None of the above

5. Which of the following functions is not supported by the string class?a) capacity ( )b) empty ( )c) assign ( )d) count ( )

Page 38: Chapter End Quiz

6. Which of the following operators cannot be used for string objects?a) [ ]b) &c) + =d) <<

7. Which of the following are TRUE for the statements1.compare(s2);

(i) returns 1, when s1 and s2 are equal(ii) returns 0, when s1 and s2 are equal(iii) returns –1, if s1 < s2(iv) returns –1, if s1 > s2(v) returns 1, if s1 < s2(vi) returns 1, if s1 > s2

a) i, ii and vib) ii, iv and vc) ii, iii and vid) i, iii and vi

8. To access individual characters, we must use the functiona) find ( )b) substr( )c) find_first_of ( )d) at ( )

9. Which of the following is TRUE?a) String objects are null terminatedb) Function end ( ) returns an iterator to the invoking objectsc) Elements of string objects are numbered from 0d) String objects cannot be copied using assignment operator

10. To replace the contents of string s1 with that of s2 and contents of s2 with that of s1,we can use the statementa) s1.swap(s2);b) swap(s1, s2);c) s1.replace(s2)d) replace(s1, s2);

Page 39: Chapter End Quiz

CHAPTER 16: NEW FEATURES ANSI C++ STANDARD

1. One of the new data types introduced by ANSI C++ standard isa) newb) throwc) boold) void

2. Which of the following operators is normally used to change a pointer type object tointeger type objecta) static_cast operatorb) reinterpret_cast operatorc) typeid operatord) const_cast operator

3. 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 + b3cout << y;

What will be the output on executing the above code?a) Error; we cannot assign integer value to a Boolean variableb) 30c) 33d) 32

4. Which of the following operators is used to obtain the type of an object?a) const_castb) typeidc) typedefd) dynamic_cast

Page 40: Chapter End Quiz

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 typesb) Same typesc) Error; we cannot compare types of two objectsd) Error; typeid( ) should be written in the form typeid(object).name( )

6. 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 beimplemented by the main ( ) as given below.

int main ( ){

Test t1 = 35.65;cout << x;

}a. Data member x should be declared publicb. The keyword explicit should be removedc. Both a and bd. No changes required

7. We can modify the value of a data member of an object declared constant bydeclaring it using the keyworda) explicitb) typeidc) typenamed) mutable

Page 41: Chapter End Quiz

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 {…}

9. We use namespaces toa) divide a long program into different modulesb) divide a program into separate filesc) restrict the scope of program elementsd) prevent any modification in data members

10. Given the namespace definitionnamespace S{

int count;}

How can we access the variable count outside the namespace?a) S::count = 10;b) using namespace S; count = 10c) using namespace :: count; count = 10d) All of the above

Page 42: Chapter End Quiz

CHAPTER 17: OBJECT-ORIENTED SYSTEM DEVELOPMENT

1. One of the fmost frequently used second generation development tools isa) Inheritance graphsb) Object dictionaryc) Data dictionaryd) Yourdan charts

2. The classic software development life cycle is usually represented bya) Fountain modelb) Spiral modelc) Unified modeld) Water-fall model

3. The object-oriented approach uses heavilya) structured chartsb) entity relationship chartsc) system flow chartsd) Grid charts

4. The fountain model of software development basically depictsa) overlap and iteration between various stagesb) data flow in a systemc) control logic of functionsd) relationship between different modules of a system

5. The 'is a' relationship can be illustrated bya) classification chartb) hierarchical chartc) composition chartd) inheritance chart

6. The process of one object calling a member of another object may be represented bya) hierarchical relationshipb) composition relationshipc) use relationshipd) inheritance relationship

7. Data flow diagrams are also known asa) process chartsb) bubble chartsc) grid chartsd) flowcharts

Page 43: Chapter End Quiz

8. Objects in a program may correspond toa) procedures for solving problemsb) processes in a real_world problemc) semantics in textual descriptiond) nouns in textual analysis

9. Which of the following types of verbs is likely to be a good candidate forrepresenting a member function?a) Compare verbsb) Being verbsc) Stative verbsd) Having verbs

10. To prepare a class hierarchy, we need to knowa) number of attributes in each classb) number of functions in each classc) common attributes and functions among classd) use relationship

11. A class, in addition to service functions, may also containa) class management functionsb) class access functionsc) class utility functionsd) All the above

12. Which of the following statements is TRUE with regard to design of classes?a) Interaction between two classes must be explicitb) An object of one class should not send any message directly to a member of

another classc) A class should be dependent on as few classes as possibled) None of the abovee) All of the above

13. Which of the following statements is FALSE with regard to design of memberfunctions?

a) Each function either accesses or modifies some data of the class it representsb) All functions must always be declared publicc) They can use top-down functional decomposition techniqued) They can use structured design techniques

14. The main ( ) function module known as the driver programa) cannot receive data values from usersb) cannot display any outputc) creates only objects from class definitionsd) creates objects and establishes communication between them

Page 44: Chapter End Quiz

15. Let a be an object of class and b of class B. A and B have some association betweenthem. Which of the following statements is TRUE?i) Object a can send a message to bii) Object b can do some service to aiii) One class must be a subclass anotheriv) One object must be a member of another object

a) i and iib) iii and ivc) All the fourd) None of the four