76 406
Assignments Done
Successfully Done
In May 2019

Answer to Question #50650 in C++ for zexy

Question #50650
Create a Job class that holds a Job ID number and the cost of the Job. Include insertion
and extraction operators. Create a JobException class that holds a Job and an error message.
When the user enters Job data, if the Job fee is below $250, then create a JobException
object and throw it. Write a main()function that declares an array of eight Job objects.
If a JobException object is thrown during the data entry for any Job, require the user
to enter data for a new Job, and replace the invalid Job. Save the file as Job.cpp.
Expert's answer
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <string>
using namespace std;
class Jobs{
int idNumber;
double cost;
Jobs() {idNumber = 0; cost = 0;};
Jobs(int _idNumber, int _cost){idNumber = _idNumber; cost = _cost;}
class JobException{
Jobs job;
string message;
JobException(Jobs _job, string _message = "Error!!!Cost of the job can not be below 250$!") {
job = _job;
message = _message;
// insertion
ostream & operator<<(ostream &stream;, Jobs obj)
stream <<"----------------------------------\n"<<endl;
stream <<" id number = "<< obj.idNumber << "\n ";
stream <<"cost = "<<obj.cost << "\n";
stream <<"----------------------------------\n"<<endl;
return stream;
// extraction
istream &operator;>>(istream &stream;, Jobs &obj;)
cout << "Enter cost of the Job: ";
stream >> obj.cost;
if (obj.cost < 250) throw JobException(obj);
return stream;
int main(){
Jobs jobs[8];
for (int i = 0; i < 8; i++)
jobs[i].idNumber = i;
catch (JobException jobExp){
cout<<endl<<endl<<"Jobs: "<<endl;
for (int i = 0; i < 8; i++)
return 0;

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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions