Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Review and run the code in the attached checkRegister.cpp file. Use the data in checkIn.dat for user input. Change the program so it uses data

Review and run the code in the attached checkRegister.cpp file. Use the data in checkIn.dat for user input.

Change the program so it uses data from a file rather than user entries to process a customers bank transactions. The file with the beginning balance and the customer transactions is named checkIn.dat. Open this file so you can see how the data is set up. The first field is the beginning balance followed by a series of records with transaction codes and amounts.

Make the following changes:

Change the code so that the program reads the balance and transactions from checkIn.dat using the provided functions. The code should work no matter how many records are in the file. Use a structure to define the record. The record structure has two members: code and amount. Eliminate the user prompts currently in the code, but still list the transactions as displayed by checkRegister.cpp.

Keep the cout statements in the program as is because the project should still list the transactions as well as the totals at the end.

Change the getBegBal function to read the beginning balance from the file. Add a call to displayBal after reading the beginning balance from the file so the beginning balance is displayed. You need to do this because you deleted the prompt for beginning balance. The getData function should be changed to get the data from the file instead of the user, and return a structure.

Write the final balance to an output file. Name this file checkOut.dat

Display the following dollar totals at the end of the report.

o Credits (additions to the account deposits)

o Debits (deductions from the account checks and ATM withdrawals)

o Service charges (ATM charges and negative balance charges)

Display the number of transactions in the file (this is a counter).

Use a structure definition for the totals including the transaction counter. Update the total structure members in main. Add a function to display the totals, sending the totals structure.

checkRegister.cpp // Author: // Source file: // Description: // Compiler used:

#include #include using namespace std;

// Function Prototypes void displayTitle(); double getBegBal(); void displayBal(double); void getData(int& , double&); double processCheck(double, double); double processDeposit(double, double); double processATM(double, double); double processSvcChg(double);

//Global Constants const double CHARGE = 10, ATMFEE = 2;

int main() { //Variable Declarations int transCode; double balance, transAmt;

cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2);

displayTitle(); balance = getBegBal(); getData(transCode, transAmt); while(transCode != 0) { switch(transCode) { case 1: balance = processCheck(balance, transAmt); break; case 2: balance = processDeposit(balance, transAmt); break; case 3: balance = processATM(balance, transAmt); break; } displayBal(balance); if(balance < 0) balance = processSvcChg(balance); getData(transCode, transAmt); } return 0; }

void displayTitle() { cout << " Check Register "; }

double getBegBal() { double bal; cout << " Enter beginning balance "; cin >> bal; return bal; }

void displayBal(double x) { cout << "\t\tBalance = $" << setw(10) << x; }

void getData(int& code, double& amt) { cout << " Enter transaction code (0 to exit) "; cin >> code; if(code > 0) { cout << " Enter transaction amount "; cin >> amt; } }

double processCheck(double bal, double amt) { cout << " Check = " << setw(10) << amt; return (bal - amt); }

double processDeposit(double bal, double amt) { cout << " Deposit = " << setw(10) << amt; return (bal + amt); } double processATM(double bal, double amt) { cout << " ATM = " << setw(10) << amt; bal = bal - amt; displayBal(bal); bal = bal - ATMFEE; cout << " ATM Fee = " << setw(10) << ATMFEE; return (bal); } double processSvcChg(double bal) { cout << " Service chg =" << setw(8) << CHARGE; bal = bal - CHARGE; displayBal(bal); return (bal); }

checkin.dat

2000 1 1225.72 1 463.81 3 200 1 632 2 1500 1 300 2 1800

payfileFunction.cpp

#include #include #include using namespace std;

struct payRec { int number; char code; double hrs; };

payRec BuildRec(ifstream&);

void DisplayRec(payRec);

int main() { payRec emp; ifstream inFile; inFile.open("e:\\pay.dat"); //insert code for file problem

while(! inFile.eof()) { emp = BuildRec(inFile); DisplayRec(emp); }

inFile.close();

system("pause"); return 0; }

payRec BuildRec(ifstream& inFile) { payRec temp; inFile >> temp.number >> temp.code >> temp.hrs; return temp; } void DisplayRec(payRec temp) { cout << temp.number << setw(4) << temp.hrs << endl; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Answered: 1 week ago

Answered: 1 week ago

Question

Understand why customers are loyal to a particular service firm.

Answered: 1 week ago