1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <math.h>
using namespace std;
class Acct
{
public:
Acct(char[], char, double); //constructor
void printAccount();
void changeBalance(double);
void setAcctType(char);
char getAcctType();
double getBalance();
void set_acctName(char []);
void set_acctType(char );
void set_acctBal(double);
double newAcctBal;
double newAcctType;
private:
char name[50];
char acctType;
double balance;
};
void Acct::set_acctType( char newAcctType )
{
if( newAcctType == 'C' || newAcctType == 'S' )
{
acctType = newAcctType;
}
}
void Acct::set_acctBal( double newAcctBal )
{
balance = newAcctBal;
}
int main()
{
Acct account1 = Acct( "Doe, John", 'C', 113019.77 );
Acct account2 = Acct( "Doe, Jane", 'S', 1234.50 );
Acct account3 = Acct( "Temperance, Brennan", 's', 82.12 );
Acct account4 = Acct( "Seeley, Booth", 'c', 3869.00 );
Acct account5 = Acct( "Zach, Addy", 'C', 71940.76 );
account1.printAccount();
account1.changeBalance(939.39);
account1.printAccount();
account2.printAccount();
account2.changeBalance(-240.00);
account2.printAccount();
account3.printAccount();
account3.changeBalance(82000.12);
account3.printAccount();
account4.printAccount();
account4.setAcctType('z');
account4.changeBalance(43321.98);
account4.getBalance();
account4.printAccount();
account5.printAccount();
account5.changeBalance(-30);
account5.changeBalance(369);
account5.printAccount();
}
void Acct::printAccount()
{
if (acctType == 'C' || acctType == 'c')
{
cout << "Name: " << name << "/t"<< "Checking Account Balance: $"<< balance;
}
else if (acctType == 'S' || acctType == 's')
{
cout << "Name: " << name << "/t"<< "Savings Account Balance: $"<< balance;
}
else
{
cout << "Invalid account type";
}
}
void Acct::changeBalance( double amountToChange )
{
if (amountToChange > 0)
{
newAcctBal = balance + amountToChange;
}
else
{
newAcctBal = balance - amountToChange;
if (balance <0)
{
cout << "Account overdrawn $10 fee added to account";
newAcctBal = newAcctBal - 10;
}
}
}
void Acct::setAcctType(char)
{
char choice;
cout << "Enter the new account type";
cin >> choice;
if(choice == 'c' || choice == 'C')
{
cout << "The new account type is checking";
}
else if (choice == 's' || choice == 'S')
{
cout << "The new account type is savings";
}
else
{
cout << "Invalid new account type";
}
}
char Acct::getAcctType()
{
cout << "The Account type is: "<< acctType;
}
double Acct::getBalance()
{
cout << "Account balance is: " << newAcctBal;
}
|