You guys, i need your help with this project. Thank you in advance you are taske
ID: 3548343 • Letter: Y
Question
You guys, i need your help with this project. Thank you in advance
you are tasked with writing a program which will write a monthly account summary of customer's transaction. The monthly transactions are stored in a file called transactions.txt in the following form
123 d45.10 d50.45 d.198.56 w45.67
the first entry is the acount number; the rest if the entry begins with a d is deposit, if it begins with a w its withdrawal
the customer database is stored in another file , acounts.txt which has the entry of the form
123 daffy 34.67
which contains customer's acount number, their name, current balance respectively
Your program will write a report in the following form
Acoutn number :123
Name: daffy
Beginning balance: $34.67
Ending balance: $283.11
Amount deposited: $294.11
Number of deposits: $3
Amount withdrawn: $45.67
Number of withdrawals $ 1
You must use the following structure to hold the data of each customer:
struct PersonAcc //struct acount holds customer info
{
int acc_num; // customer account number
string name; //customers name
int acct_bal; // customers account balance
};
Explanation / Answer
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
struct PersonAcc //struct acount holds customer info
{
int acc_num; // customer account number
string name; //customers name
int acct_bal; // customers account balance
};
PersonAcc customer;
int main()
{
/*************************************************************/
/** Declare variables **/
/*************************************************************/
ifstream trans; //transactions.txt
ifstream account; //accounts.txt
char DorW;
//Deposit info
int numDep = 0;
float Dep = 0;
float totDep = 0;
//Withdrawl info
int numWdrw=0;
float Wdrw = 0;
float totWdrw = 0l;
//Final balance
float endBal;
/*************************************************************/
/** Opening the transactions.txt **/
/*************************************************************/
trans.open ("transactions.txt"); //Actual location of file
if (trans.is_open()){
//Get account number
trans>>customer.acc_num;
//cout<<customer.acc_num<<" ";
//Get withdrawals and deposits
while ( !trans.eof()){
trans.ignore(256,' ');
DorW = trans.get();
//cout<<DorW<<" ";
if (DorW == 'd' || DorW == 'D'){
trans>>Dep;
//cout<<"Deposit: "<<Dep<<" ";
totDep +=Dep;
//cout<<totDep<<" ";
numDep++;
}
else{
trans>>Wdrw;
//cout<<"Withdrawal: "<<Wdrw<<" ";
totWdrw +=Wdrw;
//cout<<totWdrw<< " ";
numWdrw++;
}
}
trans.close();
//cout<<numDep<<" "<<numWdrw;
}
else{
cout << "Unable to open file";
}
/*************************************************************/
/** Opening accounts.txt **/
/*************************************************************/
account.open ("accounts.txt"); //Actual location of file
if (account.is_open()){
account>>customer.acc_num;
//cout<<customer.acc_num<<" ";
account.ignore(256,' ');
account>>customer.name;
//cout<<customer.name<<" ";
account.ignore(256,' ');
account>>customer.acct_bal;
//cout<<customer.acct_bal<<" ";
account.close();
}
else{
cout << "Unable to open file";
}
//Calculate final balance
endBal = customer.acct_bal + totDep - totWdrw;
/*************************************************************/
/** Output **/
/*************************************************************/
cout<<endl<<endl;
cout<<"Account number: "<<customer.acc_num<<endl;
cout<<"Name: "<<customer.name<<endl;
cout<<"Beginning balance: $"<<customer.acct_bal<<endl;
cout<<"Ending balance: $"<<endBal<<endl;
cout<<"Amount deposited: $"<<totDep<<endl;
cout<<"Number of deposits: "<<numDep<<endl;
cout<<"Amount withdrawn: $"<<totWdrw<<endl;
cout<<"Number of withdrawls: "<<numWdrw<<endl;
return 0;
}
/*
Account number: 123
Name: daffy
Beginning balance: $34.67
Ending balance: $283.11
Amount deposited: $294.11
Number of deposits: 3
Amount withdrawn: $45.67
Number of withdrawals: 1
*/
// 123 d45.10 d50.45 d198.56 w45.67 //
// 123 daffy 34.67 //
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.