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

Lab 11 week 11

The document outlines the lab instructions for Object Oriented Programming at the University of Central Punjab for Fall 2024. It includes tasks for creating a university management system, handling student and instructor data, and modeling different vehicle types using classes with specific attributes and methods. Students are required to follow coding standards and submit their work within the prescribed timings.

Uploaded by

asifhuzaifa123
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)
4 views

Lab 11 week 11

The document outlines the lab instructions for Object Oriented Programming at the University of Central Punjab for Fall 2024. It includes tasks for creating a university management system, handling student and instructor data, and modeling different vehicle types using classes with specific attributes and methods. Students are required to follow coding standards and submit their work within the prescribed timings.

Uploaded by

asifhuzaifa123
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/ 6

University of Central Punjab

Faculty of Information Technology

Object Oriented Programming


Fall 2024
Lab 11

Instructions:
 Indent your code properly.
 Use meaningful variable and function names. Use the camelCase notation.
 Use meaningful prompt lines/labels for all input/output.
 Strictly follow the Good Code Writing Style which is already shared by your theory
teacher.
 In each file of your task either it is .cpp file or .h file Your name and roll no must be
mention in the start of your file as comment. For example, //L1F22BSCS1234 – Ali
Rehman
 Students must follow the "Code Writing Guide".
 You are not allowed to use string. You can use Cstring only as character arrays.
 You are not allowed to use any buil-in function such as as strcopy(), strcpy_s, or.length().
 Marks cannot be given on codes with run-time or compile-time errors.
 Perform all the tasks in separate source, header and main driver file.

Understanding of the question is part of the evaluation.


Students are required to complete the following tasks in lab timings. Submission of each task in
prescribed timing is mandatory.

Topic: Composition/ Aggregation/ Inheritance


Task 1:
You have been hired to develop a basic university management system that models the
relationship between a university, its departments, and the professors within those
departments. The goal is to create a system where:
 Each university has multiple departments.
 Each department has multiple professors.
The system should allow adding professors to departments and departments to universities.
The system should be able to display the entire structure of the university, including its
departments and the professors in each department.
The following requirements must be met:

 Implement a Professor class that contains information about a professor.


 Implement a Department class that contains information about a department and
can store multiple Professor objects.
 Implement a University class that contains information about a university and can
store multiple Department objects.
Ensure that the relationship between University and Department, as well as between
Department and Professor, demonstrates the concept of aggregation, where the lifecycle of
departments and professors is independent of the university.
The code should include functionality to add professors to departments, add departments
to universities, and display the complete structure of the university.
You can call destructors of the objects to check the has a relationship.

--------------------------------------------------------------------------------------------------------------------------
Task 2

In UCP, we have thousands of students who are currently enrolled in any Course. One Course has
exactly one Instructor associated with it. We need to implement this scenario to store
information of Students, Instructors, and Courses.

1. Define a class Student having following private data members:


i.) name
ii.) registrationNo
iii.) city

2. Write parameterized constructor with default parameters for student class.


3. Write destructor with no memory leakage.
4. Write copy constructor and assignment operator.
5. Write setter and getter for each data member of student class.
6. Write a display function.

7. Define a class Instructor having following private data members:


i.) name (pointer to character array)
ii.) education (pointer to character array)
8. Write parameterized constructor with default parameters for Instructor class.
9. Write destructor with no memory leakage.
10. Write copy constructor and assignment operator.
11. Write a display function.
12. Write setter and getter for each data member of instructor class.

13. Define a class Course having following private data members:


i.) courseName (pointer to character array)
ii.) instructor ( a course offered has exact one Instructor)
iii.) student (a Course offered has many Students enrolled)
14. Write default and parameterized constructor for Course class.

15. Write setter and getter for each data member of Course class.
16. Write destructor with no memory leakage.
17. Write copy constructor and assignment operator.
18. Write a display function.
19. Write a function that return total student count enrolled in class.

20. Write a display() function in Course class that displays complete Course information like
following

Course Name: OOP LAB


Instructor Name: AASMA ABDUL WAHEED
Total Students Enrolled: 2
---------------------------------------------------------------------
No. Registration No Student Name
1. L1F1YBSCSWXYZ Ali
2. L1F1YBSCSWXYZ Ammar

21. A Course cannot have more than 30 students. Write logic to implement this.

22. Now do following operation in main function:

Create 3 student objects with following data:

 name: Ali registrationNo: L1F1YBSCS1ABC city: Lahore


 name: Ahmad registrationNo: L1F1YBSCS2ABC city: Islamabad
 name: Ammar registrationNo: L1F1YBSCS3ABC city: Lahore

a. Create an object oopLabSecC4 of Course class with default constructor.


b. Now set course name to ‘OOPFall2023SecC4Lab’.
c. Display total number of students in oopLabSecC4.

i.) Now add all 3 newly created students to oopLabSecC4.


ii.) Display total number of students in oopLabSecC4.
iii.) Create an Instructor inst1 having name ‘AASMA ABDUL
WAHEED’ and education ‘MPHIL’
iv.) Add inst1 to oopLabSecC4.
v.) Now display oopLabSecC4 all data on screen.
vi.) Now create another object oopLabSecC2 of Course class

vii.) Now add Ali and Ammar in oopLabSecC2.


viii.) Create a new Instructor inst2 having name ‘USAMA PERVAIZ’ and
education ‘MPHIL’

ix.) Now Add inst2 to oopLabSecC2.

x.) Now delete oopLabSecC4.


xi.) Display oopLabSecC2 data on screen and see Ali and Ammar are still in
oopLabSecC2 or deleted from here too due to deletion of
oopLabSecC4.

xii.) Now call name of inst1 on screen. Verify that whether inst1 is deleted
with oopLabSecC4 or not?

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

Task 3
In a transportation management system, the need arises to efficiently model and manage different
types of vehicles within a fleet. This scenario involves the development of classes to represent Cars,
Trucks, and Buses, each sharing common attributes like "make," "model," and "year."

Classes Structure:

Class: Vehicle

Common Attributes:

 make Represents the manufacturer or brand of the vehicle.


 model Specifies the model name of the vehicle.
 variant Represents the manufacturing year of the vehicle.

Default and Parameterized Constructor:

 Initializes make, model, and variant based on provided parameters.

Getters and Setters:

 Allows access and modification of the make, model, and variant attributes.

Operators Overloaded:

 ==: Compares two vehicles for equality based on their attributes.


 =: Assigns one vehicle's attributes to another.
 ++: Increments the manufacturing year of the vehicle.
 << and >>: Outputs/inputs vehicle attributes to/from a stream.

Virtual Functions (to be overridden by child classes):

 calculateFuelEfficiency(): Calculates and returns a default fuel efficiency value.

Class: Car (Derived from Vehicle)

Additional Attributes:

• numDoors (int): Represents the number of doors in the car.


• isConvertible (bool): Indicates whether the car is convertible or not.
Constructor:

• Calls the parent class constructor and initializes car-specific attributes.

Getters and Setters:

• Provides access and modification for car-specific attributes.

Operators Overloaded:

• Inherits and reuses the operators overloaded in the parent class.

Overridden Virtual Functions:

• calculateFuelEfficiency(): Calculates and returns fuel efficiency specific to a car.

Class: Truck (Derived from Vehicle)

Additional Attributes:

• payloadCapacity (double): Specifies the payload capacity of the truck in tons.

• hasTrailer (bool): Indicates whether the truck is equipped with a trailer or not.

Constructor:

• Calls the parent class constructor and initializes truck-specific attributes.

Getters and Setters:

• Provides access and modification for truck-specific attributes.

Operators Overloaded:

• Inherits and reuses the operators overloaded in the parent class.

Overridden Virtual Functions:

• calculateFuelEfficiency(): Calculates and returns fuel efficiency specific to a truck.

Class: Bus (Derived from Vehicle)

Additional Attributes:

 seatingCapacity (int): Represents the maximum number of passengers the bus can
accommodate.
 hasDoubleDecker (bool): Indicates whether the bus has a double-decker design or not.

Constructor:

 Calls the parent class constructor and initializes bus-specific attributes.

Getters and Setters:

 Provides access and modification for bus-specific attributes.

Operators Overloaded:
 Inherits and reuses the operators overloaded in the parent class.

Overridden Virtual Functions:

 calculateFuelEfficiency(): Calculates and returns fuel efficiency specific to a bus.


Write main to test above classes and relationships. After that in main function
Create array of pointers of parent type class and then user polymorphism to
access functions and operators of children classes.

The use of inheritance allows for code reuse, and the overridden virtual functions enable
polymorphic behaviour, allowing each derived class to provide its specific implementation of fuel
efficiency calculation.

Make sure to implement the functions and methods as per the described logic and test the classes to
ensure they function correctly. Additionally, consider adding proper error handling to enhance the
clarity and robustness of the code.

**************** Good Luck *******************

You might also like