0% found this document useful (0 votes)
31 views

Object Oriented Programming - Nabia Khalid

Uploaded by

lordcam776
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Object Oriented Programming - Nabia Khalid

Uploaded by

lordcam776
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Bahria University, Islamabad Campus

Department of Computer Science


Final Term Examination
Class/Section: BS (IT)-2A &2B
(Fall 2023 Semester)
Paper Type: Descriptive
Course: Object Oriented Programming Date: 13/Jan/2024
Course Code: CSC-210 Session: I
Faculty’s Name: Ms. Nabia Khalid Max Marks: 50
Time Allowed: 2.5 hours Total Pages: 4 (including this)
_________________________________________________________________________
INSTRUCTIONS:
I. All questions are compulsory.
II. There are FIVE questions in total.
III. The paper is closed book.
IV. Solve the paper on Answer sheet.
V. The students are not allowed any helping material (books, tables, formulas, etc.).
VI. Use blue, black or blue-black ink only. Do not use lead pencil especially.

Student’s Name: _____________________________Enroll No: ______________________


(USE CAPITAL LETTERS) (FULL ENROLLMENT)

Class and Section: ____________________________

Student Sign: ---------------------- Invigilator’s Sign:


--------------

Total Questions Q1 Q2 Q3 Q4 Q5 Total

Marks 14 10 12 6 8 50
Assigned

Marks
Obtained

Page 1 of 4
Enrollment Number: ____________________________

Question # 1 (4+10=14 Marks )


(CLO-1)

a. Recall the inheritance concept and suppose you have an inheritance hierarchy with a
base class Animal and two derived classes Bird and Snake. Based on the
characteristics of animals in general and birds and snakes specifically, can you think
of possible virtual and pure virtual functions to place in Animal? Justify your answer.
b. Complete the following tasks:
1. Create a class named Teacher that holds a Teacher’s first and last names and the grade
level the Teacher teaches. Include a constructor function that uses default first and last
names, such as “ZZZZZZZ” and a default grade level, such as 0, when no arguments
are provided.
2. Create a class named Student that holds a Student’s first and last names. Include a
constructor function that uses default first and last names, such as “ZZZZZZZ,” when
no names are provided. Create a class named Classroom. A Classroom holds a Teacher
and an array of 35 Student objects.
3. Create a class named School. A School contains an array of 100 Classroom objects.
4. In a main () demonstration function, declare a pointer to an array of 500 School objects
and include code to handle any memory allocation errors that occur. In a loop, declare 500
array objects at a time, continuing to rewrite the main () function if necessary until you
create enough School objects to cause a memory allocation exception.
(Hint: You might want to display a count periodically to assure yourself that the
School objects are being created.)
When memory is exhausted, display an appropriate message and terminate the application.

Question # 2 (3+3+4=10 Marks )


(CLO-2)
class TestScore
{
private:
string studentName;
int studentScore;
public:
TestScore(string name, int score);
string GetName() const;
int GetScore() const;

};

Given the above declaration for a TestScore class, do the following tasks:

1. Write the implementation for the TestScore class. The constructor just assigns its
parameters to the private data members, and the observers simply return the
corresponding member.
2. Write a derived class declaration called IDScore that adds an integer student ID
number as a private member, and that supplies (a) a constructor whose parameters
correspond to the three member fields, and (b) an observer that returns the ID number.
3. Write the implementation for a class called Exam that uses composition to create an
array of 100 objects of class IDScore. The class can use the default constructor, and it
will have a function that assigns an IDScore object to a location in the array, given

Page 2 of 4
Enrollment Number: ____________________________

the object and the location as parameters. The class should also have an observer that
returns the IDScore object at the position specified by its parameter.

Question # 3 (8+4 Marks)


(CLO-3)

a. Create a class template for a class that holds an object and the number of data
elements in the object. For example, if an Employee class has two data elements, an
ID number and a salary, then the class template holds the number 2 and an Employee
object; if a Student class contains 12 data elements, then the class template holds 12
and a Student. Code a standard input function for the object that displays a message
on the screen—“You will be asked to enter X items”—where X is the number of data
elements. Write a main () function that tests your template class with an integer and
two programmer designed classes.

b. Write a program that allows a user to use the keyboard to input the first and last
names of 40 friends, up to 50 characters each. Display the names 15 at a time, pausing
to let the user press a key before the list continues.

Question # 4 (3+3=6 Marks)


(CLO-3)
Create/Design an Item class that contains fields for a stock number, price, and quantity in
stock, and functions to set and display each field. Write a program that declares an array of
10 Item objects. Write a main function and display all the data in report form—that is,
aligned correctly in columns.

Question # 5 (8 Marks)
(CLO-2)
Given the following declaration for a class that represents a computer in a company’s
inventory, extend a derived class declaration (for a class called InstallRecord) that adds (1)
a string field representing the location of the computer and (2) a field of class SimpleDate
that holds the installation date. The new class should provide observers for each of the new
fields. It should also re implement the Write function.
class Computer
{
public:
Computer (string newName, string newBrand, string newModel, int newSpeed, string
newSerial, int newNumber);
string GetName() const;
string GetBrand() const;
string GeModel() const;
int GetSpeed() const;
string GetSerial() const;
int GetNumber() const;
void Write() const;
private:
string name;
string brand;
int speed;
string model;
string serialNumber;
int inventoryNumbr;
Page 3 of 4
Enrollment Number: ____________________________

};

1. Implement the constructors for the Computer and InstallRecord class.


2. Implement the Write function for the Computer class. It should output each member
field on a separate line.
3. Implement the Write function for the InstallRecord class. It should output each
member field on a separate line. Assume that the SimpleDate class should provide a
void function called Write() that outputs the date in a standard format.

Best of Luck

Page 4 of 4

You might also like