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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class AccInfo
{
protected:
string name, type, accno;
int age;
double balance;
public:
AccInfo(){}
void BasicMenu(void);
void CreateAcc(void);
void savedata(void);
void savedata2(void);
void readdata(void);
void Deposit(void);
void Withdraw(void);
void display(void);
void checkbal(double balance);
};
void AccInfo::BasicMenu(void)
{
cout << "<1> Create Account."<<endl;
cout << "<2> Display Account."/*(Key in Account No.)*/<<endl;
cout << "<3> Deposit."<<endl;
cout << "<4> Withdraw."<<endl;
cout << "<5> Calculate Interest."<<endl;
cout << "<6> Quit Bank Program."<<endl;
}
void AccInfo::CreateAcc(void)
{
string na, ty, no;
int ag;
float amt;
cout<<"Please enter the account user name : ";
fflush(stdin);
getline(cin, na);
cout<<"Please enter Age : ";
cin>>ag;
fflush(stdin);
cout<<"Please enter the account number : ";
getline(cin, no);
cout<<"Please enter the account type : ";
getline(cin, ty);
cout<<"Amount to be deposited into the account : ";
cin>>amt;
name = na;
age = ag;
type = ty;
accno = no;
balance = amt;
}
void AccInfo::savedata(void)
{
ofstream outfile;
outfile.open("c:\\CreatedAcc.txt",fstream::app);
//outfile.seekp (0, ios_base::end);
outfile<<"Name : "<<name<<endl;
outfile<<"Age : "<<age<<endl;
outfile<<"Account Number : "<<accno<<endl;
outfile<<"Account Type : "<<type<<endl;
outfile<<"Balance : "<<balance<<endl<<endl;
outfile.close();
}
void AccInfo::savedata2(void)
{
ofstream outfile;
outfile.open("c:\\DataBase.txt",fstream::app);
//outfile.seekp (0, ios_base::end);
outfile<<name <<endl; //"\t" ;//<<endl;
outfile<<age <<endl;//"\t" ;//endl;
outfile<<accno <<endl;//"\t" ;//<<endl;
outfile<<type <<endl;//"\t" ;//endl;
outfile<<balance <<endl<<endl;//"\t" ;//endl;
outfile.close();
}
void AccInfo::readdata(void)
{
ifstream infile;
string show;
if (infile == 0)
cout<<"File not found!!!"<<endl;
else
{
cout << "Please key in your Account Name : ";
fflush(stdin);
getline(cin, name);
//infile.open("c:\\Database.txt");
infile.open("c:\\DataBase.txt",fstream::beg);
//infile.seekp (0, ios_base::end);
fflush(stdin);
//infile>>show;
//getline(infile,show);
//cout<<show<<endl;
while (show != name)
{
getline(infile, show);
fflush(stdin);
}
cout<<"Name : "<<name<<endl;
getline(infile,accno);
cout<<"Age : "<<age<<endl;
getline(infile,accno);
cout<<"Account Number : "<<accno<<endl;
getline(infile,type);
cout<<"Account Type : "<<type<<endl;
getline(infile,show);
//cout<<"Balance : "<<show<<endl;
//getline(infile,amt);
//while(!infile.eof())
//{
//getline(infile,show);
//cout<<"Balance : "<<show<<endl;
//}
cout<<"Balance : "<<balance<<endl<<endl;
infile.close();
}
}
void AccInfo::Deposit(void)
{
int choice;
double amt;
cout <<"<1> Deposit $100."<<endl;
cout <<"<2> Deposit $200."<<endl;
cout <<"<3> Deposit $300."<<endl;
cout <<"<4> Deposit $400."<<endl;
cout <<"<5> Deposit $500."<<endl;
cout <<"<6> Other Deposit."<<endl;
cout <<"<7> Quit Deposit."<<endl;
do{
cin >> choice;
switch (choice)
{
case 1 : balance = balance + 100;
break;
case 2 : balance = balance + 200;
break;
case 3 : balance = balance + 300;
break;
case 4 : balance = balance + 400;
break;
case 5 : balance = balance + 500;
break;
case 6 : cout << "Please key in the amount to be deposit : $";
cin >> amt;
balance = balance + amt;
break;
case 7 : break;
default: cout << "Wrong Choice!"<<endl;
cout << "Please key in a valid option : ";
}
} while(choice == 0 || choice > 7);
}
void AccInfo::Withdraw(void)
{
int choice;
double amt;
cout <<"<1> Withdraw $100."<<endl;
cout <<"<2> Withdraw $200."<<endl;
cout <<"<3> Withdraw $300."<<endl;
cout <<"<4> Withdraw $400."<<endl;
cout <<"<5> Withdraw $500."<<endl;
cout <<"<6> Other Withdrawal."<<endl;
cout <<"<7> Quit Withdrawal."<<endl;
do{
cin >> choice;
if (balance)
switch (choice)
{
case 1 : if(balance - 100 <= 0)
{
cout << "Withdrawal not granted. Balance not changed."<<endl;
break;
}
else
{
balance = balance - 100;
break;
}
case 2 : if(balance - 200 <= 0)
{
cout << "Withdrawal not granted. Balance not changed."<<endl;
break;
}
else
{
balance = balance - 200;
break;
}
case 3 : if(balance - 300 <= 0)
{
cout << "Withdrawal not granted. Balance not changed."<<endl;
break;
}
else
{
balance = balance - 300;
break;
}
case 4 : if(balance - 400 <= 0)
{
cout << "Withdrawal not granted. Balance not changed."<<endl;
break;
}
else
{
balance = balance - 400;
break;
}
case 5 : if(balance - 500 <= 0)
{
cout << "Withdrawal not granted. Balance not changed."<<endl;
break;
}
else
{
balance = balance - 500;
break;
}
case 6 : cout << "Please key in the amount to be deposit : $";
cin >> amt;
if(balance - amt <= 0)
{
cout << "Withdrawal not granted. Balance not changed."<<endl;
break;
}
else
{
balance = balance - amt;
break;
}
case 7 : break;
default: cout << "Wrong Choice!"<<endl;
cout << "Please key in a valid option : ";
}
} while(choice == 0 || choice > 7);
};
|
Main
------------------------------------------------------------------------------------------------------
#include "Account_Info.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
int menuchoice;
string na;
AccInfo Acc;
do
{
Acc.BasicMenu();
cout<<"Please enter your choice : ";
cin >> menuchoice;
switch(menuchoice)
{
case 1 : cout <<"Creating Account."<<endl;
Acc.CreateAcc();
Acc.savedata();
Acc.savedata2();
cout <<"Account Created!"<<endl;
break;
case 2 : Acc.readdata();
break;
case 3 : Acc.Deposit();
Acc.savedata();
Acc.savedata2();
//Acc.readdata();
break;
case 4 : Acc.Withdraw();
Acc.savedata();
Acc.savedata2();
break;
case 6 : cout << "Quitting Program!"<<endl;
break;
default: cout<<"Wrong choice entered!"<<endl;
cout<<"Please enter again! "<<endl;
}
}while (menuchoice != 6);
} | |