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