OOP Theory Mid Part 1 Objective Sol

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Air University

Mid Term Examination, Spring 2022


Subject: Object-Oriented Programming Class: BSCS-II- (A,B,C), BSIT-II-A
Course code: CS-112 Total Marks: 24
FM name: Dr. Abdul Hameed, Dr. Ashfaq Time Allowed: 30mins
Mr. Usman, Mr. Sagheer Date: April 01, 2022
Time: 08:30-10:30 AM
Student Name: _____________________________ Reg. No. _______________________

Instructions:
 Part-1 is objective and time allowed is 30 minutes. Part-1 should be solved on question
paper. Write name & roll no on the question paper.
 Paper is closed book & closed notes. Part-1 must be returned before attempting Part-II.
 Students can get Part-2 earlier if Part-1 is returned.
 Cutting/Correction is not allowed in this section. Corrections will be marked zero.

Part- I (Objective)

Question 1 CLO 1 & 2 Marks: 24

Encircle the correct option/s.

1. Assume the following code 2. Assume the following code,

#include <iostream> struct Rectangle {


int length;
#include <string>
int width;
using namespace std;
};
struct names Rectangle *r = nullptr;
{ string first; r = new Rectangle;
string last;
}; Which of the following statements correctly assign 20 to
int main () length member and 16 to width member r?
{
names customer = "Smith", "Orley"; a) r.length = 20; r.width = 16;
cout << names.first << endl; b) r->length = 20; r.width = 16;
cout << names.last << endl; c) r.length = 20; r->width = 16;
return 0; d) None of above
}

What is the issue with the above code? 3. Which of the following are fundamental principles of
a) All members of the structure must be of the same object-oriented programming?
type
b) The structure name/tag is missing a) Encapsulation b) Inheritance
c) The initialization list for the customer variable c) Polymorphism d) Templates
must be enclosed in braces.
d) Missing semi-colon after structure declaration

Page 1 of 2
4. Which of the following oop feature provides reusability 5. Classes in C++ are________?
of code?
a) derived data types b) User defined data types
a) Abstraction b) Inheritance c) built-in data types d) All of these
c) Dynamic binding d) Encapsulation

6. Which of the following statement is correct about the 7. What must be done for hiding member data of a class?
constructors and destructors?
a) The member function must be declared as private in the
a) Destructors can take arguments but constructors cannot. class
b) Constructors can take arguments but destructors b) The member data must be declared as private in the
class
cannot. c) The member function must be declared as public in the
c) Constructors can return a value. class
d) The member data must be declared as public in the
d) None of them. class

8. Consider Car as an entity. Which of the following could 9. Suppose a class named Car whose specifications are
be considered as the member variables of the Car class? stored separately from its implementation. Which of the
following can be the implementation of a member
a) Name of car function of the Car? (…. in the body of function
b) The Engine Switch On/off operation indicate the code is omitted)
c) The gear change operation
d) The price of the car a) void Speed-UP(int sp);
e) The Speed-up operation b) void Speed-UP(int sp){ …};
c) void Car::Speed-UP(int sp){ …};
d) void car(int so){ …}

10. Find the error from the following code. 11. When the definition of the member function is written
inside the class definition, then that function becomes
class Time {
private: a) the private function of that class
int hour = 0;
int minute = 0; b) the inline function of that class
int second = 0; c) Not inline function of that class
public:
void Time( ); d) None of them
void set_values(int, int, int);
void display( );
}; 12. Which among the following member variables are
accessible inside a static member function of a class?
a) Definition of class member functions should be
written inside class definition.
a) Private data members
b) Constructor is not allowed to return value. b) Private Static data members
c) Destructor is missing c) Public data member
d) Public Static data members
d) Both (a) and (b)
e) All of the above
e) Both (a) and (c)

Page 2 of 2

You might also like