Home CPP Examples C++ Class Program to Store and Display Employee Information

C++ Class Program to Store and Display Employee Information

by anupmaurya
19 minutes read

Let’s see an example of C++ class where we are storing and displaying employee information using method.

 #include <iostream>  
 using namespace std;  
 class Employee {  
    public:  
        int id;//data member (also instance variable)      
        string name;//data member(also instance variable)  
        float salary;  
        void insert(int i, string n, float s)    
         {    
             id = i;    
             name = n;    
             salary = s;  
         }    
        void display()    
         {    
             cout<<id<<"  "<<name<<"  "<<salary<<endl;    
         }    
 };  
 int main(void) {  
     Employee e1; //creating an object of Employee   
     Employee e2; //creating an object of Employee  
     e1.insert(201, "Kashish",990000);    
     e2.insert(202, "Abhishek", 29000);    
     e1.display();    
     e2.display();    
     return 0;  
 }   

Output:

201  Kashish  990000
202  Abhishek 29000

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.