-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlec3.cpp
More file actions
82 lines (68 loc) Β· 1.53 KB
/
lec3.cpp
File metadata and controls
82 lines (68 loc) Β· 1.53 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
#include<iostream>
using namespace std;
// hw const keyword
class Customer
{
string name;
int acc_no;
int balance;
static int total_customer;
static int total_balance;
public:
Customer(string name , int acc_no , int balance)
{
this->name = name;
this->acc_no = acc_no;
this->balance = balance;
total_customer++;
total_balance+=balance;
}
void display()
{
cout<<name<<endl;
cout<<acc_no<<endl;
cout<<balance<<endl;
}
void display_total()
{
cout<<"Total number of Customer is "<<total_customer<<endl;
cout<<"Total Balance is "<<total_balance<<endl;
}
//static function ; can access only static attributes
static void display_total_static()
{
cout<<total_customer<<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;
}
}
};
int Customer :: total_customer = 0 ;
int Customer :: total_balance = 0 ;
int main()
{
Customer A1("Jashan" , 124, 50000);
Customer A2("Josep" , 125, 50000);
A1.display();
A2.display();
// access directly , public only
//Customer::total_customer = 5;
Customer::display_total_static();
A1.deposit(5000);
A2.withdraw(4000);
A1.display_total();
return 0 ;
}