-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstaticFnc.cpp
60 lines (49 loc) · 1.51 KB
/
staticFnc.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
#include <iostream>
using namespace std;
class BackAccount{
private:
int accNumber;
string accHolderName;
double accBalance;
static int totalAccounts;
public:
BackAccount(int accNumber, string accHolderName, double accBalance){
this->accNumber = accNumber;
this->accHolderName = accHolderName;
this->accBalance = accBalance;
totalAccounts++;
}
static int getTotalAccounts(){
return totalAccounts;
}
void display(){
cout<<"Account Number: "<<accNumber<<endl;
cout<<"Account Holder Name: "<<accHolderName<<endl;
cout<<"Account Balance: "<<accBalance<<endl;
}
void deposit(double amount){
accBalance += amount;
cout<<"Amount "<<amount<<" deposited successfully."<<endl;
}
void withdraw(double amount){
if(accBalance - amount >= 0){
accBalance -= amount;
cout<<"Amount "<<amount<<" withdrawn successfully."<<endl;
}else{
cout<<"Insufficient balance."<<endl;
}
}
};
int BackAccount::totalAccounts = 0;
int main(){
BackAccount acc1(101, "HIHI", 5000);
acc1.display();
acc1.deposit(2000);
acc1.withdraw(1000);
BackAccount acc2(102, "HAHA", 6000);
acc2.display();
acc2.deposit(3000);
acc2.withdraw(4000);
cout<<"Total Accounts: "<<BackAccount::getTotalAccounts()<<endl;
return 0;
}