Answer to Question #210009 in C++ for ASAP

Question #210009

Topic: Files and Streams

Codes discussed will be posted here. Write your conclusion on the File&stream discussion. 


Filename: "Ch5_money.txt"

Given problem:

467343 23750.40
W 250.00
D 1200.00
W 75.00
W 375.00
D 580.00
I 245.50
W 400.00
W 600.00
D 450.50
W 35.65

*Note: Need the proper codes

*Note need proper codes and conclusion on how its done and about the results. And please give the proper solution and explanation.

*Note: Give your conclusion, one paragraph will do. And give a reason why you use that code for this given problem, and based it on File and Stream topics



1
Expert's answer
2021-06-25T05:21:59-0400
// ******************************************************
// Program -- Checking Account Balance
// This program calculates a customer's checking account
// balance at the end of the month.
// ******************************************************
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

const double minimumBalance = 1000.00;
const double serviceCharge = 25.00;

int main()
{
    // Declare and initialize variables
    int acctNumber;
    double beginningBalance;
    double accountBalance;

    double amountDeposited = 0.0;
    int numberOfDeposits = 0;
    double amountWithdrawn = 0.0;
    int numberOffWithdrawals = 0;

    double interestPaid = 0.0;

    char transactionCode;
    double transactionAmount;

    bool isServiceCharged = false;

    ifstream infile;
    ofstream outfile;

    infile.open("a:Ch5_money.txt");

    if (!infile)
    {
        cout << "Cannot open input file" << endl;
        cout << "Program terminates!!!" << endl;
        return 1;
    }

    outfile.open("a:Ch5_money.out");

    outfile << fixed << showpoint;
    outfile << setprecision(2);

    cout << "Processing data" << endl;

    infile >> acctNumber >> beginningBalance;

    accountBalance = beginningBalance;

    infile >> transactionCode >> transactionAmount;

    while (infile)
    {
        switch (transactionCode) {
            case 'D':
            case 'd':
                accountBalance += transactionAmount;
                amountDeposited += transactionAmount;
                numberOfDeposits++;
                break;
            case 'I':
            case 'i':
                accountBalance += transactionAmount;
                interestPaid += transactionAmount;
                break;
            case 'W':
            case 'w':
                accountBalance -= transactionAmount;
                amountWithdrawn += transactionAmount;
                numberOffWithdrawals++;
                if ((accountBalance < minimumBalance) && (!isServiceCharged))
                {
                    accountBalance -= serviceCharge;
                    isServiceCharged = true;
                }
                break;
            default:
                cout << "Invalid transaction code" << endl;
        }
        infile >> transactionCode >> transactionAmount;
    }

    outfile << "Account Number: " << acctNumber << endl;
    outfile << "Beginning Balance: $" << beginningBalance << endl;
    outfile << "Ending Balance: $" << accountBalance << endl << endl;
    outfile << "Intersect Paid: $" << interestPaid << endl << endl;
    outfile << "Amount Deposited: $" << amountDeposited << endl;
    outfile << "Number of Deposits: " << numberOfDeposits << endl << endl;
    outfile << "Amount Withdrawn: $" << amountWithdrawn << endl;
    outfile << "Number of withdrawals: " << numberOffWithdrawals << endl << endl;
    
    if (isServiceCharged) 
    {
        outfile << "Service Charge: $" << serviceCharge << endl;
    }
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS