Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROJECT DESCRIPTION Continue your code from Lab 6 and include this time all run time transaction occuring in main to be now written to a

PROJECT DESCRIPTION

Continue your code from Lab 6 and include this time all run time transaction

occuring in main to be now written to a file. Example of transactional data

to be written to a file would be the account number, account type (checking or

savings) and any initial balance. Another transaction can be the deposit amount

into the account noting the account number and account type and another

transaction can be the withdrawal amount into the account noting the account

number and account type.

Call your output file accounts.dat.

STEP 1 Implement code logic to write any transactional data to a file.

For each transaction in main, write out transactions to a file called accounts.dat. No need to recompute the balance after each transaction. Include your name at the end of the file.

STEP 2 Take a snapshot of your accounts.dat file.

Paste the snapshot of your file in Word. Include your source file(s) as well.

The code from the previous lab is :

#include #include using namespace std;

class BankAccount { public: BankAccount(int = 0, float = 0); void deposit(float amount) { bal += amount; } int account_num() const { return acctnum; } float balance() const { return bal; } virtual void print() = 0;

protected: int acctnum; float bal; }; BankAccount::BankAccount(int num, float ibal) { acctnum = num; bal = ibal; }

const float MIN_BALANCE = 1000.00; const float SERVICE_CHARGE = 0.005;

class checkingAccount : public BankAccount { public: void withdraw(float amount); void print(); checkingAccount(int acctNumber, float _bal);

protected: float minimumBalance; }; checkingAccount::checkingAccount(int acctNumber, float _bal) : BankAccount(acctNumber, _bal) { acctnum = acctNumber; bal = _bal; minimumBalance = MIN_BALANCE; } void checkingAccount::withdraw(float amount) { float serviceCharge = SERVICE_CHARGE * amount; if (bal - amount < 0) cout << "Not enough money in the account." << endl; else if (bal - amount < minimumBalance) { if (bal - amount - serviceCharge < 0) { cout << "After this transaction, the balanace will be " << "below the minimum balance." << endl << "However account does not have enough money " << "to process the transaction and apply service charge." << endl << "Transaction denied!" << endl; } else { cout << "After this transaction, the balanace will be " << "below the minimum balance." << endl << "Service charges will apply." << endl; bal = bal - amount - serviceCharge; cout << fixed << setprecision(2) << amount << " successfully withdrawn and Service charges of " << serviceCharge << " are levied "; } } else { bal = bal - amount; cout << fixed << setprecision(2) << amount << " successfully withdrawn "; } } void checkingAccount::print() { cout << fixed << setprecision(2); cout << "Account Type: Checking Account " << "Account Number: " << acctnum << " " << "Balance: " << bal << " "; }

class savingsAccount : public BankAccount { public: savingsAccount(int acctNumber, double _bal); void withdraw(double amount); void print();

protected: double minimumBalance; }; savingsAccount::savingsAccount(int acctNumber, double _bal) : BankAccount(acctNumber, _bal) { minimumBalance = MIN_BALANCE; } void savingsAccount::withdraw(double amount) { if (bal - amount < 0) { cout << "Insufficient balance. Transaction denied! "; } else if (bal - amount < minimumBalance) { cout << "After this transaction, the balanace will be " << "below the minimum balance." << endl << "Transaction denied!!." << endl; } else { bal -= amount; cout << fixed << setprecision(2) << amount << " successfully withdrawn "; } } void savingsAccount::print() { cout << fixed << setprecision(2); cout << "Account Type: Savings Account " << "Account Number: " << acctnum << " " << "Balance: " << bal << " "; }

// driver function int main() { checkingAccount c(5678, 3000); savingsAccount s(1234, 2000);

cout << " Withdrawing 1000 from Checking Account.... "; c.withdraw(1000); cout << " Withdrawing 1500 from Checking Account.... "; c.withdraw(1500);

cout << " Withdrawing 500 from Savings Account.... "; s.withdraw(500); cout << " Withdrawing 1000 from Savings Account.... "; s.withdraw(1000);

BankAccount *accounts[2]; accounts[0] = &c; accounts[1] = &s; cout << " "; for (int i = 0; i < 2; i++) { accounts[i]->print(); }

return 0; } Also if possible please answer these questions

  1. If you were able to read data from accounts.dat, what kind of reports can be generated. Name a few possible feasible reports.
  2. How would you adjust transactional record data written to the file if you had to include any fees charged for any penalties.
  3. How would you adjust transactional record data written to the file if you had to include some flag representing a transaction dropping below 100.
  4. Explain how would you read from your file and show a report on all checking transactions followed by all savings transactions.
  5. Explain how would you read from your file and show a report on ending balances on all checking transactions followed by all savings transactions by account number.

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

Why is the System Build Process an iterative process?

Answered: 1 week ago