Showing posts with label scope resolution. Show all posts
Showing posts with label scope resolution. Show all posts

Wednesday, 4 January 2012

Program To Find Static Data Member In C++ Using Scope Resolution

#include<iostream.h>
#include<conio.h>

class add
{
private:
int a;
static float pi;     // Static Data Member
public:
void getdata(int x)  //(:: Scope Resolution)
{
a=x;
}
void  display()
{
float c;
c=pi*a*a;
cout<<"\n Answer="<<c;
}
};
float add :: pi=3.14;
main()
{
clrscr();
add a1;
int p,q;
cout<<"Enter p=";
cin>>p;
a1.getdata(p);
a1.display();
getch();
}