C++ Program to Maintain Employee Database using Virtual class

By | 03.01.2017

Maintain Employee Database using Virtual class


Write a C++ Program to Maintain Employee Database using Virtual class. Here’s a Simple Program to Maintain Employee Database using Virtual class in C++ Programming Language.


What is Polymorphism in C++ ?


The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance.

C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function.


Virtual Function : :


A virtual function is a function in a base class that is declared using the keyword virtual. Defining in a base class a virtual function, with another version in a derived class, signals to the compiler that we don’t want static linkage for this function.


Below is the source code for C++ Program to Maintain Employee Database using Virtual class which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/*  C++ Program to Maintain Employee Database using Virtual class  */

#include <iostream>
#include <stdlib.h>
using namespace std;

class person
{
  protected:
      char name[20];
      int code;
  public:
      void getdetail(void)
      {
    cout<<"\n\nEnter name :- ";
    cin>>name;
    cout<<"\nEnter code :- ";
    cin>>code;
      }
      void dispdetail(void)
      {
    cout<<"\n\nNAME      :- "<<name;
    cout<<"\nCODE      :- "<<code;
      }
};

class account : virtual public person
{
  protected:
       float pay;
  public:
       void getpay(void)
       {
     cout<<"\nEnter Pay amount :- ";
     cin>>pay;
       }
       void dispay(void)
       {
      cout<<"\nPAY       :- "<<pay;
       }
};

class admin : virtual public person
{
  protected:
       int experience;
  public:
       void getexpr(void)
       {
      cout<<"\nEnter Experience in yrs :- ";
      cin>>experience;
       }
       void dispexpr(void)
       {
      cout<<"\nEXPERIENCE:- "<<experience;
       }
};

class master : public account, public admin
{
    public:
    void create(void)
    {
       cout<<"\n\n=====GETDATA IN=====\n";
       getdetail();
       getpay();
       getexpr();
    }

    void display(void)
    {
      cout<<"\n\n=====DISPLAY DETAILS=====\n";
      dispdetail();
      dispay();
      dispexpr();
    }

    void update(void)
    {
      cout<<"\n\n=====UPDATE DETAILS=====\n";
      cout<<"\nChoose detail you want to update\n";
      cout<<"1)  NAME\n";
      cout<<"2)  CODE\n";
      cout<<"3)  EXPERIENCE\n";
      cout<<"4)  PAY\n";
      cout<<"Enter your choice:- ";
      int choice;
      cin>>choice;
      switch(choice)
      {
        case 1 : cout<<"\n\nEnter name : - ";
             cin>>name;
             break;
        case 2 : cout<<"\n\nEnter code :- ";
             cin>>code;
             break;
        case 3 : cout<<"\n\nEnter pay :- ";
             cin>>pay;
             break;
        case 4 : cout<<"\n\nEnter Expereince :- ";
             cin>>experience;
             break;
        default: cout<<"\n\nInvalid choice\n\n";
      }
    }
};

int main()
{
    master ob1;
    int choice;
    while(1)
    {

       cout<<"\n\n=====EMPLOYE DATABASE=====\n\n";
       cout<<"\nChoose Operation you want to perform\n";
       cout<<"1)  Create  Record\n";
       cout<<"2)  Display Record\n";
       cout<<"3)  Update  Record\n";
       cout<<"4)  Exit\n";
       cout<<"\nEnter your choice:- ";
       cin>>choice;
       switch(choice)
       {
         case 1 : ob1.create();
              break;
         case 2 : ob1.display();
              break;
         case 3 : ob1.update();
              break;
         case 4 : exit(1);
        default : cout<<"\n\nInvalid Choice\nTry Again\n\n";
       }
    }
    return 0;
}

OUTPUT : :


/*  C++ Program to Maintain Employee Database using Virtual class  */

=====EMPLOYE DATABASE=====


Choose Operation you want to perform
1)  Create  Record
2)  Display Record
3)  Update  Record
4)  Exit

Enter your choice:- 1


=====GETDATA IN=====


Enter name :- Codez

Enter code :- 01

Enter Pay amount :- 40000

Enter Experience in yrs :- 3


=====EMPLOYE DATABASE=====


Choose Operation you want to perform
1)  Create  Record
2)  Display Record
3)  Update  Record
4)  Exit

Enter your choice:- 2


=====DISPLAY DETAILS=====


NAME      :- Codez
CODE      :- 1
PAY       :- 40000
EXPERIENCE:- 3

=====EMPLOYE DATABASE=====


Choose Operation you want to perform
1)  Create  Record
2)  Display Record
3)  Update  Record
4)  Exit

Enter your choice:- 3


=====UPDATE DETAILS=====

Choose detail you want to update
1)  NAME
2)  CODE
3)  EXPERIENCE
4)  PAY
Enter your choice:- 1


Enter name : - CodezClub


=====EMPLOYE DATABASE=====


Choose Operation you want to perform
1)  Create  Record
2)  Display Record
3)  Update  Record
4)  Exit

Enter your choice:- 2


=====DISPLAY DETAILS=====


NAME      :- CodezClub
CODE      :- 1
PAY       :- 40000
EXPERIENCE:- 3

=====EMPLOYE DATABASE=====


Choose Operation you want to perform
1)  Create  Record
2)  Display Record
3)  Update  Record
4)  Exit

Enter your choice:- 4

Process returned 1

Above is the source code and output for C++ Program to Maintain Employee Database using Virtual class which is successfully compiled and run on Windows System to produce desired output.

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.


Thanks for reading the post….

0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
omkar

i need a help . i want an code regarding staff managment using inheritance for c++