Write a C++ program to create a class Worker with data members as Worker_Name, No_of_Hours_worked, Pay_Rate. Write necessary member functions to calculate and display the salary of worker. (Use default value for Pay_Rate)

//Note :- If you are not using Borland or Turbo c then please add following line after header files -
//using namespace std;
#include<iostream.h>
#include<conio.h>

class worker
{
  char name[50]; //declare name as a string
        int noh; //noh=no of hours
        void display()
       {
            cout<<"Name \t\t\t:\t"<<name<<"\n"<<"No of hours worked \t:\t"<<noh;
       }
      public:
      void calculate(int payrate=10)
      {

           noh=noh*payrate;// calculating no of hours * payrate 
           display(); //display is private function 
      }
      void accept()
      {
         //accept all information
         cout<<"Enter employee name:-> ";
         cin>>name;
         cout<<"Enter how many hours worked:-> ";
         cin>>noh;
         calculate();
      }
};
int main()
{
   worker w1;//w1 is instance of class worker
   w1.accept();//calling of class function
   getch();
    return(0);
}

0 Comments