Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Modify program 1 to include a function getEndBalance that computes the ending balance of a savings account. The function takes three arguments that hold

1) Modify program 1 to include a function getEndBalance that computes the ending balance of a savings account. The function takes three arguments that hold the starting balance, total deposits, total withdrawals and returns the ending balance. The ending balance is printed in main.

This is my program 1 below. Keep everything in the same format of c++ as it is in program 1

Program1: Write a program that calculates the ending balance of several savings accounts. The program reads information about different customers accounts from an input file, accounts.txt. Eachrow in the file contains account information for one customer. This includes: the account number, account type (premium, choice, or basic account), starting balance, total amount deposited, and total amount withdrawn.

Your program should:

  • - open the file and check for successful open,

  • - then calculate the ending balance for each customer account. The calculated data must

    be saved in an output file, accountsOut.txt, in a neat format as shown below. You may assume that the interest is 5% for premium accounts, 3% for choice accounts, and 1% for basic accounts.

    You MUST use a named constant for the interest rates. Since the results displayed are monetary values, your output must be displayed with two decimal places of precision. Be sure decimals line up when you output the final accounts information. And do not forget to close the files when done with them.

#include #include #include using namespace std;

//Constants const double Premium=0.05; const double Choice=0.03; const double Basic=0.01;

int main() { ifstream fin; ofstream fout; fin.open("accounts.txt");

if(!fin) { cout<<"Cannot open the input file"<

fout.open("accountsOut.txt");

}

int account; string type; double Startbalance; double deposit; double withdrawal; double endbalance;

fout<>account; fin>>type; fin>>Startbalance; fin>>deposit; fin>>withdrawal;

while(fin) { endbalance=Startbalance+deposit-withdrawal; if(type=="Premium") endbalance=endbalance+(endbalance*Premium); else if(type=="Choice") endbalance=endbalance+(endbalance*Choice); else endbalance=endbalance+(endbalance*Basic); fout<>account; fin>>type; fin>>Startbalance; fin>>deposit; fin>>withdrawal; } fin.close(); fout.close(); return 0;

}

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

Step: 3

blur-text-image

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

Persuading Your Audience Strategies for

Answered: 1 week ago