-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass4.cpp
More file actions
38 lines (35 loc) · 783 Bytes
/
Copy pathclass4.cpp
File metadata and controls
38 lines (35 loc) · 783 Bytes
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
//static member variable and class variable
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class Account
{
private:
int balance; //this is called instance member variable
static float rate; //static member variable or class variable
public:
void setBalance(int b)
{
balance = b;
}
void showBalance()
{
cout << "balance is " << balance << endl;
}
static void setRate(float r) //non instance member function
{
rate = r;
}
};
float Account::rate = 2.5f;
int main(int argc, char const *argv[])
{
//creating objects of class
Account a;
a.setBalance(1000);
a.setRate(2.5);
a.showBalance();
Account::setRate(5.0f); //static member function
return 0;
}