i've been looking over my work more and i think i got the hang of all that other stuff i've been doing...but this overloading stuff is a little confusing. would this program be right if i was trying to just find the 3 things out about jobA and display them? i want to make sure i get this part right before i go ahead and do the rest of the problem. I get an error that says that there is no appropriate constructor for the Job class, and i get errors in my declaration of the operator>> fuction that says it cant access the members of Job, but I think its because it says theres no constructor. anybody know why that is?
Code:
#include<iostream.h>
#include<string.h>
class Job
{
friend istream& operator>>(istream& in, const Job &jobA);
friend ostream& operator<<(ostream& out, const Job &jobA);
private:
int JobNum;
int hours;
double rate;
public:
Job(const int JobNum, const int hours, const double rate);
};
istream& operator>>(istream& in, Job &jobA)
{
cout<<endl;
cout<<"Enter a job number: ";
in>>jobA.JobNum;
cout<<"Hours to complete: ";
in>>jobA.hours;
cout<<"Rate per hour: ";
in>>jobA.rate;
return(in);
}
ostream& operator<<(ostream& out, const Job &jobA)
{
out<<"Job #"<<jobA.JobNum<<" takes "<<jobA.hours<<" hours at $"<<jobA.rate<<" per hour."<<endl;
return(out);
}
int main()
{
Job jobA; // instantiates an object, jobA
cin>>jobA; //interactive input for data means no explicit
// constructor needed (page 289)
cout<<jobA; // output pretty data members (page 288)
// The following line is for part c, using overload + and - operators
// cout<<"The difference between "<<jobA<<" and "<<jobB<<" is
// "<<(jobA - jobB)<<" hours"<<endl; (page 278)
}