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
|
#include<fstream>
int main(){
vector<account> db;
int tempint;
string tempstr;
double tempdouble;
stringstream stream;
int current;
int filesize;
int choice=1;
char * tempname;
char c;
account* tempacc;
while(choice!=0){
cout<<"\n\n1.List accounts\n2.Change current account\n3.Display current account info\n4.Make Deposit\n5.Withdraw funds\n6.New account\n7.Delete account\n8.Save data\n9.Load data\n0.Exit";
cout<<"\nEnter choice: ";
cin>>choice;
switch(choice){
case 8:
{
ofstream outfile("account.dat");
for(unsigned t=0;t<db.size();++t){
outfile<<db.at(t).getname()<<","<<db.at(t).getaccno()<<","<<db.at(t).getbalance()<<",";
}
outfile.close();
cout<<"\n\nData Saved!";
break;
}
case 9:
{
ifstream infile("account.dat");
{
int counter=0;
while(!(infile.eof())){
infile.get(c);
if(c==',')
++counter;
}
filesize=counter/3;
infile.clear();
infile.seekg(0);
db.clear();
for(int t=0;t<filesize;++t){
stream.flush();
counter=0;
c=' ';
while(c!=','){cout<<c;
infile.get(c);
if(c==','){
tempname=new char[81];
tempstr.clear();
tempstr.resize(counter);
stream.getline(tempname,counter+1);
tempstr=tempname;
delete tempname;
cout<<"\nname="<<tempstr;
stream.flush();
}
else{ ++counter;
stream.put(c);
}}
c=' ';
while(c!=','){cout<<c;
infile.get(c);
if(c==','){
stream>>tempint;
stream.flush();
}
else{
stream.put(c);
}}
c=' ';
while(c!=','){cout<<c;
infile.get(c);
if(c==','){
stream>>tempdouble;
stream.flush();
}
else{
stream.put(c);
}}
db.resize(db.size()+1);
db.at(db.size()-1).setup(tempstr,tempint,tempdouble);
}}
infile.close();
cout<<"\n\n"<<filesize<<" accounts loaded.";
break;
}
case 0:
return 0;
break;
default:
cout<<"\nInvalid Entry!";
break;
}}
return 0;
}
|