Answer to Question #214686 in C++ for Shivani

Question #214686

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.


1
Expert's answer
2021-07-07T06:26:28-0400
#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";
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS