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
|
#include <iostream>
using namespace std; //introduces namespace std
class Account
{
private:
int acctNumber;
string acctName;
double acctBal;
public:
// 2 constructors
Account ()
{
acctNumber=0;
acctName=" ";
acctBal=0;
}
Account (int a,string ac,double acc)
{
acctNumber=a;
acctName = ac;
}
// sets
void setNum(int a)
{
acctNumber = a;
}
void setName(string ac)
{
acctName = ac;
}
// gets
int getAccNum()
{
return acctNumber;
}
string getName()
{
return acctName;
}
double getBal()
{
return acctBal;
}
};// end class
int main()
{
const int SIZE = 15;
Account bank[SIZE]= {Account (12345, "Smith", 1005.99),
Account (19822, "Lee", 20.21),
Account (18521, "Kim", 3061.77),
Account (85218, "Wall", 9855.33),
Account (85199, "Harry", 9077.88),
Account (91532, "Jess", 63112.99),
Account (43174, "Glee", 641.88),
Account (63173, "Corr", 841.55),
Account (23441, "Matt", 124.92),
Account (65185, "Card", 90.22),
Account (62188, "Kells", 529.77),
Account (32188, "Slyth", 863.22),
Account (90888, "Booth", 7422.88),
Account (52111, "Good", 321.99),
Account (87331, "Williams", 7317.21)};
cout <<"\tWelcome to Bank!";
cout <<"\n\tYou can make a deposit or withdraw ";
cout <<"\n\n\tPlease have your account number";
cout <<"\n\tor the name on the account ready\n";
// all of your code here
int choice;
cout << "Do you want to check account balance by name or account number?";
cout << endl;
cout << "1-Name";
cout << endl;
cout << "2-Account Number";
cout << endl;
cout << "3-Exit";
cout << endl;
cin >> choice;
string name = " ";
int accNum=0;
int acctBal=0;
double bal=0;
if (choice == 1)
{
cout << "Enter your name: ";
cin >> name;
}
if (choice == 2)
{
cout << "Enter your account #: ";
cin >> accNum;
}
if (choice == 3)
{
cout <<"Have a nice day."<<endl;
}
while (choice <=0||choice >=4)
{
cout << "Wrong choice, please try again: ";
cin >> choice;
}
for(int i=0; i<SIZE; i++)
{
if(bank[i].getAccNum() == accNum || bank[i].getName() == name)
{
cout<<"Account Number: " << bank[i].getAccNum()<<endl;
cout<<"Account Name: " <<bank[i].getName()<<endl;
cout<<"Account Balance: "<<bank[i].getBal()<<endl;
}
}
// give user a choice of searching by acct number, name or quit
// make sure withdraw amount is not greater than balance
cout <<"Good Bye";
return 0;
}
|