-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path07_account.cpp
executable file
·153 lines (139 loc) · 2.46 KB
/
07_account.cpp
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
#include <iostream>
#include <cstring>
using namespace std;
class Account{
int acc, bal;
char name[20];
Account *acptr;
public:
Account(int a, char n[]){bal = 0; strcpy(name, n); acc = a; acptr = NULL;}
bool deposit(int, int);
bool withdraw(int, int);
bool balance(int);
Account* newac(int, char*);
Account* nextac();
};
int main(){
char name[20];
int acc, n = 0, c, amt;
bool f;
Account *header = NULL, *ptr = NULL, *tptr = NULL;
do{
cout<<"\n1. Create Account\n2. Deposit\n3. Withdraw\n4. Balance\n0. Exit\n:";
cin>>c;
switch(c){
case 1:
cout<<"Enter name : ";
cin>>name;
cout<<"Account no : "<<n+1<<"\n";
if(header == NULL){
header = new Account(n+1, name);
ptr = header;
}else{
ptr = ptr->newac(n+1, name);
}
++n;
break;
case 2:
cout<<"Enter account no: ";
cin>>acc;
cout<<"Enter amount: ";
cin>>amt;
tptr = header;
while(tptr != NULL){
f = tptr->deposit(acc, amt);
if(f){
break;
}else{
tptr = tptr->nextac();
}
}
if(!f){
cout<<"Account does not exist\n";
}
break;
case 3:
cout<<"Enter account no: ";
cin>>acc;
cout<<"Enter amount: ";
cin>>amt;
tptr = header;
while(tptr != NULL){
f = tptr->withdraw(acc, amt);
if(f){
break;
}else{
tptr = tptr->nextac();
}
}
if(!f){
cout<<"Account does not exist\n";
}
break;
case 4:
cout<<"Enter account no: ";
cin>>acc;
tptr = header;
while(tptr != NULL){
f = tptr->balance(acc);
if(f){
break;
}else{
tptr = tptr->nextac();
}
}
if(!f){
cout<<"Account does not exist\n";
}
break;
case 0:break;
default :cout<<"Invalid option\n";
}
}while(c != 0);
return 0;
}
//Account
bool Account::deposit(int ac, int d){
if(acc == ac){
bal += d;
cout<<"Deposited \n";
balance(acc);
return 1;
}else{
return 0;
}
}
bool Account::withdraw(int ac, int w){
if(acc == ac){
if(bal-w > 2000){
bal -= w;
cout<<"Withdrawed\n";
balance(acc);
}else{
cout<<"Not sufficient balance\n";
balance(acc);
}
return 1;
}else{
return 0;
}
}
bool Account::balance(int ac){
if(acc == ac){
cout<<"Balance : "<<bal<<"\n";
return 1;
}else{
return 0;
}
}
Account* Account::newac(int a, char n[]){
if(acptr == NULL){
acptr = new Account(a, n);
return acptr;
}else{
return NULL;
}
}
Account* Account::nextac(){
return acptr;
}