Class Program Example



#include <iostream.h>

#include<stdio.h>

#include<conio.h>

 

class worker

{  

private:

char wname[20]; //Name

float hrwrk;   //Hours worked

float wgrate;  // Work Rate

float totwage; //Total wage

                      //REQUIRED CALCULATIONS

float calcwg()

  return (hrwrk*wgrate);    }

 

public:

int wno;


                      //ENTER THE VALUES

void in_data() 

{    

cout<<"\nEnter the Worker number"<<'\n';

cin>>wno;

cout<<"\nEnter the Worker Name:"<<'\n';

gets(wname);

cout<<"\nEnter No: of Hours worked:"<<'\n';

cin>>hrwrk;

cout<<"\nEnter Wage rate per hour:"<<'\n';

cin>>wgrate;

totwage=calcwg();   

}


                      //SHOW THE VALUES

void out_data()

{  

cout<<"\nWorker number:"<<wno;

cout<<"\nWorker Name:"; puts(wname);

cout<<"\nNo: of Hours worked:"<<hrwrk;

cout<<"\nWage rate per hour:"<<wgrate;

cout<<"\n\n Total Wage: Rs"<<totwage; 

}

};

 

void main()

{              

 clrscr();     worker w[100]; int n; int Wno;   char ch;

cout<<"Enter the number of workers of which to find total wage:\n";

cin>>n;

for(int i=0; i<n; i++)

{ cout<<"\nDetails for Member #"<<(i+1)<<'\n';

w[i].in_data();    }


do

{   

cout<<"\n\n Enter the Worker No of whose data you would like to see:"<<"\n";

cin>>Wno;

 

for(i=0; i<n; i++)

if(w[i].wno==Wno)

{ w[i].out_data(); cout<<endl; }

else if(i==(n-1))

{ cout<<"\nNo such Worker Number. Try "; }

 

cout<<"Again? (y/n)";      ch=getch();

}

while(ch=='y' || ch=='Y');    cout<<"\nProgram Terminated!"<<'\n';   

}