Assignment 3 4
Assignment 3 4
55 PM Night)
Assignment 3 & 4
Polymorphism Association, Aggregation and Composition
Question 1:
There is Employee Hierarchy as shown in figure 1 below. Data corresponding to each employee
is in file “EmployeesData.txt”. Where 1st number shows the number of data sample available.
Also number before each data shows which type of employee it is?
EmployeesData.txt
Task:
Create a function called CalculateSalary() in each class that returns the salary after
calculation
o Salaried: Returns entered salary
o Hourly: Returns salary by multiplying Hours and PerhourCharges
o HourPlusSalaried: Returns salary by multiplying Hours and PerhourCharges plus
actual Salary.
Make Employee Class as abstract class by making CalculateSalary() as pure virtual
Create appropriate Constructors, destructors and setter/getter.
In main function you can only create Two dimensional pointer of Employee. No any
other object or pointer should be there. You have to read data from file using concept of
polymorphism.
Employee **ptr= new Employee * [NumberOfSamples];
o After reading data from file display salary of each employee along his/her ID and name.
Question 2: Implement the following hierarchy of shop management system as shown below
in (incomplete) UML diagram. Add attribute and functions by considering the requirements.
The ShopManagement is a parent class, which saves and updates the entire record (person’s
and his mobile’s information). Two classes Mobile and Person are associated with it. The Mobile
class is publically inherited by Nokia, OPPO and QMobile. Whereas the person is categorized as
salaried employee or Businessman. The given hierarchy depicts the above statement in
graphical way.
Important: We are interested in polymorphism relationship (see main for details). Consider the
given main() and expected output, and write complete clear and clean code. Do not use string
library for any purpose.
Deadline is 11th July 2021 (11.55 PM Night)
Question 3:
Banks offer various types of accounts, such as savings, checking, certificate of deposits, and
money market, to attract customers as well as meet with their specific needs. Two of the most
commonly used accounts are savings and checking. Each of these accounts has various options.
For example, you may have a savings account that requires no minimum balance but has a
lower interest rate. Similarly, you may have a checking account that limits the number of checks
you may write. Another type of account that is used to save money for the long term is
certificate of deposit (CD).
Deadline is 11th July 2021 (11.55 PM Night)
In this programming exercise, you use abstract classes and pure virtual functions to design
classes to manipulate various types of accounts. For simplicity, assume that the bank offers
three types of accounts: savings, checking, and certificate of deposit, as described next. Savings
accounts: Suppose that the bank offers two types of savings accounts: one that has no
minimum balance and a lower interest rate and another that requires a minimum balance and
has a higher interest rate. Checking accounts: Suppose that the bank offers three types of
checking accounts: one with a monthly service charge, limited check writing, no minimum
balance, and no interest; another with no monthly service charge, a minimum balance
requirement, unlimited check writing and lower interest; and a third with no monthly service
charge, a higher minimum requirement, a higher interest rate, and unlimited check writing.
Certificate of deposit (CD): In an account of this type, money is left for some time, and these
accounts draw higher interest rates than savings or checking accounts. Suppose that you
purchase a CD for six months. Then we say that the CD will mature in six months. Penalty for
early withdrawal is stiff. Figure shows the inheritance hierarchy of these bank accounts Note that
the classes bankAccount and checkingAccount are abstract.
That is, we cannot instantiate objects of these classes. The other classes in Figure are not
abstract.
bankAccount: Every bank account has an account number, the name of the owner, and a
balance. Therefore, instance variables such as name, accountNumber, and balance should be
declared in the abstract class bankAccount. Some operations common to all types of accounts
are retrieve account owner’s name, account number, and account balance; make deposits;
withdraw money; and create monthly statement. So include functions to implement these
operations. Some of these functions will be pure virtual.
checkingAccount: A checking account is a bank account. Therefore, it inherits all the properties
of a bank account. Because one of the objectives of a checking account is to be able to write
checks, include the pure virtual function writeCheck to write a check.
serviceChargeChecking: A service charge checking account is a checking account. Therefore, it
inherits all the properties of a checking account. For simplicity, assume that this type of account
does not pay any interest, allows the account holder to write a limited number of checks each
month, and does not require any minimum balance. Include appropriate named constants,
instance variables, and functions in this class.
noServiceChargeChecking: A checking account with no monthly service charge is a checking
account. Therefore, it inherits all the properties of a checking account. Furthermore, this type
of account pays interest, allows the account holder to write checks, and requires a minimum
balance.
highInterestChecking: A checking account with high interest is a checking account with no
monthly service charge. Therefore, it inherits all the properties of a no service charge checking
account. Furthermore, this type of account pays higher interest and requires a higher minimum
balance than the no service charge checking account.
savingsAccount: A savings account is a bank account. Therefore, it inherits all the properties of
a bank account. Furthermore, a savings account also pays interest.
Deadline is 11th July 2021 (11.55 PM Night)
Best of Luck.!