Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Ankara University

Department of Computer Engineering


COM102 A

WEEK-5

LAB WORK

Lab p-1) Create a class called Account that a bank might use to represent
customers’ bank accounts. Your class should include one data member
of type double to represent the account balance. Your class should
provide a constructor that receives an initial balance and uses it to
initialize the data member. The constructor should validate the initial
balance to ensure that it is greater than or equal to 0.0. If not, the
balance should be set to 0.0 and the constructor should display an error
message, indicating that the initial balance was invalid. The class
should provide three member functions. Member function credit should
add an amount to the current balance. Member function debit should
withdraw money from the Account and should ensure that the debit
amount does not exceed the Account’s balance. If it does, the balance
should be left unchanged and the function should print a message
indicating “Debit amount exceeded account balance.” Member function
getBalance should return the current balance. Create a program that
creates two Account objects and tests the member functions of the
class Account.

Lab p-2) Create a class called IntegerSet. Each object of class IntegerSet can
hold integers in the range 0 through 10. A set is represented internally
as an array of ones and zeros. Array element a[i] is 1 if integer i is in the
set. Array element a[j] is 0 if integer j is not in the set. The default
constructor initializes a set to the so-called “empty-set”.
Provide an insertElement member function that inserts a new integer k
into a set (by setting a[k] to1).
Provide a deleteElement member function that deletes integer m (by
setting a[m] to 0).
Provide a setPrint member function that prints a set as a list of numbers
separated by spaces. Print only those elements that are present in the
set. Print --- for an empty set.
Write a driver program to test your IntegerSet class. Create several
IntegerSet objects. Test that all your member functions work properly.

You might also like