Private members of class worker
wno integer
wname 25 characters
hrwk, wgrate float (hour worked and wage rate per hour)
totwage float (hrwk * wgrate )
calcwg ( ) A function to find hrwk * wgrate with float return type.
Public members of class worker
In_data ( ) a function to accept values for wno, wname, hrwk, wgrate and invoke calcwg ( ) to calculate netpay.
Out_data ( ) a function to display all the data members on the screen
PROGRAM:
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
class worker {
private:
int wno;
char name[25];
char subject[10];
float hrwk;
float wgrate;
float totwage;
float calcwg();
public:
void In_data();
void Out_data();
};
float worker::calcwg() {
return hrwk*wgrate;
}
void worker::In_data() {
cout<<"\nEnter worker number: ";
cin>>wno;
cout<<"\nEnter your name: ";
gets(name);
cout<<"\nEnter hour worked: ";
cin>>hrwk;
cout<<"\nEnter wage per hour : ";
cin>>wgrate;
totwage=calcwg();
}
void worker::Out_data() {
cout<<"\nYour worker number: "<<wno;
cout<<"\nYour name: "<<name;
cout<<"\nhours worked: "<<hrwk;
cout<<"\nWage per hour: "<<wgrate;
cout<<"\nYour total wages: "<<calcwg();
}
void main() {
worker w1;
w1.In_data();
w1.Out_data();
getch();
}
Monday, May 5, 2008
Using class in c++
Define a class worker with the following specifications :
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment