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.

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;
}

No comments:

Post a Comment