Assignment 3: Topics: Instruction
Assignment 3: Topics: Instruction
Topics:
● Inheritance (public, private and protected)
● Aggregation,Composition and Association
Instruction:
● Individual submission Deadline:07th jan 2021,friday till 11.59 PM
● Bonus task should be submitted individually till 8th jan2021 11.59PM
● Group submission Deadline: 10th jan 2021, sunday till 11.59 PM
● Group Feedback submission deadline:12 th jan 2021, Tue till 11.59 PM
Link for Review:https://forms.gle/FGpK8CDDw2AHYTyq6
● Bonus task and Compulsory task should be submitted separately
● Evaluation of this assignment will be Quiz based. Quiz will be counted in Quiz
and Assignment as well. In some case a Viva may be arranged
● Submission folder should name Group_section
Question 1 (Inheritance)
(Account Inheritance Hierarchy) 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. Morespecific 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’s
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 base-
class 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.
Question 2(Inheritance)
Package-delivery services, such as FedEx ®, DHL® and UPS®, offer a number of different
shipping options, each with specific costs associated. Create an inheritance hierarchy to represent
various types of packages. Use class Package as the base class of the hierarchy, then include
classes TwoDayPackage and OvernightPackage that derive from Package. Base class Package
should include data members representing the name, address, city, state and ZIP code for both
the sender and the recipient of the package, in addition to data members that store the weight (in
ounces) and cost per ounce to ship the package. Package’s constructor should initialize these data
members. Ensure that the weight and cost per ounce contain positive values. Package should
provide a public member function calculateCost that returns a double indicating the cost
associated with shipping the package. Package’s calculateCost function should determine the
cost by multiplying the weight by the cost per ounce. Derived class TwoDayPackage should
inherit the functionality of base class Package, but also include a data member that represents a
flat fee that the shipping company charges for two-day-delivery service. TwoDayPackage’s
constructor should receive a value to initialize this data member. TwoDayPackage should
redefine member function calculateCost so that it computes the shipping cost by adding the flat
fee to the weight-based cost calculated by base class Package’s calculateCost function. Class
OvernightPackage should inherit directly from class Package and contain an additional data
member representing an additional fee per ounce charged for overnight-delivery service.
OvernightPackage should redefine member function calculateCost so that it adds the additional
fee per ounce to the standard cost per ounce before calculating the shipping cost. Write a test
program that creates objects of each type of Package and tests member function calculateCost.
Task 3 (static)
Create a SavingsAccount class. Use a static data member annualInterestRate to store the annual
interest rate for each of the savers. Each member of the class contains a private data member
savingsBalance indicating the amount the saver currently has on deposit. Provide member
function calculateMonthlyInterest that calculates the monthly interest by multiplying the balance
by annualInterestRate divided by 12; this interest should be added to savingsBalance. Provide a
static member function modifyInterestRate that sets the static annualInterestRate to a new value.
Write a driver program to test class SavingsAccount. Instantiate two different objects of class
SavingsAccount, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set
the annualInterestRate to 3 percent. Then calculate the monthly interest and print the new
balances for each of the savers. Then set the annualInterestRate to 4 percent, calculate the next
month’s interest and print the new balances for each of the savers
(** Download this assignment and double click on this file, it will open)
A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, pointType,
that can store and process a point in the x-y plane.
● You should then perform operations on the point, such as setting the coordinates of the point,
printing the coordinates of the point, returning the x-coordinate, and returning the y-coordinate
● Create constructor.
After designng pointType class, Design circleType class having a center and a radius. Given the radius, we
can determine the circle’s area and circumference. Given the center, we can determine its position in
the x-y plane. The center of the circle is a point in the x-y plane. Design a class, circleType, that can store
the radius and center of the circle. Because the center is a point in the x-y plane.
● You should be able to perform the usual operations on the circle, such as setting the radius,
printing the radius, calculating and printing the area and circumference.. Also, write a program
to test various operations on a circle.
In class BillingSystem We have a list(array) of patient and doctors, these are on concept of parallel
array.AddRecord function add patient and doctor object in corresponding list. PatientInfo function takes
patient ID and print complete patient and corresponding doctor detail. CalculateBill() function calculates
the bill based on formula:
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 publicly
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.
Bonus Question (For Extra Marks)