OOP Lab - 2-3
OOP Lab - 2-3
Task 1:
Make a class of Bike with parameters strokes, horsepower with all possible getter/setter and print() and write
test program for it.
Task 2:
Make a class of School with parameters all int type: rooms, staff, students and function initialize() and print()
write test program for it.
Task 3:
Write a code for a class named Date which must incorporate the following given main write each type of
constructor implemented in following main function.
int main()
{
Date D1;
D1.DisplayDate();
Date D2(23);
D2.DisplayDate();
Date D3(23,03);
D3.DisplayDate();
Date D4(23,03,2013);
D4.DisplayDate();
return 0;
}
Task 4:
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.
• 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.
1
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..
Task 5:
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.
2
3