MCQ-Prog2-CS211-100 Past Paper PDF

Summary

This document is a programming past paper, specifically focusing on programming concepts and questions. The paper includes multiple choice questions (MCQs) focusing on different aspects of programming, including data structures, functions, and object-oriented programming (OOP) principles in C++.

Full Transcript

Programming2 -CS211 1.The array can be described as? A. Data structure *B. A container having similar values C. Not a data structure D. None of these 2.Advantage of an array is? A. Stores Element B. index of the element is 1 *C. Stores many elements with the same data type D. None of these 3. Inde...

Programming2 -CS211 1.The array can be described as? A. Data structure *B. A container having similar values C. Not a data structure D. None of these 2.Advantage of an array is? A. Stores Element B. index of the element is 1 *C. Stores many elements with the same data type D. None of these 3. Index of an array starts with? A. 1 B. 2 C. 3 *D. 0 4. Data types of the array include? A. int B. float C. char, double, struct *D. All of these 5. The function called to passed the entire array? *A. Call by reference B. Call by value C. Both A and B D. None of these 6. What do we use to access the seven-element of an array? *A. arr B. arr C. Both A and B D. arr{7} 7. What is the index of the last element having 9 elements? A. 7 B. 9 *C. 8 D. 0 Answer: C 1 8. What is the scope of the variable declared in the user defined function? A. Whole program *B. Only inside the {} block C. The main function D. None of the above 9. Where does the execution of the program starts? A. User-defined function *B. Main function C. Void function D. None of the above 10. A friend function does not have 'this' pointer associated with it. *A. TRUE B. FALSE C. May Be D. Can't Say 11. which of the following is used to terminate the function declaration? a) : b) ) *c) ; d) ] 12. What is an inline function? *a) A function that is expanded at each call during execution b) A function that is called during compile time c) A function that is not checked for syntax errors d) A function that is not checked for semantic analysis 13. Which of the following features must be supported by any programming language to become a pure object-oriented programming language? a. Encapsulation b. Inheritance c. Polymorphism d. All of the above 2 14. Which of the following comment syntax is correct to create a single-line comment in the C++ program? *a.//Comment b./Comment/ c.Comment// d.None of the above 15. Which of the following is the correct syntax for printing the address of the first element? *a.array; b.array; c.array; d.None of the above 16.Which of the following can be considered as the object of an array? a.Index of an array *b.Elements of the Array c.Functions of the Array d.All of the above 17. Which of the following statement is correct about the C++ programming language? *a.In C++, both the Static and Dynamic type checking are allowed b.In C++, member function are allowed to be of the type canst c.In C++, Dynamic checking is allowed d.None of the above 3 18. Which of the following statements is true about the C++ programming language? a.C++ is an object-oriented programming language b.C++ is a procedural programming language c.C++ is a functional programming language *d.C++ is both procedural and object-oriented language 19. What does your class can hold? a) data b) functions *c) both a & b d) none of the mentioned 20. How many specifiers are present in access specifiers in class? a) 1 b) 2 *c) 3 d) 4 21, Which is used to define the member of a class externally? a) : *b) :: c) # d) none of the mentioned 22. Which of the following is a valid class declaration? *a) class A { int x; }; b) class B { } c) public class A { } d) object A { int x; }; 23. The fields in the class in c++ program are by default a) protected *b) private c) public d) none of the mentioned 24. Constructors are used to 4 *a) initalize the objects b) construct the data members c) both a & b d) none of the mentioned 25. Which of these following members are not accessed by using direct member access operator? a) public b) private c) protected *d) Both b & c 26. Pick out the other definition of objects. a) member of the class b) associate of the class c) attribute of the class *d) instance of the class 27. How many objects can present in a single class? a) 1 b) 2 c) 3 *d) as many as possible 28. Which special character is used to mark the end of class? *a) ; b) : c) # d) $ 29. Which rule will not affect the friend function? *a) private and protected members of a class cannot be accessed from outside b) private and protected member can be accessed anywhere c) both a & b d) None of the mentioned 30. Which keyword is used to declare the friend function? a) firend *b) friend c) classfriend d) myfriend 5 31. Pick out the correct statement. a) A friend function may be a member of another class. b) A friend function may not be a member of another class. *c) A friend function may or may not be a member of another class. d) None of the mentioned 32. Where does keyword ‘friend’ should be placed? *a) function declaration b) function definition c) main function d) None of the mentioned 33. What is class in c++ ? *a) When you define a class, you define a blueprint for a data type. b) When you define a class, you make get more funtionality. c) When you define a class, you define the logic. d) When you define a class, you make debugging. 34. What is object in C++ ? a) Object is part of syntax of a class. b) Object is datatype of a class. *c) Object is an instance of a class. d) Object is function of a class. 35. What is default visibility mode for members of classes in C++ ? *a) Private b) Public c) Protected d) Depends 36. What is true about Constructor ? a) Its name is plural of class name. b) Its name has * symbol before it. *c) Its name is same as of class name. d) Its name has # symbol before it. 37. What is actual syntax of destructor in c++ ? a) !Classname( ) b) @Classname( ) c) $Classname( ) *d) ~Classname( ) 6 38. ------------------ is/are a special method that’s called automatically each time an object is declared. a. A destructor function *b. A constructor function c. A constructor destructor functions d.A public functions 39. A static class variable can share the same storage space for all a. class objects b. class functions c. class variables and functions d. class space 40. A class named Time that has integer data members named secs, mins, and hours can be defined by: a. Class Time { int hours , mins, secs }. b. class Time { private : int hours ; mins ; secs ; }; *c. class Time { int hours , mins, secs ; }; d.All above 41.. Construct a class named Rectangle that has double-precision data members named length and width. a. Class Rectangle { int length width }. b. class Rectangle { private : int length width; }; c. class Rectangle { private : double length , width; }; d. class Rectangle { double length ; double area; }; 42. The default constructor of class Time which uses default values of 0 for each data member. a) Time::Time(int=0, int=0, int=0) ; b) Time(int=0, int=0, int=0) ; c) Time::Time() { hrs=0 ; min=0 ; sec=0; } d) Time::Time(hrs=0, min=0, sec=0) ; 43.. Construct a class named Student consisting of an integer student ID number, an array of three double-precision grades? a. Class Student { int ID , array 3 grades ;}; b. Class Student { int ID , double 3 grades ;}; c. Class Student { int ID , double grades=3 ; }; d. Class Student { int ID , double grades; }; 44. The constructor for Student class should initialize all Student data members to 0. a. Student:: Student { ID=0 ; grades=0;} b. Student:: Student( ) { ID=0 ; grades=0;} c. Student:: Student ( ) { ID=0 ; grades=grades=grades=0;} d. Student:: Student ( ID=0 , grades=grades=grades=0;) ; Ans. c 7 45 Construct a class named Circle containing two integer variables named xCenter and yCenter and a double- precision variable named radius. Additionally, the class should contain a static integer data member named scaleFactor. a. Class Circle { int xCenter , yCenter; double radius; int scaleFactor }; b. Class Circle { int xCenter and yCenter; double radius; int static scaleFactor }; c. Class Circle { int xCenter , yCenter; double radius; static scaleFactor }; d. Class Circle { int xCenter , yCenter; double radius; static int scaleFactor }; Ans. d 46. A nonmember function can access a class’s private data members if it’s granted by the class. *a)Friend function a) Private function b) Public function c) Both b and c 47. A member function can access a class’s private data members class. a) Friend function b) Private function c) Public function *d)Both b and c 48. A constructor that accepts no parameters is called the ………………. a) Paramless constructor b) No parameter constructor *c) Default constructor d) Argumentless constructor 49. Which of the following characteristics of constructor are true. a) They should be declared in the public section. b) They are invoked automatically when the objects are created. c) They do not have return type and void also. d) All of above. 50. Which of the following is a valid destructor of the class name “ Country” a. int ~ Country() b. void Country() c. int ~ Country( Country obj) *d. ~Country() 51. The default access level assigned to members of a class is *a. Private b. Public c. Protected d. needs to be assigned 8 52. Which Operator can access on public member of object a. :: b. -> *c.. c. & 53. Which Operator can access on public member of pointer object a. :: *b. -> b.. c. & 55. In above example the following statement will call which constructor int main() { Example obj(1,2,3) ; } a. Constructor 2 *b. Constructor 4 b. Constructor 1 c. Type Error mismatch 56. Every elements in an array is associated with a unique subscript value starting from: a. 0 to size b. 0 to size +1 *c. o to size -1 d. None of these 57. To declare array of object of size five of class Time a. Time *t; *b. Time t; c. Time t{5}; d. Time t(5) ; 58.. C++ provides facility to specify that the compiler should match function calls with the correct definition at the run time. This process is called as a. Static binding b. Run time binding *c. Dynamic Binding d. None of the above 59. Which allows you to create a derived class that inherits properties from more than one base class? A. Multilevel inheritance *B. Multiple inheritance C. Hybrid Inheritance D. Hierarchical Inheritance 52. Which feature in OOP allows reusing code? A) Polymorphism *B) Inheritance C) Encapsulation D) Data hiding 9 53. The function whose prototype is void getData(Item *thing); receives *a) a pointer to a structure b) a reference to a structure c) a copy of a structure d) nothing 54. What is the implicit pointer that is passed as the first argument for nonstatic member functions? a. ‘self’ pointer b. std::auto_ptr pointer c. ‘Myself’ pointer *d)‘this’ pointer 56. Which of the following is/are false a) Inheritance is deriving new class from existing class *b) In an inheritance, all data and function members of base class are derived by derived class c) We can specify which data and function members of base class will be inherited by derived class d) We can add new functions to derived class without recompiling the base class 57. A base class will offer a) offer more specific objects than its derived classes b) correspond to something in the rest world c) behave badly when the chops are down *d) be a generalized version of its derived classes 58. What is meant by multiple inheritance? a) Deriving a base class from derived class b) Deriving a derived class from base class *c) Deriving a derived class from more than one base class d) None of the mentioned 59. Which symbol is used to create multiple inheritance? a) Dot *b) Comma c) Dollar d) None of the mentioned 60. In C++..................... operator is used for Dynamic memory allocation. a) Scope resolution b) Conditional *c) New d) Membership access 61. Which of the following keywords are used to control access to a class member? a) default b) break *c) protected 10 d) goto 62. The major goal of inheritance in C++ is a) To facilitate the conversion of data types b) To help modular programming *c) To facilitate the reusability of code d) To extend the capabilities of a class 63. What is default visibility mode for members of classes in C++ ? *a) Private b) Public c) Protected d) Depends 64. Reference is like a *a) Pointer b) Structure c) Array d) None of above 64. What is polymorphism *a) Ability to take more than one form b) Ability to destroy destructor c) Ability to create constructor d)None of above 65. Which of the following cannot be inherited from the base class a) Constructor b) Friend *c) Both A and B cannot be inherited d) Both A and B can be inherited 66.What is the meaning of base class in C++ *a) Another class got inherit from this class b) It inherit other class c) It has a pointer variable d)It is the first class declared 67.. What is inheritance? *a) Inheritance allows one class to reuse the state and behavior of another class. b) It deals with dangling pointers c) It deals with void pointers d) It is type of class declaration 68. The process of deriving a class from another derived class is known as ? a) single inheritance 11 b) dual inheritance c) multiple inheritance *d) multilevel inheritance 69. When a derived class inherits from many base classes, this process is known as ? *a) multiple inheritance b) multilevel inheritance c) default inheritance d)multiplex inheritance 70. Inheritance is a way to a) pass arguments and improve data hiding b) pass arguments and add features to existing classes without rewriting them *C. make general classes into more specific classes and add features to existing classes without rewriting them D. improve data hiding and encapsulation. 71. Which is not a protection level provided by classes in C++? a) protected *b) hidden c) private d)public 72. The process of building new classes from existing one is called ______. a) Polymorphism b) Structure *c)Inheritance d) Cascading 73. Which of the following concepts means determining at runtime what method to invoke? a) Data hiding b) Dynamic Typing *c) Dynamic binding d. Dynamic loading 74. Multilevel inheritance comprises of how many levels? a) Only two *b) Two or more c) More than three d) None of the above 75. A _______ access specifier is needed only when inheritance is involved. a) public. b) private. *c) protected. d) automatic. 76. Which special pointer contains the address of an object of a class currently calling the member function of the class? *a) This pointer 12 b) char (ename) c) class_name *pointer_name[size]; d) None of the above 77. __________are one of the attributes of C++ that support run-time polymorphism. a) Pointers b) Derived classes * c) Virtual functions d) Heap tree 78. A ________ function has access to all private and protected members of the class for which it is a __________. *A. friend. B. member. C. nonmember. D. void. 79. Creating a new class using one or more existing classes is known as ____. A. Polymorphism B. Encapsulation C. overloading *D. inheritance 80. Ability of an operator or function call to take different forms is known as ____. *A. Polymorphism B. Encapsulation C. overloading D. inheritance 81. A function that changes the state of the cout object is called a(n) _____ A. member B. adjuster *C. manipulator D. operator 82. What does C++ append to the end of a string literal constant? a) a space b) a number sign (#) c) an asterisk (*) *d) a null character 83. ________________ Provides methods for declaring, creating, and initializing a string a) the this class. *b) the string class. c) the C++ class. d) the null class. 84. _____________ is any sequence of characters enclosed in quotation marks. a) constant literal. b) public specifier. 13 *c) string literal. d) all of the mentioned. 85. quotation marks identify __________________. a) the beginning a string. b) the end of a string. *c) a and b. d) none of the mentioned. 86. ________________ are not stored with string. a) numbers. b) characters. *c) quotation marks. d) special characters. 87. cin is a general-purpose terminal input that stops reading when a ____________ is encountered. a) digit. b) comma. *c) whitespace. d) colon. 88. getline(cin, strObj): general-purpose terminal input that inputs all characters entered into the string named strObj and stops accepting characters when it receives ___________________. a) digit. b) comma. c) colon. *d) a newline character (\n). 89. Unexpected results occur when: a) cout output stream and getline() method are used together to output data. b) cin input stream and cout output stream are used together. *c) cin input stream and getline() method are used together to accept data. d) all of the mentioned. 90. Solutions to the “phantom” Enter key problem: a) do not mix cin with getline() inputs in the same program. b) follow the cin input with the call to cin.ignore(). c) accept the Enter key into a character variable and then ignore it. *d) all of the mentioned. 91. Preferred solution for the “phantom” Enter key problem is: *a) do not mix cin with getline() inputs in the same program. b) follow the cin input with the call to cin.ignore(). c) accept the Enter key into a character variable and then ignore it. d) none of the mentioned. 92. Most commonly used string class method is ______________ which returns the number of characters in the string. 14 a) compare() method. *b) length() method. c) find() method. d) swap() method. 93. Most commonly used string class method is ______________ which returns the number of characters in the string. a) compare() method. b) find() method. c) swap() method. *d) none of the mentioned. 94. When comparing methods, "Hello" is _______________ "Good Bye". a) less than. *b) greater than. c) equal. d) all of the mentioned. 95. When comparing methods, "Hello" is _______________ "hello". a) less than. b) greater than. *c) equal. d) all of the mentioned. 96. To prevent the Enter key from being accepted as a legitimate character input when the getline() method is used, you can use the following ways: a) follow the cin.get() input with the call cin.ignore(). b) accept the Enter key in a character variable, and then don’t use it again. *c) a and b. d) none of the mentioned. 97. To prevent the Enter key from being accepted as a legitimate character input when the getline() method is used, you can use the following ways: a) follow the cin.get() input with the cout output stream. *b) accept the Enter key in a character variable, and then don’t use it again. c) a and b. d) none of the mentioned. 98. To prevent the Enter key from being accepted as a legitimate character input when the getline() method is used, you can use the following ways: *a) follow the cin.get() input with the call cin.ignore(). b) accept the Enter key in a character variable. c) a and b. d) none of the mentioned. 99. which is used to handle exceptions in C++? a) catch handler. b) operator handler. *c) exception handler. d) none of the mentioned. 15 100. The function ______________ can be used to check that an entered string complies with these conditions. a) compare() method. b) find() method. c) swap() method. *d) none of the mentioned. 16

Use Quizgecko on...
Browser
Browser