Design a Job class with three data fields-Job number, time in hours to complete the Job, and per-hour rate charged for the Job.
Include overloaded extraction and insertion operators that get and display a Job's values.
Include overloaded + and - operators that return integers that indicate the total time for two Jobs, and indicate the difference in time between two Jobs, respectively.
Write a main()function demonstrating that all the functions work correctly.
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
class Job{
public:
int jobNumber;
int time;
int perHourRate;
Job(int jobNumber, int time, int perHourRate)
{
this->jobNumber = jobNumber;
this->time = time;
this->perHourRate = perHourRate;
}
Job operator + (Job const &j1)
{
Job res(j1);
res.time = this->time + j1.time;
return res;
}
Job operator - (Job const &j1)
{
Job res(j1);
res.time = abs(this->time - j1.time);
return res;
}
};
int main()
{
Job j1(101953024, 5, 12);
Job j2(101953025, 8, 10);
Job j3 = j1+j2;
Job j4 = j1-j2;
cout<<"Total time : "<<j3.time<<" hours"<<endl;
cout<<"Difference in time : "<<j4.time<<" hours";
}
Comments
Leave a comment