Object Oriented Programming
Lab Manual
(Lab-02)
Topic: Composition and Aggregation
Lab Instructor: Ahmad Abduhu
Session: Fall 2019
School of Systems and Technology
UMT Lahore Pakistan
Lab Tasks
Task 1:
Make a class with objects of following classes, data members and member functions.
Monitor // an object of Monitor class.
CPU // an object of CPU class.
Keyboard // an object of Keyboard class.
Mouse // an object of Mouse class.
USBDrive // a reference of USBDrive class.
Price // sum of prices of all parts.
Brand // string containing the name of ComputerSystem’s
Brand.
ShowSystem() // print the complete system devices with name and
specs.
ShowPrice() // print the cumulative price of computer system.
AttachUSB() // connect the USB to system (Aggregation part of the
Task)
RemoveUSB() // disconnect the USB from system
Monitor must have following member variables
String CompanyName
int Size (diagonal size in inches)
double price
CPU must have following member variables
String CompanyName
double Speed (in Hertz)
double price
Key Board must have following member variables
String CompanyName
int NumOfKeys
double price
ComputerSystem has a reference of USBDrive class’s object. USBDrive class must have the
following
String CompanyName
double size (in GBs)
double price
NOTE:
1. Also write the constructor & destructor and getter/setter for every class.
2. A user may connect upto 5 USB devices manage it using attachUSB functions.
Task 2 (Aggregation):
Create a class Student which has attribute Name, Age methods GetName, Get Age, SetName, SetAge.
Create another class Class Course which has reference of student object as its member and a data member
Grade method PrintStudent. Write test program to show aggregation relationship between these two
objects.