Develop an algorithm to balance your checking account. The program should let yo
ID: 3550297 • Letter: D
Question
Develop an algorithm to balance your checking account. The program should let you enter the initial balance for the month, followed by a series of transactions. For each transaction entered, the program should echo-print the transaction data, the current balance for the account, and the total service charges. Service charges are $0.10 for a deposit and $0.15 for a check. If the balance drops below $500.00 at any point during the month, a service charge of $5.00 is assessed for the month. If the balance drops below $50.00, the program should print a warning message. If the balance becomes negative, an additional service charge of $1.00 should be assessed for each check until the balance becomes positive again. A transaction takes the form of a letter, followed by a blank and a float number. If the letter is a C, then the number is the amount of a check. if the letter is a D, then the number is the amount of a deposit. The last transaction consists of the letter E, with no number following it. A sample run might look like this:
The beginning balance:
879.46
C 400.00
Transaction:
Check in amount of $400.00
Current balance: $479.46
Service charge: Check --- $0.15
Service charge below $500 --- $5.00
Total service charges: --- $5.15
D 100.0
Transaction: Deposit in amount of $100.00
Current balance: $579.46
Service charge: Deposit --- $0.10
Total service charge; --- $5.25
E
Transaction: End
Current balance: $579.46
Total service charges: --- $5.25
Final balance: --- $574.21
You should use the above data and input them from a file and output the results to another file. Error checks should be done on all input values and proper error messages should be printed for invalid input. As usual, your program should use proper style and indentation, meaningful identifiers and constants, and appropriate comments. Also, be sure to check for data errors such as invalid transaction codes or negative amounts.
879.46
C 400.00
D 100.0
F 525.00
C 450.00
D 500.00
D 1000.00
C 2000.00
D 3000.00
D 3500.00
C 5500.00
C 500.00
B 200.00
C -235.00
D 250.00
H -500.00
D 500.00
E 0
**Note that function prototyping is not required.
** I will not tolerate the comments that imply me to head over to pastebin and end up having me pay more $$ for this question.
Explanation / Answer
please rate - thanks
partial output file-from your input file
#include<iostream>
#include<iomanip>
#include <fstream>
using namespace std;
int main ()
{double balance,amount,fee=0;
char type;
bool given=false;
char filename[30];
ifstream input;
ofstream output;
cout<<"what is the name of the input file you are using? ";
cin>>filename;
input.open(filename); //open file
if(input.fail()) //is it ok?
{ output<<"file did not open please check it ";
system("pause");
return 1;
}
cout<<"what is the name of the output file? ";
cin>>filename;
output.open(filename);
output<<setprecision(2)<<fixed;
input>>balance;
output<<"The beginning balance: "<<balance<<endl<<endl;
input>>type;
while(type!='E')
{input>>amount;
output<<type<<" "<<amount<<endl;
if(amount>0)
{
if(type=='C')
{output<<"Transaction: Check in amount of $"<<amount<<endl;
balance-=amount;
output<<"Current balance: $"<<balance<<endl;
fee+=.15;
output<<"Service charge: Check - $0.15 ";
if(balance<500&&!given)
{fee+=5;
given=true;
output<<"Service charge: Below $500 - $5.00 ";
}
if(balance-fee<50) //fee will bring you below
output<<"***You have a low balance < $50.00*** ";
if(balance-fee<0) //fee may make you negative
{fee+=10;
output<<"Service charge: negative balance ";
}
output<<"Total service charges: $"<<fee<<endl;
}
else if(type=='D')
{output<<"Transaction: Deposit in amount of $"<<amount<<endl;
balance+=amount;
output<<"Current balance: $"<<balance<<endl;
fee+=.1;
output<<"Service charge: deposit - $0.10 ";
output<<"Total service charges: $"<<fee<<endl;
}
else
output<<"Invalid transaction ";
}
else
output<<"Invalid amount ";
output<<endl;
input>>type;
}
output<<type<<endl;
output<<"Transaction: End ";
output<<"Current balance: $"<<balance<<endl;
balance-=fee;
output<<"Total service charges: $"<<fee<<endl;
output<<"Final balance: $"<<balance<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.