-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbanking system struct.cpp
More file actions
89 lines (74 loc) · 1.87 KB
/
banking system struct.cpp
File metadata and controls
89 lines (74 loc) · 1.87 KB
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
#include <iostream>
#include <string>
using namespace std;
struct BankAccount
{
string name;
int age;
double balance;
};
BankAccount open(BankAccount);
BankAccount deposit(BankAccount);
BankAccount withdraw(BankAccount);
BankAccount display(BankAccount);
int main()
{
BankAccount b1, b2, temp;
//Testing for first object
temp = open(b1);
b1 = temp;
temp = deposit(b1);
b1 = temp;
temp = withdraw(b1);
b1 = temp;
display(b1);
//Testing for second object
temp = open(b2);
b2 = temp;
temp = deposit(b2);
b2 = temp;
temp = withdraw(b2);
b2 = temp;
display(b2);
return 0;
}
BankAccount open(BankAccount b1)
{
cout<<"Enter your name: ";
cin>>b1.name;
cout<<"Enter your age: ";
cin>>b1.age;
cout<<"Enter your balance: ";
cin>>b1.balance;
return b1;
}
BankAccount deposit(BankAccount b1)
{
double deposit;
cout<<"Enter amount to deposit: ";
cin>>deposit;
if(deposit<0)
cout<<"Invalid amount";
else
b1.balance = b1.balance + deposit;
return b1;
}
BankAccount withdraw(BankAccount b1)
{
double withdraw;
cout<<"Enter amount to withdraw: ";
cin>>withdraw;
if(withdraw>b1.balance)
cout<<"Insufficient balance";
else
b1.balance = b1.balance - withdraw;
return b1;
}
BankAccount display(BankAccount b1)
{
cout<<"Your name: "<<b1.name<<endl;
cout<<"Your age: "<<b1.age<<endl;
cout<<"Your balance: "<<b1.balance<<endl;
cout<<"Thank you for banking with TBL"<<endl;
return b1;
}