Search This Blog

Tuesday 2 February 2016

Demonstrating Static Functions and Static Members

 Practical 12


#include<iostream>
#include<iomanip>

using namespace std;

class STAT
{
static int a;
int b;
public:
void getdata();
static void display();
void display2();
};

void STAT::getdata()
{
cout << "\t\tEnter number : ";
cin >> b;
}

void STAT::display()
{
cout << "Static number is " << a++ << endl;
}

void STAT::display2()
{
cout << "Static number is " << a++ << endl; 
cout << "Non Static number is " << b << endl;
}

int STAT::a;

int main()
{
STAT a;
a.getdata();
STAT::display();
a.display2();
return 0;
}



output:



enter number : 2
static number is : 0
static number is 1
non static number is : 2

No comments:

Post a Comment