Assign 04 – Creating Classes & Objects
How to submit your assignment
You need to submit a single pdf document with the following contents:
- Three files (main.cpp, assign_4.h, assign_4.cpp)
- Screenshots of source code & sample run(s)
- UML diagram for each class
1. (Bank Account) Design a class named Account that contains:
A string data field for customer’s name.
An int data field named id for the account.
A double data field named balance for the account.
A no-arg constructor that creates a default account with id 0, and balance 0
A parametrized constructor
The accessor(getters) and mutator(setters) functions for id, and balance
A function named withdraw(amount) that withdraws a specified amount from the
account.
A function named deposit(amount) that deposits a specified amount to the
account.
Draw the UML diagram for the class. Implement the class.
Create an array of objects of size 5 and load the data from the file with the following contents.
data.txt
Alexander Bowman
1234
845.90
Bianca Bradley
8888
550.49
Cindy Chen
7777
1000.55
Diane Zhang
6666
854.99
Elizabeth May
5555
1234.56
Teacher: Mr. Saleem, Computer Studies, EHSS 1
Deposit $2000.00 to each account and then withdraw $400.00 from each account.
2. (Quadratic Equation) Design a class named QuadraticEquation for a quadratic equation
ax2 + bx + c = 0. The class contains:
Data fields a, b, and c that represent three coefficients.
A constructor for the arguments for a, b, and c.
Three get functions for a, b, and c.
A function named getDiscriminant() that returns the discriminant, which is b2 - 4ac.
The functions named getRoot1() and getRoot2() for returning two roots of the
equation:
These functions are useful only if the discriminant is nonnegative. Let these functions
return 0 if the discriminant is negative.
Draw the UML diagram for the class. Implement the class. Write a test program that
prompts the user to enter values for a, b, and c, and displays the result based on the
discriminant. If the discriminant is positive, display the two roots. If the discriminant is 0,
display the one root. Otherwise, display "The equation has no real roots".
Write a client code in the main function to test your classes.
Teacher: Mr. Saleem, Computer Studies, EHSS 2
Rubric
Knowledge [5]
1. Program runs without any syntax error(s)
2. Program read in the input correctly
3. Program process the output correctly
4. Replit link is clickable
5. Neat and clean screenshots of source code and sample run are taken
Communication [5]
1. Program header is included
2. Major blocks of code are commented
3. Descriptive identifiers names are used
Application [5]
1. Program produces correct output
2. All calculations are correct
3. Program has no logical errors
4. UML diagram(s) are correct
Thinking [5]
1. Logical blocks are separated by a blank line
2. Program’s logic is easy to read
3. A user-friendly main function allows the user to test each class
Note:
*Late submissions will lose marks
*In-class progress must be demonstrated to verify authenticity of work or marks may also be
deducted
Teacher: Mr. Saleem, Computer Studies, EHSS 3