BIT 2108 BBIT 203 BSD 2102 BISF 2101 BAC 2101 – OBJECT ORIENTED PROGRAMMING KCA Past Paper

UNIVERSITY EXAMINATIONS: 2019/2020
EXAMINATION FOR THE DEGREE OF BACHELOR OF SCIENCE IN
INFORMATION TECHNOLOGY/ BUSINESS INFORMATION
TECHNOLOGY/ APPLIED COMPUTING/ SOFTWARE DEVELOPMENT/
INFORMATION SECURITY & FORENSCIS
BIT 2108/ BBIT 203/ BSD 2102/ BISF 2101/ BAC 2101: OBJECT ORIENTED
PROGRAMMING
FULL TIME/PART TIME/DISTANCE LEARNING
DATE: MAY, 2020 TIME: 6 HOURS
INSTRUCTIONS: Answer ALL Questions
SECTION B: SHORT ANSWER QUESTIONS

QUESTION ONE [20 MARKS]
a) Write a program that calculates and displays the weekly salary for an employee who earns
$25 an hour, works 40 regular hours, 13 overtime hours, and earns time and one-half (wage *
1.5) for overtime hours worked. Create a separate method to do the calculation and return the
result to be displayed. Your program contain a class that holds the employee details indicated
as well as the method to do the computation
(10 Marks)
b) Create a class called Invoice that a hardware store might use to represent an invoice for an
item sold at the store. An Invoice should include four pieces of information as data
members—a part number (type string), a part description (type string), a quantity of the item
being purchased (type int) and a price per item (int). [Note: In subsequent chapters, we’ll use
numbers that contain decimal points (e.g., 2.75)—called floating-point values—to represent
dollar amounts.] Your class should have a constructor that initializes the four data members.
Provide a set and a get method for each data member. In addition, provide a member function
named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by
the price per item), then returns the amount as an int value. If the quantity is not positive, it
should be set to 0. If the price per item is not positive, it should be set to 0. Write a test
program that demonstrates class Invoice’s capabilities.
(10 Marks)
SECTION C: APPLICATION QUESTION (20 MARKS)
QUESTION ONE [20 MARKS]
Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All
customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e.,
debit) money from their accounts. More specific types of accounts also exist. Savings accounts,
for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge
a fee per transaction (i.e., credit or debit).
Create an inheritance hierarchy containing base class Account and derived classes
SavingsAccount and CheckingAccount that inherit from class Account.
Base class Account should include one data member of type double to represent the account
balance. The 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 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 the message “Debit amount exceeded account balance.” Member
function getBalance should return the current balance.
Derived class SavingsAccount should inherit the functionality of an Account, but also include a
data member of type double indicating the interest rate (percentage) assigned to the Account.
SavingsAccount’s constructor should receive the initial balance, as well as an initial value for the
SavingsAccount’s interest rate. SavingsAccount should provide a public member function
calculateInterest that returns a double indicating the amount of interest earned by an account.
Member function calculateInterest should determine this amount by multiplying the interest rate
by the account balance. [Note: SavingsAccount should inherit member functions credit and debit
as is without redefining them.]
Derived class CheckingAccount should inherit from base class Account and include an
additional data member of type double that represents the fee charged per transaction.
CheckingAccount’s constructor should receive the initial balance, as well as a parameter
indicating a fee amount. Class CheckingAccount should redefine member functions credit and
debit so that they subtract the fee from the account balance whenever either transaction is
performed successfully. CheckingAccount’s versions of these functions should invoke the baseclass
Account version to perform the updates to an account balance. CheckingAccount’s debit
function should charge a fee only if money is actually withdrawn (i.e., the debit amount does not
exceed the account balance). [Hint: Define Account’s debit function so that it returns a bool
indicating whether money was withdrawn. Then use the return value to determine whether a fee
should be charged.]
After defining the classes in this hierarchy, write a program that creates objects of each class and
tests their member functions. Add interest to the SavingsAccount object by first invoking its
calculateInterest function, then passing the returned interest amount to the object’s credit
function.
(20 Marks)

(Visited 155 times, 1 visits today)
Share this:

Written by