Oop Practical Exercises
Oop Practical Exercises
COMPUTER ENGINEERING
OOP PRACTICAL EXERCISES/Past Questions
1. A class called Box contains:
Three private instance variables: height h, its width W, and its length L and colour c.
Two overloaded constructors - a default constructor with no argument which will assign
a value of your choice to each instance variable, and a constructor which takes 4
arguments L1, h1, W1 and c1 to initialized L,h,W and c
Two public methods: getLength() and getVolume(), which return the Length and volume
of this instance, respectively.
a) What can be the data type of each instance variable of class Box? (3 marks)
b) Give the equivalent C++ or java code of this description (9 marks)
2. Create a class in either C++ or Java to model a simple banking system. Include attributes
such as account balance and account holder name, and implement methods for deposit
and withdrawal. Provide a brief explanation of your class structure. (5 marks)
3. Write a C++ program that list all even numbers between given integer number a and b.
(4 marks)