OOPc using C++

With this blog I want to share my knowledge of OOPs and C++. I Hope this can quench your thirst for learning.Any suggestions and comments are welcome.
Showing posts with label Employee class. Show all posts
Showing posts with label Employee class. Show all posts

Friday, August 6, 2010

Program 9 - Employee Class advanced


The following program which utilizes the same class Employee with a few extensions:

class Employee
{
     int Empno;
     char *Ename;
     char *Add;
     float Salary, Comm, TotSal;

     public:
            void Input( );
            void Output( );
            void ChangeEmpno(int);                //function with argument of type int
            void ChangeEmpno2(int =2);         //function with default argument
            float Tot_sal( );                           //function with return type float
};

int main()
{
           Employee Emp1;
           Emp1.Input( );
           Emp1.Output( );

           cout<<Emp1.Tot_Sal( );
           
           Emp1.ChangeEmpno( );
           Emp1.ChangeEmpno(458);
           Emp1.ChangeEmpno2(100);

          return 0;
}

void Employee::Input()
{
          cin>>Empno>>Ename>>Add>>Salary>>Comm;
          TotSal=Tot_Sal( );               //Input() is calling Tot_Sal()
}
void Employee::Output( )
{
          cout<<Empno<<Ename<<Add<<Salary<<Comm<<TotSal;
}
void Employee::ChangeEmpno( )
{
          int NewEmpno;
          cin>>NewEmpno;

          Empno=NewEmpno;
}
void Employee::ChangeEmpno(int NewEmpno)
{
        Empno=NewEmpno;
}
void Employee::ChangeEmpno2(int IncEmpno)
{
        Empno+=IncEmpno;
}
float Employee::Tot_sal( )
{
        return Salary+Comm;
}

Program 8 - Employee Class program

This program takes the name,age, and salary of the employee as input and just displays the entered data.

#include<iostream.h>


class Employee
{
            private: 
                       char cname[30];
                       int iage,isalary;
            public:
                       void getdata( )                    //Function to get input from the user
                        {
                                 cout<<"Enter the Name of the Employee"<<endl;
                                 cin>>cname[30];
                                 cout<<"Enter the Age and salary of the employee"<<endl;
                                 cin>>iage>>isalary;
                            }


                       void display( )              //Function to display the entered data
                       {
                                 cout<<"***************************"<<endl; 
                                 cout<<"Name of the Employee : "<<name[30];
                                 cout<<"Age : "<<endl;
                                 cout<<"Salary : "<<endl;
                                 cout<<"***************************"<<endl;
                         }


};                                                                        //End of class


void main( )
{
             Employee e1,e2,e3;                 //Creating objects e1,e2,e3
               
             e1.getdata( );                           // Calling getdata function using object e1
             e2.getdata( );
             e3.getdata( );
          
             e1.display( );                          //Calling getdata function using object e1
             e2.display( );
              e3.display( );
}