0% found this document useful (0 votes)
2 views5 pages

OOP Model Paper

This document is a model examination paper for a university course on Object Oriented Programming (OOP) in C++. It includes multiple choice questions, fill in the blanks, short conceptual questions, and long programming tasks related to C++. The total marks for the exam are 50, and students are instructed to attempt all questions within a time limit of 2 hours.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

OOP Model Paper

This document is a model examination paper for a university course on Object Oriented Programming (OOP) in C++. It includes multiple choice questions, fill in the blanks, short conceptual questions, and long programming tasks related to C++. The total marks for the exam are 50, and students are instructed to attempt all questions within a time limit of 2 hours.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIVERSITY MODEL EXAMINATION PAPER

Subject: Object Oriented Programming (OOP) in C++


Semester: 2nd | Time Allowed: 2 Hours | Total Marks: 50

Student Name: _______________________________ Roll No: _______________ Date: _______________

Instructions: Attempt ALL questions. Write clearly. Each section has its own marks.

SECTION A — Multiple Choice Questions (MCQs) Marks: 5


Circle the correct answer for each question. (1 mark each)

1. Which of the following is the correct syntax to declare a class in C++?

(a) class MyClass { }; (b) MyClass class { };


(c) declare class MyClass { }; (d) object MyClass { };

2. What happens when a constructor has no parameters?

(a) It is called a Parameterized Constructor (b) It is called a Copy Constructor


(c) It is called a Default Constructor (d) It cannot be defined

3. In C++, which access specifier allows a member to be accessed by child class but NOT from
outside?

(a) public (b) private


(c) protected (d) internal

4. What is the correct symbol for a destructor?

(a) !ClassName() (b) ~ClassName()


(c) -ClassName() (d) *ClassName()

5. Which OOP pillar is achieved when you make data private and provide public getter/setter
functions?

(a) Inheritance (b) Polymorphism


(c) Abstraction (d) Encapsulation

SECTION B — Fill in the Blanks Marks: 5


Fill in each blank with the correct word or term. (1 mark each)

1. A constructor that takes no parameters is called a __________________ constructor.

2. The access specifier that allows access only within the class itself is called __________________.

3. In inheritance, the class that inherits properties from another class is called the
__________________ class.

4. A pure virtual function is declared using the syntax: virtual void funcName() =
__________________.
5. The destructor of a class named 'Student' is written as __________________.

SECTION C — Short Conceptual Questions Marks: 18


Answer each question briefly and conceptually. (3 marks each)

Q1. What is the difference between a class and an object? A student says 'class and object are the
same thing.' Do you agree? Justify your answer with a real life example.

(3 marks)

Q2. Explain the difference between pass by value and pass by reference. If you want to swap two
numbers using a function, which method will you use and WHY? What happens if you use the wrong
method?

(3 marks)

Q3. What is Encapsulation? A programmer makes all data members public in a class. What problems
can this cause? How does making data private with getter/setter functions solve this problem?

(3 marks)

Q4. Explain the difference between Default Constructor and Parameterized Constructor. Why does a
constructor have NO return type — not even void? What would happen if you tried to call a
constructor manually?

(3 marks)

Q5. What is Inheritance in OOP? Can a child class access private members of its parent class? What
keyword do you use to allow child class access but block outside access? Why is inheritance useful
— what problem does it solve?

(3 marks)

Q6. What is the difference between Encapsulation and Abstraction? A student says 'both are the
same — they both hide things.' Correct the student with a proper explanation and one example for
each.

(3 marks)

SECTION D — Long Questions (Programs) Marks: 22


Write complete C++ programs for each question. (marks as indicated)

Q1. (7 marks)

Write a complete C++ program for a BankAccount class with the following specifications:

• Private data members: accountHolder (string), balance (double), pin (int)


• A parameterized constructor to initialize all three members
• A deposit(double amount) function — add to balance if amount > 0, else print 'Invalid amount'
• A withdraw(int enteredPin, double amount) function — check pin first, then check balance
• A display() function showing account holder name and current balance
• Create 2 BankAccount objects in main and demonstrate all functions

Q2. (8 marks)

Write a complete C++ program demonstrating Inheritance with the following specifications:

• A parent class Animal with: name (string), age (int), eat() and sleep() functions
• A child class Dog inheriting Animal with: breed (string) and bark() function
• A child class Cat inheriting Animal with: color (string) and meow() function
• In main: create one Dog and one Cat object, set all values, and call all functions
• Show that child objects can use both parent functions AND their own functions

Q3. (7 marks)

Study the following code carefully and answer the questions below:

#include<iostream>
#include<string>
using namespace std;

class Student {
private:
string name;
int marks;

public:
Student() {
name = "Unknown";
marks = 0;
}

Student(string n, int m) {
name = n;
marks = m;
}

Student(Student &s) {
name = [Link];
marks = [Link];
}

void setMarks(int m) {
if (m >= 0 && m <= 100)
marks = m;
else
cout << "Invalid marks!" << endl;
}

int getMarks() { return marks; }

void display() {
cout << "Name: " << name << endl;
cout << "Marks: " << marks << endl;
}

~Student() {
cout << name << " object destroyed!" << endl;
}
};

int main() {
Student s1;
Student s2("Ali", 85);
Student s3(s2);

[Link]();
[Link]();
[Link]();

[Link](150);
[Link](95);
[Link]();
return 0;
}
Answer the following questions about the code above:

(a) [1 mark] What will be the output of [Link]()? Why?

(b) [1 mark] What will be the output of [Link]()? Which constructor was called for s3?

(c) [2 marks] What will happen when [Link](150) is called? What will [Link]() show after
[Link](95)?

(d) [1 mark] How many constructors does this class have? Name each one.

(e) [2 marks] What will be printed when the program ends (after return 0)? In what order will
destructors be called and why?

*** END OF PAPER — Good Luck! ***


Section A — MCQs B — Fill Blanks C — Short Qs D — Programs TOTAL
Max Marks 5 5 18 22 50
Obtained

You might also like