UNIVERSITY OF THE PUNJAB
BS. 4 Years Program: Third Semester - Spring 2024
Course Code: CC-211 Paper: Object Oriented Programming
Roll No.: ___________________ Time: 3 Hours Marks: ________
Q.1. Answer the following short questions
1. Consider the following code. Suppose we have the objects as:
Base b; and derived d; Which of the following statements are
incorrect or generates the error?
Answer:
The constructor in Base is
public, so it can be called
without error. Therefore, no
error occurs due to constructor
visibility.
2. Suppose address of OOP is 0804 and address of this is 08D4 .
What will be the output of the following?
Program: Output: yours might be different.
In
this case, *this refers to the actual object itself.
So, when you write cout << *this;, it tries to print the memory address of the object, not the
values of its properties, and it will show the raw memory information instead of something
readable.
3. What will be the output of the following?
OUTPUT:313
4. Consider the following code. Can we access base2()
using sptr pointer ?
Answer:No, we cannot access the base2() function using the sptr pointer in your code,
because base2 declared as protected can only be accessed within the class itself, its derived
classes, and friends of the class. But it is not accessible from outside the class hierarchy
such as in the main() function, or through a pointer to Successor like sptr.
5.Does the following code has any error? If yes then
pls specify the lines that have error.
This isn’t any
error in this
program. Output
will be
Function of Child
Class
6. What will be the output of the following code ?
OUTPUT:
Explanation:
r is a pointer of type Vehicle*, which points to an object of type Bus. The
Vehicle class does not have a method called getAddressBus(), so trying
to call it via r will result in a compilation error because the compiler will
only look at the base class (Vehicle) to find the method, and
getAddressBus() is not defined in Vehicle.
PART B [15 Marks]
a) Consider that you have designed a new music application, let's call it OOPMIP, short for
OOP Music Player. OOPMIP will have a playlist in which songs can be added or removed.
Each song will have lyrics and a name. (As we cannot store audio for the lyrics, let's assume
that the lyrics are represented as a string or char*.)
Songs will have the following types:
1. MP3: This is an audio song containing only lyrics. Each MP3 song will also have a
genre (for example, pop, rock, classical, etc.).
2. MP4: This is a video song containing both lyrics and a video. (Since we cannot store
video, we will assume the video is represented as a char* or string containing a
description of the scenes.)
3. sMP4 (short for secret MP4): This type of song contains both audio and video. It is
called a "secret MP4" because only the OOP Music Player can play the real lyrics and
video. If anyone else tries to play it, they will only hear a bleep as the lyrics and see
glitches as the video.
Design and implement your classes based on the above specifications. You do not need to
define main() functions.
Create a JobExpectation class with the following attributes:
A Job object (which is an object of the Job class).
An error message (string).
Create a Job class with the following attributes:
Job_ID (an identifier for the job).
fee (the fee for the job).
You must implement the following functions:
1. Overload the insertion (<<) and extraction (>>) operators for the Job class.
2. In the insertion operator (>>), validate the input. If the job fee is below $250, create a
JobExpectation object and throw it.
Write a main() function that declares an array of eight Job objects. If a JobExpectation
object is thrown during the data entry for any job, prompt the user to enter a new job and
replace the invalid job.
PART A
Student Record Management System