Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Question: Redefine CDAccount from Display 10.1 so that it is a class rather than a structure. Use the same member variables as in Display 10.1

Question:

Redefine CDAccount from Display 10.1 so that it is a class rather than a structure. Use the same member variables as in Display 10.1 but make them private. Include member functions for each of the following: one to return the initial balance, one to return the balance at maturity, on e to return the interest rate, and one to return the term. Include a constructor that sets all of the member variables to any specified values, as well as a default constructor. Also, include an input member function with one formal parameter of type istream and an output member function with one formal parameter of type ostream. Embed your class definition in a test program.

10.1 is as follows

#include using namespace std; struct CDAccount { double balance; double interest_rate; int term; //months until maturity }; void get_data(CDAccount& the_account); //postcondition: the_account.balance and the_account.interest_rate //have been given values that the user entered at the key board. int main() { CDAccount account; get_data(account); double rate_fraction, interest; rate_fraction = account.interest_rate/100.0; interest = account.balance*rate_fraction*(account.term/12.0); account.balance = account.balance + interest; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << "When your CD matures in " << account.term << " months, " << "it will have a balance of $" << account.balance << endl; return 0; } //uses iostream: void get_data(CDAccount& the_account) { cout << "Enter account balance: $"; cin >> the_account.balance; cout << "Enter account interest rate: "; cin >> the_account.interest_rate; cout << "Enter the number of months until maturity " << "(must be 12 or fewer months): "; cin >> the_account.term; } SAMPLE DIALOGUE Enter account balance: $100.00 Enter account interest rate: 10.0 Enter the number of months until maturity (must be 12 or fewer months): 6 When your CD matures in 6 months, it will have a balance of $105.00

Guidelines from Teacher

private member variables to hold the three values of a CD account

a default constructor that initializes the private member variables

a constructor that accepts three initial values for the private member variables

member functions to return the current value of each of the private member variables

a member function that calculates and returns the account balance at maturity based on the values in the three member variables.

a member function that accepts an argument of type istream and reads the three member values from the open input stream

a member function that accepts an argument of type ostream and writes a nicely formatted summary of the account values to that open output stream

For the sake of this assignment, your test program should only use cin to read and cout to write. Please write your input/output member functions so that they could accept an open file stream, but you don't need to demonstrate reading from or writing to files.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students explore these related Databases questions