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

Object Oriented Programming Lab-03 (GetterSetter, Constructors, MemberFunctions)

The document describes three tasks related to object-oriented programming concepts in C++. Task 1 involves creating a Car class with member variables for year, make, and speed, along with constructor, accessor, and mutator methods. Task 2 involves creating a Date class with member variables for day, month, and year, and implementing different constructor options. Task 3 describes designing an Inventory class to hold retail item data with private member variables.

Uploaded by

Ahmad Abduhu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
91 views4 pages

Object Oriented Programming Lab-03 (GetterSetter, Constructors, MemberFunctions)

The document describes three tasks related to object-oriented programming concepts in C++. Task 1 involves creating a Car class with member variables for year, make, and speed, along with constructor, accessor, and mutator methods. Task 2 involves creating a Date class with member variables for day, month, and year, and implementing different constructor options. Task 3 describes designing an Inventory class to hold retail item data with private member variables.

Uploaded by

Ahmad Abduhu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 4

Object Oriented Programming

Lab Manual (Lab 03)

Topic: Constructors, Getters/Setters and Member


Functions

Course Instructor: Miss Sundas Sagheer


Lab Instructor: Ahmad Abduhu

Session: Fall 2019


School of Systems and Technology
UMT Lahore Pakistan

1
Lab Tasks

Task 1:

Write a class named Car that has the following member variables:
• year. An int that holds the car’s model year.
• make. A string that holds the make of the car.
• speed. An int that holds the car’s current speed.

In addition, the class should have the following member functions.

• Constructor.
The constructor should accept the car’s year and make as arguments
and assign these values to the object’s year and make member variables. The constructor
should initialize the speed member variable to 0.
• Accessors.
Appropriate accessor functions should be created to allow values to be
retrieved from an object’s year, make, and speed member variables.
• accelerate.
The accelerate function should add 5 to the speed member variable
each time it is called.
• brake.
The brake function should subtract 5 from the speed member variable each
time it is called.

Demonstrate the class in a program that creates a Car object, and then calls the accelerate
function five times. After each call to the accelerate function, get the current speed of the
car and display it. Then, call the brake function five times. After each call to the brake
function, get the current speed of the car and display it..

2
Task 2: Write a code for a class named Date with three data members day, month and year
which must incorporate the following given main. Write each type of (all possible) constructors
implemented in following main function and getter/setter methods.
int main()

Date D1;

D1.DisplayDate();

Date D2(23); // Constructor with single value of day

D2.DisplayDate();

Date D3(23,03); // Constructor with the values of day and Month

D3.DisplayDate();

Date Today(1,11,2019); // Constructor with the values of day, Month and year.

Today.DisplayDate();

return 0;

3
Task 3:

Design an Inventory class that can hold information for an item in a retail store’s inventory.
The class should have the following private member variables.

You might also like