Pages

C++ Programming Tutorials -20(Static Data Members & Methods in C++ OOPS)

tut24.cpp =
//This tut contains Static Data Members & Methods in C++ OOPS
#include<iostream>
using namespace std;

class Employee
{
   int id;
   static int count;1

   public:
   void setData(void)
   {
       cout<<"Enter the Id of employee :"<<endl;
       cin>>id;
   }
   void getData(void)
   {
       cout<<"The Id is "<<id<<" of employee no "<<count<<endl;
       count++;
   } 
   static void getCount(void)
   {
       cout<<"The count is "<<count<<endl;
   }
};

int Employee :: count;
int main(){
    Employee harry,rocky,john;
    harry.setData();
    harry.getData();
    Employee :: getCount();

    rocky.setData();
    rocky.getData();
    Employee :: getCount();

    john.setData();
    john.getData();
    
    Employee :: getCount();

    return 0;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Top 10 Python Packages Every Developer Should Learn

Top 10 Python Packages Every Developer Should Learn There are more than  200,000 Python packages  in the world (and that’s just counting tho...