Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem statement: You are tasked with writing a program which will write a mont

ID: 3773480 • Letter: P

Question

Problem statement:
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

--------------------------------------------------------------------------------------

specify the directory where the text files are save> for example C:DRIVE

Also note to anyhelp out there if you do not have screen shot of your code output.

USE VISUAL STUDIO C++

THANKS

Explanation / Answer

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <string>
using namespace std;
struct PersonAcct // struct account holds customer info
{
int acct_num; // customer account number
string name; // customers name
int acct_bal; // customers account balance
};
void funcAccounts(PersonAcct &accountStructure, ifstream &account);
void funcTransactions(PersonAcct &accountStructure, ifstream &transaction , double &withdrawls, double &deposits, int &num_of_deposits, int &num_of_withdrawls);
void outReport(PersonAcct &accountStructure, ofstream &monthlyReport, int num_of_withdrawls, int num_of_deposits, double withdrawls, double deposits);
string getMonth();
int getAcctNum();
int main()
{
ifstream account;           //the accounts.txt file stream
ifstream transaction;       //the transactions.txt file stream
ofstream monthlyReport;       //the output report
string month;               //the month
PersonAcct accountStructure;//structure, the current account
int prog = 'y';
double w, d;               //the value of each
int withdrawls, deposits;   //number of each
while(prog == 'y')    
{        
accountStructure.acct_num = getAcctNum();
month = getMonth();       //input to be taken
account.open("accounts.txt");       //files to open
transaction.open("transactions.txt");
monthlyReport.open("account_report_" + month + ".txt");   
if( !account || !transaction ) // test for unsuccessful file opening    
{        
cerr << "Cannot open file: " << "accounts.txt or transactions.txt" << endl << endl;
exit (0);
}
funcAccounts(accountStructure, account); // from account.txt        
funcTransactions(accountStructure, transaction, w, d, withdrawls, deposits);
cout << "NO PROBLEM BEFORE OUTREPORT";
outReport(accountStructure, monthlyReport, withdrawls, deposits, w, d);
account.close();       //files to open
transaction.close();
monthlyReport.close();
cout << "Would you like to run the program again? y or n ";
cin >> prog;
cout << endl << endl;
}
return 0;
  
}   
/************************************************* / / / / / / / / / /*************************************************/   
string getMonth()
{
string month;
cout << "What month are we making a report file for? ";
cin >> month;
cout << endl << endl;
return month;
  
}
/************************************************* / / / / / / / / / /*************************************************/   
int getAcctNum()
{
int accountNum;
cout << "What is the account number? ";
cin >> accountNum;    
cout << endl << endl;   
return accountNum;
}
/************************************************* / / / / / / / / / /*************************************************/   
void funcAccounts(PersonAcct &accountStructure, ifstream &account)
{
int placeHolder1;
while(!account.eof())
{        
account >> placeHolder1;
if(placeHolder1 == accountStructure.acct_num)    
{
account >> accountStructure.name;
account >> accountStructure.acct_bal;        
  
}    
cout << "HI!";
}
}
void funcTransactions(PersonAcct &accountStructure, ifstream &transaction, double &withdrawls, double &deposits, int &num_of_deposits, int &num_of_withdrawls)
{    
int placeHolder2;
char ch = 'k'; //to set a default value
double value = 0;  
//for adding/subtracting values
deposits = 0.0; //initializations
withdrawls = 0.0;
num_of_deposits = 0;
num_of_withdrawls = 0;
while(!transaction.eof())
{        
transaction >> placeHolder2;
if(placeHolder2 == accountStructure.acct_num)
{    
while(ch != ' ')
{
transaction.get(ch);
if(ch == 'd')    
{
transaction >> value;
deposits += value;    
num_of_deposits++;
value = 0;
}
if(ch == 'w')
{
transaction >> value;
withdrawls += value;            
num_of_withdrawls++;    
value = 0;
}
}
}
}
}
/************************************************* / / / / / / / / / /*************************************************/
void outReport(PersonAcct &accountStructure, ofstream &monthlyReport, int num_of_withdrawls, int num_of_deposits, double withdrawls, double deposits)
{
double endBalance = accountStructure.acct_bal - withdrawls + deposits;
monthlyReport << "HI!";
monthlyReport.width(26);
monthlyReport << "Account Number : " << right << accountStructure.acct_num << endl;
monthlyReport.width(26);
monthlyReport << "Name : " << right << accountStructure.name << endl;
monthlyReport.width(26);
monthlyReport << "Beginning Balance : " << right << accountStructure.acct_bal << endl;
monthlyReport.width(26);
monthlyReport << "Ending Balance : " << right << endBalance << endl;
monthlyReport.width(26);
monthlyReport << "Amount Deposited : " << right << deposits << endl;
monthlyReport.width(26);    
monthlyReport << "Number of Deposits : " << right << num_of_deposits << endl;
monthlyReport.width(26);
monthlyReport << "Amount Withdrawn : " << right << withdrawls << endl;    
monthlyReport.width(26);
monthlyReport << "Number of Withdraws : " << right << num_of_withdrawls << endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote