0% found this document useful (0 votes)
6 views3 pages

Lab 11

The lab manual for Object Oriented Programming at National University of Computer and Emerging Sciences outlines three tasks for students to practice key concepts such as virtual destructors, abstract classes, and templates. Task 1 involves creating a class structure with memory management, Task 2 focuses on implementing a template class for a calculator, and Task 3 requires calculating the area of different shapes using an abstract class. The manual is designed for BSCS 2A students in Spring 2022 under the guidance of instructors Ms. Saira Karim, Ms. Mamoona Akbar, and Ms. Sonia Anum.

Uploaded by

mariamqadeem181
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)
6 views3 pages

Lab 11

The lab manual for Object Oriented Programming at National University of Computer and Emerging Sciences outlines three tasks for students to practice key concepts such as virtual destructors, abstract classes, and templates. Task 1 involves creating a class structure with memory management, Task 2 focuses on implementing a template class for a calculator, and Task 3 requires calculating the area of different shapes using an abstract class. The manual is designed for BSCS 2A students in Spring 2022 under the guidance of instructors Ms. Saira Karim, Ms. Mamoona Akbar, and Ms. Sonia Anum.

Uploaded by

mariamqadeem181
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/ 3

National University of Computer and Emerging Sciences

Lab Manual
Object Oriented Programming

Course Instructor Ms. Saira karim


Lab Instructor (s) Ms. Mamoona Akbar
Ms. Sonia Anum
Section BSCS 2A
Semester Spring 2022

Department of Computer Science


FAST-NU, Lahore, Pakistan
Objectives
After performing this lab, students shall be able to:
 virtual Destructor
 Abstract Classes
 Templates

TASK 1: (Hint: Virtual Destructor)

Write a program to practice memory management alongside polymorphism.


You are not allowed to change function prototypes
Implement following class structure. In addition to this you are to implement destructors in all
classes below to ensure dynamically allocated memory is properly deleted.

Person (Base Class) Employee (Derived) Student (Derived)

//member variables //member variables //member variables


{ { {
Private: Private: Private:
String fullName; String departement; String schoolName;
Int height; Int ID;
Public:
Public: Public:
Student (string name,Int
Person(string name,Int Employee(string name,Int height, string
height) //constructor height,string SchoolName) : Person(
departement,Int id) : name, height)
Virtual void printInfo(); Person( name, height) //constructor
//this function is to print all //constructor
private varaibles void printInfo();
void printInfo(); //this function is to print all
//this function is to print all private variables alongside
//destructor to be private variables alongside type of class
implemented alongside type type of class
of class eg cout<<”person
destructor” (5) //destructor to be //destructor to be
implemented alongside type implemented alongside type
of class eg of class eg cout<<”student
} cout<<”employee destructor”
destructor” }
}
Main Program:
1. Create an array of base class of size 2.
2. Initialize each of the base class member with employee and student object respectively.
3. Run a loop to call printInfo on the array created.
4. Call delete operator on the array of base class to test the memory management.
TASK 2:

Create a Template class Calculator that have following data member


 Num1
 Num2
 Result

Following are the functionalities that you perform.


 Constructor
 Parameterize constructor
 Sum() : that takes two number as argument and store result in Result variable.
 Sum() : that takes three number as argument and store result in Result variable.
 Subtract() : that takes two number as argument and store result in Result variable.
 Subtract() : that takes three number as argument and store result in Result variable.
 Multiplication():that takes two number as argument and store result in Result variable.
 Multiplication():that takes three number as argument and store result in Result variable.
 Division():that takes two number as argument and store result in Result variable.
 Division():that takes three number as argument and store result in Result variable.
 Modulus():that takes two number as argument and store result in Result variable.
 Max():that takes two number as argument and store result in Result variable
 Min():that takes two number as argument and store result in Result variable

TASK 3:
We have to calculate the area of a rectangle, a square and a circle. Create an abstract class 'Shape' with three
abstract methods namely 'RectangleArea' taking two parameters, 'SquareArea' and 'CircleArea' taking one
parameter each. The parameters of 'RectangleArea' are its length and breadth, that of 'SquareArea' is its side
and that of 'CircleArea' is its radius. Now create another class 'Area' containing all the three methods
'RectangleArea', 'SquareArea' and 'CircleArea' for printing the area of rectangle, square and circle
respectively. Create an object of class 'Area' and call all the three methods.

You might also like