| 1. |
Define a class worker with the following specification: Private members of class workerwname25 charactershrwrkfloat (hors worked and wagerate per hourtotwagefloat(hrwrk*wgrate)calcwgA fuction to find hrerk* wgrate with float return typePublic members of class workerin_data() a function to accept values for wno, wname, hrwrk, wgrate and invoke calcwg() to calculate totwage.out_data() a function to display all the data members on the screen you should give definations of functions |
|
Answer» #include <iostream.h> #include<stdio.h> #include<conio.h> class worker { int wno; char wname[25]; float hewrk,wgrate; float totwage; float calcwg() { totwage = hewrk*wgrate; return totwage; } public: void in_data(); void out_data(); }; void worker::in_data() { cout<<"Enter worker number:"; cin>>wno; cout<<"enter worker name:";\ gets(wname); cout<<"Enter hours worked: "; cin>>hewrk; cout<<"Enter wage rate per hour:"; cin>>wgrate; calcwg(); } void worker::out_data() { cout<<"......Worker Information........"<<end1; cout<<"Worker number:"<<wno<<end1; cout<<" Worker name:"<<wname<<end1; cout<<" Hours worked:"<< hewrk<<end1; cout<<" Wage rate per hour:"<< wgrate<<end1; cout<<" Total wage:"<<totwage<<end1; } int main() { worker obj; obj in_data(); obj.out_data(); getch(); return 0; } |
|