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: 3773367 • 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

Program:

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
#include <iterator>
using namespace std;

struct PersonAcct // struct account holds customer info
{
int acct_num; // customer account number
string name; // customers name
double acct_bal; // customers account balance
};

int main()
{
   PersonAcct persons[10];
   int n=0;
   ifstream accFile("accounts.txt");
   if(!accFile)
   {
       cout<<endl<<" File not found";
       exit(0);
   }
   ifstream trFile("transactions.txt");
   if(!trFile)
   {
       cout<<endl<<" File not found";
       exit(0);
   }
   while(!accFile.eof())
   {
       accFile>>persons[n].acct_num;
       accFile>>persons[n].name;
       accFile>>persons[n].acct_bal;
       cout<<" "<<n;
       n++;
   }
   cout<<endl<<"Enter a month: ";
   string month;
   cin>>month;
   string filename="account_report_";
   filename.append(month);
   filename.append(".txt");
   ofstream outFile(filename.c_str());
   if(!outFile)
   {
       cout<<endl<<"File creation error";
       exit(0);
   }
   int num_withdrawals;
   int num_deposits;
   double deposited;
   double withdrawals;
   double init_bal;
   string record;
   int acc;
   while(!trFile.eof())
   {
       getline(accFile, record);
       cout<<record;
       //istringstream buf(record);
//istream_iterator<std::string> beg(buf), end;
//vector<std::string> tokens(beg, end);
string tokens[8];
   int k = 0;
   stringstream ssin(record);
   while (ssin.good() &){
ssin >> tokens[k];
++k;
}
acc=atoi(tokens[0].c_str());
cout<<" "<<acc;
num_withdrawals=0;
num_deposits=0;
deposited=0;
withdrawals=0;
for(int j=1;j<k;j++)
{
   string type=tokens[j].substr(0,1);
   if(type.compare("w")==0)
   {
       num_withdrawals++;
       withdrawals+=(double)atof(tokens[j].substr(1,tokens[j].size()).c_str());
           }
           if(type.compare("d")==0)
   {
       num_deposits++;
       deposited+=(double)atof(tokens[j].substr(1,tokens[j].size()).c_str());
           }
           cout<<"ok";
       }
      
       for(int i=0;i<n;i++)
       {
           if(persons[i].acct_num==acc)
           {
               outFile<<endl<<"Account Number : "<<persons[i].acct_num;
               outFile<<endl<<"Name: "<<persons[i].name;
               outFile<<endl<<"Beginning Balance : $"<<persons[i].acct_bal;
               init_bal=persons[i].acct_bal;
               break;
           }
       }
       outFile<<endl<<" Ending Balance : $"<<(init_bal-withdrawals+deposited);
       outFile<<endl<<" Amount Deposited : $"<<deposited;
       outFile<<endl<<" Number of Deposits : $"<<num_deposits;
       outFile<<endl<<" Amount Withdrawn : $"<<withdrawals;
       outFile<<endl<<" Number of Withdraws : $"<<num_withdrawals;
   }
   accFile.close();
   trFile.close();
   outFile.close();
   return 0;
}

//-----------------------------------

//input files

//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

//accounts.txt

123 daffy 34.67
345 goofy 123.89
639 sneezy 1945.76
890 dopey 12345667.90
666 grumpy 666.66

// you have to keep the input files iwhere your program reside.Output file will be created in the same folder.

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