-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17_static_member_example.cpp
More file actions
62 lines (61 loc) · 1.49 KB
/
Copy path17_static_member_example.cpp
File metadata and controls
62 lines (61 loc) · 1.49 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
//example on static member function
//example based on banking system-
#include <iostream>
using namespace std;
class customer {
string name;
int account_num;
int balance;
static int total_customer;
static int total_balance;
public :
customer (string n,int acc_no,int bal)
{
name =n;
account_num = acc_no;
balance = bal;
total_customer ++;
total_balance = total_balance + balance;
}
static void display_total()
{
cout<<"Total Customer : "<<total_customer<<endl;
cout<<"Total Balance : "<<total_balance<<endl;
}
void deposit(int amount)
{
if(amount>0)
{
balance += amount;
total_balance += amount;
}
}
void withdraw(int amount)
{
if(amount <= balance && amount > 0)
{
balance -= amount;
total_balance -= amount;
}
}
void display ()
{
cout<<"Name : "<<name<<endl;
cout<<"Account Number : "<<account_num<<endl;
cout<<"Balance : "<<balance<<endl;
}
};
int customer :: total_customer = 0;
int customer :: total_balance = 0;
int main()
{
customer A1("Piyush",6969,5000);
A1.display(); //before deposit
A1.deposit(800);
A1.display(); //after deposit
customer::display_total();
A1.withdraw(5000);
customer::display_total();
A1.display();//after withdrawn of 5000
return 0;
}