1 Replies - 307 Views - Last Post: 04 August 2014 - 11:18 AM Rate Topic: -----

#1 jesslich  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-August 14

Banking Program

Posted 04 August 2014 - 08:20 AM

Trying to design a banking program. So, the program starts by having the user enter his/her initial amount in the bank. Then, a menu displays asking if the user wants to make a deposit, withdrawal by check, or withdrawal by ATM. There is also a selection of fees, which displays the bank fees and the fees accrued based on the transaction. Right now, the program does everything I want it to do, except upon exit. Upon exit, or in my code, the decision not to make another transaction, I'd like my program to display a list of all the transactions made. I've not learned about lists yet, so my idea was to store each of the transactions into an array, yet I am struggling to do so. In terms of my code, I'd like the displaySummary() method to do this. As it's set right now, it is not what I'm looking for, so ignore the code. Any help would be greatly appreciated. Here is my code so far:


#include <iostream>
#include <iomanip>
using namespace std;



class CheckingAccount
{
    
public:
    
	CheckingAccount() { runningBalance = 0; depositcount = 0; checkcounttot = 0; checkcount = 0; atmcounttot = 0; atmcount = 0; totalcount = 0; depositfees = 0;checkfees = 0; atmfees = 0; totalfees = 0; }
    
	void putInitialBalance(double w) { runningBalance = w; }
	void calcDep(double);
	void calcCheck(double);
	void calcATM(double);
    void displayFees();
	void displayBalance();
    void displaySummary();
    
    
private:
    
	double runningBalance;
    int depositcount, checkcounttot, checkcount, atmcounttot, atmcount, totalcount;
    double depositfees, checkfees, atmfees, totalfees;
   // double depositarr[1000], checkarr[1000], atmarr[1000];
    
};


void CheckingAccount::calcDep(double amount)
{
	runningBalance += amount - 0.25;
    ++depositcount;
    ++totalcount;
    
    /* for (int i = 0; i < depositcount; i++)
        amount = depositarr[i];
    
    cout << depositarr; */
}

void CheckingAccount::calcCheck(double amount)
{
	if (runningBalance - amount >= 0)
	{
		runningBalance -= amount;
        ++checkcounttot;
	}
    
	else if (runningBalance - amount < 0)
	{
		runningBalance -= (amount + 35.00);
        ++checkcount;
        ++checkcounttot;
        ++totalcount;
	}
}

void CheckingAccount::calcATM(double amount)
{
	char answer;
    
	if (runningBalance - amount >= 0)
	{
        runningBalance -= amount;
        ++atmcounttot;
	}
    
    else if (runningBalance - amount < 0)
    {
        cout << "\nWithdrawing " << amount << " will overdraft your account and accrue a $35.00 overdraft fee." << endl;
		cout << "Do you wish to continue with this transaction? [Y/N]? ";
		cin >> answer;
        
		if (answer == 'Y' || answer == 'y')
		{
			runningBalance -= (amount + 35.00);
            ++atmcount;
            ++atmcounttot;
            ++totalcount;
		}
		else if (answer == 'N' || answer == 'n')
		{
			cin.clear();
		}
    }
}

void CheckingAccount::displayFees()
{
    depositfees += (double(depositcount)*0.25);
    checkfees += (double(checkcount)*35.00);
    atmfees += (double(atmcount)*35.00);
    
    
    cout << endl  << endl << "Bank fees include: " << endl;
    cout << "$0.25 Deposit fee." << endl;
    cout << "$35.00 Overdraft fee for bounced check." << endl;
    cout << "$35.00 Overdraft fee for exceeding available amount via ATM withdrawal." << endl << endl;
    
    cout << "So far, you've made " << depositcount << " deposits, accruing a deposit bank fee of $" << depositfees << "." << endl;
    cout << "You've made " << checkcount << " check withdrawals in which the check bounced, accruing an overdraft fee of $" << checkfees << "." << endl;
    cout << "You've made " << atmcount << " ATM withdrawals, despite insufficient funds, accruing an overdraft fee of $" << atmfees << "." << endl << endl;
    
    totalfees += depositfees + checkfees + atmfees;
    cout << "In total, you've made " << totalcount << " transactions, amounting in $" << totalfees << " in banking fees." << endl << endl;
    
}

void CheckingAccount::displayBalance()
{
	cout << "Total Balance: " << setprecision(2) << fixed << runningBalance << endl << endl;
}

void CheckingAccount::displaySummary()
{
    cout << "Thank you for stopping by! Here is a summary of your transactions." << endl;
    cout << "In total, you've made " << depositcount << " deposits, " << checkcounttot << " check withdrawals, and " << atmcounttot << " ATM withdrawals." << endl;
    cout << "You were deducted " << totalfees << " in bank maitenance fees.";
    
}



int main()
{
    
	char X;
	char next = '\0';
	double initialAmount;
	double amount;
    
	CheckingAccount A;
    
	cout << "Welcome to the Bank! Please, enter your starting balance: ";
	cin >> initialAmount;

    
if (!cin.eof() && cin.good())
{
    
    A.putInitialBalance(initialAmount);
        
	do
	{
		cout << endl << endl << "What would you like to do?" << endl;
		cout << "For Deposits, Enter [D]." << endl;
		cout << "For Check Withdrawals, Enter [C]." << endl;
		cout << "For ATM Withdrawals, Enter [A]." << endl;
		cout << "For Fees, Enter [F]." << endl;
		cout << "To Exit, Enter [E]." << endl << endl;
		cout << "Please enter choice here: ";
        
		cin >> X;
        

		switch (X)
		{
            case 'D': case 'd':
            {
                cout << endl << "How much would you like to deposit? ";
                cin >> amount;
                A.calcDep(amount); A.displayBalance();
                cout << "Would you like to make another transaction? [Y/N]? ";
                cin >> next;
                break;
            }
                
            case 'C': case 'c':
            {
                cout << endl << "How much would you like to withdraw? ";
                cin >> amount;
                A.calcCheck(amount); A.displayBalance();
                cout << "Would you like to make another transaction? [Y/N]? ";
                cin >> next;
                break;
            }
                
            case 'A': case 'a':
            {
                cout << endl << "How much would you like to withdraw? ";
                cin >> amount;
                A.calcATM(amount); A.displayBalance();
                cout << "Would you like to make another transaction? [Y/N]? ";
                cin >> next;
                break;
            }
                
            case 'F': case 'f':
            {
                A.displayFees();
                cout << "Would you like to make another transaction? [Y/N]? ";
                cin >> next;
                break;
            }
                
            case 'E': case 'e':
            {
                cout << "Thank you for stopping by! Here is a summary of your transactions." << endl;
                return EXIT_SUCCESS; break;
            }
                
            default:
            {
                cout << "Invalid selection. Please, try again." << endl << endl;
            }
        }
        
	}while (next == 'Y' || next == 'y');
    

	if (next == 'N' || next == 'n')
	{
		cout << "Report ending balance, total deposits, total withdrawals, and total fees.";
		return 0;
	}
}
}







Is This A Good Question/Topic? 0
  • +

Replies To: Banking Program

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4074
  • View blog
  • Posts: 12,578
  • Joined: 25-December 09

Re: Banking Program

Posted 04 August 2014 - 11:18 AM

If you want to store the data for later processing you'll need either a vector or an array. I suggest the vector since you don't know the maximum number of entries the user will make.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1