CAN SOME GOOD EXPERT PLEASE ANSWER THIS ?. Over 8 solutions has either been flat
ID: 3773397 • Letter: C
Question
CAN SOME GOOD EXPERT PLEASE ANSWER THIS ?. Over 8 solutions has either been flat wrong or copy from google. If you do not have a solution . I will be glad you do not guess or post a scam. Thanks
You are tasked with writing a program which will write a monthly account summary of customers' transactions at the bank at which you are employed. The monthly transactions are stored in a file called
transactions.txt in the follow form: 123 d45.10 d50.45 d198.56 w45.67
The first entry is the account number; the remainder of the line, variable in length, contains all the transactions of the particular customer for the month: If the entry begins with a d, the number that follows is the amount of deposi If it begins with a w, the number that follows is the amount of withdraw.
The customer "database" is stored in another file, accounts.txt which has entries of the form 123 daffy 34.67 where each line contains the customer's account number then their name, followed by the current account balance at the beginning of the month.
Your program will write report in the following form ( given the above data )
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 Withdraws : 1
The report is to be written to a file called account_report_MONTH.txt, where MONTH is a user entered month name CODE:
Your program will read from the following files: a file containing the listing of all transactions for the month; a file containing a list of all customers, along with their account ids. You must use the following structure to hold the data of each customer:
struct PersonAcct // struct account holds customer info
{ int acct_num; // customer account number
string name; // customers name
int acct_bal; // customers account balance };
Note: Feel free to construct your own files to test/debug you program Please provide a screenshot of where the file is located on the directory.
Here are the two text files:
accounts.txt 123 daffy 34.67 345 goofy 123.89 639 sneezy 1945.76 890 dopey 12345667.90 666 grumpy 666.66
transactions.txt 123 d45.10 d50.45 d198.56 w45.67 345 w34.00 d4.56 w45.13 d23.23 w23.12 639 d1000.34 d1234.56 w34.33 w345.87 w22.13 890 d345.67 d123.67 d45.99 d45.99 w34.77 666 d66.60 d666.66 d6.66 d66.6 d6666.66
Also specify the directory where the text files are save>
for example C:DRIVE USE VISUAL STUDIO C++ Can someone provide a credible answer. Every other one is a fluke or a copy form google forum
Explanation / Answer
Solution: bankaccount.cpp
---------------------------------------------------------
//This program process accounts and transactions information of a bank and prepares accounts report
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <stdlib.h>
#define MAX_ACCOUNTS 100 //maximum no. of accounts
using namespace std;
string accounts_filename="./src/accounts.txt"; //accounts file
string transactions_filename="./src/transactions.txt"; //transaction file
//structure to store customer account information
typedef struct // struct account holds customer info
{
int acct_num; // customer account number
string name; // customers name
double acct_bal; // customers account balance
} PersonAcct;
//global variables to hold accounts' and transactions' information
int total_accounts=0; //total no. of accounts in bank
PersonAcct accounts[MAX_ACCOUNTS]; //array to store accounts info
string transactions[MAX_ACCOUNTS]; //array to store transactions info
int total_transactions=0; //total transactions held
//function to read accounts info from accounts file
void read_accounts_info(string filename)
{
ifstream accounts_file(filename.c_str()); //stream to read from file
int i=0;
//reads from file, if it is open.
if(accounts_file.is_open())
{
string line;
while(getline(accounts_file,line))
{
stringstream ss(line);
int acc_no;
string name;
double balance;
//reads customer info
ss>>acc_no>>name>>balance;
accounts[i].acct_num=acc_no;
accounts[i].name=name;
accounts[i].acct_bal=balance;
i++;
total_accounts++;
}
accounts_file.close(); //closes the file
}
else
cout<<"Error opening file!"<<endl;
}
//function to read transactions
void read_transactions_info(string filename)
{
ifstream transactions_file(filename.c_str()); //stream to read from file
int i=0;
//reads from file, if it is open.
if(transactions_file.is_open())
{
string line;
while(getline(transactions_file,line))
{
transactions[i]=line;
i++;
total_transactions++;
}
transactions_file.close();
}
else
cout<<"Error opening file!"<<endl;
}
//function to print accounts info
void print_accounts_info()
{
for(int i=0;i<total_accounts;i++)
{
cout<<"Name:"<<accounts[i].name
<<", Acc. No.:"<<accounts[i].acct_num
<<", Balance:"<<accounts[i].acct_bal
<<endl;
}
}
//function to print transactions info
void print_transactions_info()
{
for(int i=0;i<total_transactions;i++)
{
cout<<transactions[i]<<endl;
}
}
//function to prepare transaction report
void prepare_accounts_report()
{
//loop to process transactions
for(int i=0;i<total_transactions;i++)
{
string line=transactions[i]; //captures transaction string
stringstream ss(line);
int acc_no;
//extracts account no.
ss>>acc_no;
double total_deposits=0.0;
double total_withdrawls=0.0;
double final_balance=0.0;
int num_deposits=0;
int num_withdrawls=0;
//loop to process deposits and withdrawls
while(ss.good())
{
string trans;
ss>>trans;
if(trans.at(0)=='d')
{
trans=trans.substr(1,trans.length()-1);
total_deposits+=atof(trans.c_str());
num_deposits++;
}
else if(trans.at(0)=='w')
{
trans=trans.substr(1,trans.length()-1);
total_withdrawls+=atof(trans.c_str());
num_withdrawls++;
}
}
//calculates final balance and prints account report of a customer
if(acc_no==accounts[i].acct_num)
{
final_balance=accounts[i].acct_bal+total_deposits-total_withdrawls;
cout<<"Account Number: "<<accounts[i].acct_num<<endl;
cout<<"Name:"<<accounts[i].name<<endl;
cout<<"Beginning Balance:$"<<accounts[i].acct_bal<<endl;
cout<<"Ending Balance:$"<<final_balance<<endl;
cout<<"Amount deposited:$"<<total_deposits<<endl;
cout<<"Total deposits:"<<num_deposits<<endl;
cout<<"Amount withdrawn:$"<<total_withdrawls<<endl;
cout<<"Total withdrawls:"<<num_withdrawls<<endl;
}
}
}
//main() function
int main() {
cout<<"Reading accounts' information..."<<endl;
read_accounts_info(accounts_filename);
cout<<"Accounts' information read!"<<endl;
cout<<"Total accounts:"<<total_accounts<<endl;
cout<<"Accounts' info:"<<endl;
print_accounts_info();
cout<<"Reading transactions' information..."<<endl;
read_transactions_info(transactions_filename);
cout<<"Transactions' information read!"<<endl;
cout<<"Total transactions:"<<total_transactions<<endl;
cout<<"Transactions info:"<<endl;
print_transactions_info();
cout<<"Preparing accounts' information..."<<endl;
cout<<"Accounts report:"<<endl;
prepare_accounts_report();
return 0;
}
--------------------------------------------
Note: I have just printed the accounts' report. You can modify function 'prepare_accounts_report()' accordingly to store the result to a file.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.