You are tasked with writing a program which will write a monthly account summary
ID: 3772927 • Letter: Y
Question
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++
Need other solutions provide does not help
Explanation / Answer
#include <iomanip>
#include <stdio.h>
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
#define withdrawl (isit == 'W' || isit == 'w' )
#define deposit ( isit== 'D' || isit == 'd' )
struct PersonAcct
{
int acct_num;
double acct_bal;
string name;
};
string getAccountFileName();
void printReport(int a, int w, int d, double eb, double bb, double ad, double aw, string name);
void errorCheck();
int main()
{
ifstream accounts;
ifstream transactions;
string fileName;
string acct = "accounts.txt";
string trans = "transactions.txt";
string trans2 = "monthly_transactions.txt";
int const PEEPS = 50;
int const U = PEEPS;
int acnum2[PEEPS];
int acnum[PEEPS];
string name[PEEPS];
double bBalance[PEEPS];
PersonAcct p[U];
string line, line2;
int amountline = 0;
char isit;
int dCount = 0;
int wCount = 0;
accounts.open(acct.c_str(), ios::in);
if (!accounts)
{
cerr << "Your Accounts.txt file was not automatically found " << endl << endl;
fileName = getAccountFileName();
accounts.open(fileName.c_str(), ios::in);
if (!accounts)
{
errorCheck();
}
}
while (accounts)
{
for (int i = 0; i < PEEPS; i++)
{
accounts >> acnum[i] >> name[i] >> bBalance[i];
p[i].acct_num = acnum[i];
p[i].name = name[i];
p[i].acct_bal = bBalance[i];
}
accounts.clear();
accounts.seekg(0);
while (getline(accounts, line))
{
amountline++;
}
accounts.close();
}
transactions.open(trans.c_str(), ios::in);
if (!transactions)
{
cerr << "Your Transactions.txt file was not automatically found " << endl << endl;
transactions.open(trans2.c_str(), ios::in);
if (!transactions)
{
cerr << "Still not found one more try : " << endl;
}
fileName = getAccountFileName();
transactions.open(fileName.c_str(), ios::in);
if (!transactions)
{
errorCheck();
}
}
transactions.get(isit);
while (transactions)
{
cout << isit;
transactions.get(isit);
if (isit != ' ' || ' ')
{
if (deposit)
{
dCount++;
cout << dCount;
}
if (withdrawl)
{
wCount++;
cout << wCount;
}
}
}
transactions.close();
int persons = 0;
persons = amountline-1;
for (int counter = 0; counter < persons; counter++) // printer
{
cout << fixed << setprecision(2) << p[counter].acct_num << " " << p[counter].name
<< " " << p[counter].acct_bal << " ";
}
system("pause");
return 0;
}
string getAccountFileName()
{
string fName;
cout << "Please enter the fully qualified name of the" << endl
cin >> fName;
cout << endl;
return fName;
}
string getTransactionsFileName()
{
string fName;
cout << "Please enter the fully qualified name of the " << endl
cin >> fName;
cout << endl;
return fName;
}
void printReport(const int AccoutNumber,
const int NumberOfWithdrawls,
const int NumberOfDeposits,
const double BalanceEnd,
const double BalanceBegin ,
const double DepositAmount,
const double WithdrawlAmount,
const std::string& name)
}
void errorCheck()
{
cerr << "file is still not found" << endl << endl;
system("pause");
exit(0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.