0% found this document useful (0 votes)
29 views2 pages

Oop Practical Exercises

Uploaded by

tsaydaniel80
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Oop Practical Exercises

Uploaded by

tsaydaniel80
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

HUIB

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)

4. A hardware store represents an invoice as an item sold in the store. An


invoice should include four pieces of information as instance variables – a
part number (type string), a part description(type string) a quantity of the
item being purchased(type int) and a price per item(double). Your class
should have a constructor that initializes the four instance variables.
Carry out the following tasks in C++ or java programming language
i. Create an invoice class 5marks
ii. Provide a set and get method for each instance variable. 5marks
iii. In addition provide a method named get invoice amount that
calculates the invoice amount (i.e. multiplies the quantity by the price
per item) then returns the amount as a double value. 6marks
iv. Write a test application named as invoice test that demonstrates
class invoice capabilities 3marks.
5. Using C++ or Java, write a program to illustrate inheritance concept of
object oriented programming 7marks.

You might also like