0% found this document useful (0 votes)
63 views4 pages

OOP - MID I - Spring 2020 - Solution

This document contains instructions and questions for a midterm exam in an Object Oriented Programming course. It includes: 1) Instructions to not write anything except the student's roll number and section, and to return the question paper. 2) Three multiple choice and short answer questions about OOP concepts like pointers, copy constructors, static member functions, and class relationships. 3) A scenario describing an university system with classes for campuses, faculties, programs, courses, students, and results, asking students to identify classes and attributes. The time allowed for the exam is 60 minutes and it is out of a total of 30 points. Good luck is wished to students at the end.

Uploaded by

Abdullah Zain
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)
63 views4 pages

OOP - MID I - Spring 2020 - Solution

This document contains instructions and questions for a midterm exam in an Object Oriented Programming course. It includes: 1) Instructions to not write anything except the student's roll number and section, and to return the question paper. 2) Three multiple choice and short answer questions about OOP concepts like pointers, copy constructors, static member functions, and class relationships. 3) A scenario describing an university system with classes for campuses, faculties, programs, courses, students, and results, asking students to identify classes and attributes. The time allowed for the exam is 60 minutes and it is out of a total of 30 points. Good luck is wished to students at the end.

Uploaded by

Abdullah Zain
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
You are on page 1/ 4

FAST- National University of Computer & Emerging Sciences, Karachi.

Department of Computer Science,


Mid Term I Examination, Spring 2020
24th February, 2020, 11:00 pm – 12:00 noon

Course Code: CS-217 Course Name: Object Oriented Programming


Instructors: Dr. Abdul Aziz, Muhammad Danish Khan, Syed Zain-ul-Hassan, and Basit Ali
Student’s Roll No: Section:

Instructions:

 Except your Roll No and Section, DO NOT WRITE anything on this paper.
 Return the question paper with your answer sheet.
 Read each question completely before answering it. There are 3 questions on 2 pages.
 In case of any ambiguity, you may make assumption but your assumption must not contradict any statement in the
question paper.
 All the answers must be solved according to the SEQUENCE given in the question paper, otherwise points will be
deducted.

Time Allowed: 60 minutes Maximum Points: 30


=================================================================================================

Q No. 1 Provide brief answers to the following questions: [2 x 5 = 10 Points]


a. What will be the behavior of the following pointer when declared this way:
int * const ptr = &var;
Answer: This statement will declare a constant pointer to non-constant data i.e. the value of the variable
pointed to can be changed through this pointer but the pointer itself cannot point to any other variable.

b. What can be done if we don't want any objects to be copied in our program?
Answer: We can add a copy constructor in that class and change its access level to private, hence making
both user-defined and compiler-provided copy constructors unusable.

c. How can we initialize a constant using value taken at runtime?


Answer: We can initialized a constant class variable at runtime using member initialization list with a
constructor. The value taken at runtime can be passed to that constructor as a parameter.

d. Can a static member function call non-static member functions? If yes, then how?
Answer: A static member function cannot directly call any non-static member functions. However, it can use
an object of the class to call non-static member functions.

e. Can two different unrelated classes in a single program contain functions with the same name and parameter
signature?
Answer: Yes. Since the naming scope of two unrelated classes are different in a program.

1 OF 2
Q No. 2 Consider the following scenario: [2.5 x 4 = 10 Points]
ABC University is a large institution with several campuses. Each campus has a different name, address, and distance to
the city center.
The University consists of a number of faculties, such as the Art Faculty, the Science Faculty, and so on. Each faculty has a
name, dean and building. ABC University offers different programmes and each programme has a code (valid format: P-nnn,
where n can be any digit), title, level and duration (1, 2 or 3). Each programme comprises several courses, different programmes
have different courses. Each course has a code (valid format C-nnn, where n can be any digit) and course title.
Each of the students is enrolled in a single programme of study which involves a fixed set of core courses specific to that
programme as well as a number of electives taken from other programmes. Students work on courses and are awarded a grade
in any course if he/she passes the course. Otherwise the student has to re-take the failed course. The system needs to record
the year and term in which the course was taken and the grade awarded to the student. Every student has a unique ID. The
system also keeps the student name, birthday and the year he/she enrolled in the course.
a. Identify all the classes and objects that will be needed.
Campus
Faculty
Programme
Course
Result
Student

b. Identify the key attributes and functionalities of each class.


Campus: name, address, distance
Faculty: name, dean, building
Programme: code, title, level, duration, const courses[a,b,c…], validateCode(string){*/WORKING*/},
validateDuration(int){ */WORKING*/}
Course: code, title, validateCode(string){ */WORKING*/}
Result: year, term, grade
Student: ID, name, birthday, enrollmentYear

c. Explain how Object Oriented approach can make your program more robust, secure and efficient with reference to the
given scenario.
[FREE RESPONE] each of the above entity’s data (instance) is contained within the objects, making it hidden
from accidental changes and access from outside the object. For example student1 cannot access the data
contained in student2 instance. OR ANY OTHER OOP approach
d. Identify any one of the member functions which the compiler can inline.
Any of the member functions from Campus class can be inlined as there are setters mainly. For e.g. the
following:
Campus(string cName, string cAddress, float cDistance):name(cName),
address(cAddress),distance(cDistance)

2 OF 2
Q No. 3 [5 x 2 = 10 Points]
a. Consider the code snippet given below, identify and explain the error and also provide the corrected code.

Note: The access specifiers for the given attribute and function are not allowed to be changed

class Employee
{
string name;

set_Name(string a)
{
name = a;
}

};

int main()
{
Employee e1;
e1.set_Name("Rehan");
}

#include<iostream>
using namespace std;

class Employee
{
string name;

set_Name(string a)
{
name = a;
}

public:
my_func(string a)
{
set_Name(a);
}

};

int main()
{
Employee e1;
//e1.set_Name("Rehan");
e1.my_func("Rehan");
}

3 OF 2
b. Consider the code snippet given below, in which the constructors of class Car have been labeled as 1, 2, 3, and 4:

class Car {
public:
Car(); // 1
Car(int x); // 2
Car(int x, int y); // 3
Car(const Car& b); // 4
};

int main() {
Car b1(10); // A
Car* p = new Car(11); // B
Car arr[10]; // C
Car b2 = b1; // D
return 0;
}

Identify which constructor is called in each of these different cases at A, B, C and D.

A 2

B 2

C 1

D 4

- Good Luck -

4 OF 2

You might also like