Sunteți pe pagina 1din 2

Assignment # 1

Course Name: Object Oriented Programming Submission date: 20 April 2020


Instructor Name: Dr. Muhammad Younas
Questions # 1.
Create a BankAcc class. Use a static data member annual-InterestRate 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
savingsBalance 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 (main function) to test class
BankAcc. Instantiate two different objects of class BankAcc, saver1 and saver2, with balances
of 2000 RS and 3000 RS, respectively. Set the annualInterestRate to 5 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.
Questions # 2
Create a class called time that has separate int member data for hours, minutes, and seconds.
One constructor should initialize this data to 0, and another should initialize it to fixed values.
Another member function show should display it, in 11:59:59 format. The final member function
Add should add two objects of type time passed as arguments. A main() program should create
two initialized time objects (should they be const?) and one that isn’t initialized. Then it should
add the two initialized values together, leaving the result in the third time variable. Finally, it
should display the value of this third variable. Make appropriate member functions const.

Question # 3
Create a class called Complex for performing arithmetic with complex numbers.
Write a program to test your class. Complex numbers have the form
realPart + imaginaryPart * i
where i is Use double variables to represent the private data of the class. Provide a constructor
that enables an object of this class to be initialized when it’s declared. The constructor should
contain default values in case no initializers are provided. Provide public member functions that
perform the following
tasks:
a) Adding two Complex numbers: The real parts are added together and the imaginary
parts are added together.
b) Subtracting two Complex numbers: The real part of the right operand is subtracted
from
the real part of the left operand, and the imaginary part of the right operand is subtracted
from the imaginary part of the left operand.
c) Printing Complex numbers in the form (a, b), where a is the real part and b is the
imaginary part.
Question #4
Imagine a tollbooth at a bridge. Cars passing by the booth are expected to pay a 50 cent toll.
Mostly they do, but sometimes a car goes by without paying. The tollbooth keeps track of the
number of cars that have gone by, and of the total amount of money collected. Model this
tollbooth with a class called tollBooth. The two data items are a type unsigned int to hold the
total number of cars, and a type double to hold the total amount of money collected. A
constructor initializes both of these to 0. A member function called payingCar() increments the
car total and adds 0.50 to the cash total. Another function, called nopayCar(), increments the car
total but adds nothing to the cash total. Finally, a member function called display() displays the
two totals. Make appropriate member functions const. Include a program to test this class. This
program should allow the user to push one key to count a paying car, and another to count a
nonpaying car. Pushing the Esc key should cause the program to print out the total cars and total
cash and then exit.

Question #4
Explain the following terms in your own words with some code example.
Class, Object of class, data members, member functions, abstraction and abstract class, getter
and setter methods, Default constructor, Default copy constructor, constructor and data
validation, copy constructor and how it calls (all possible forms), Destructor, Function
overloading, constructor overloading, operator overloading.

S-ar putea să vă placă și