I got the idea to write this out of a book as a little project for myself. It works, but I'm thinking their had be be an easier way. I'm just starting, and struggling with the usage (not concept) of classes. Any suggestions will be greatly appreciated.
Thanks in advance.
#include <iostream.h>
class Bob
{
public:
Bob();
void input_bob();
void output_bob();
int getBobAge() {return itsAge;}
int getBobYearOnJob() {return itsYears;}
double getBobSalary() {return itsSalary;}
void setBobAge(int Age) {itsAge = Age;}
void setBobYearsOnJob(int YOJ) {itsYears = YOJ;}
void setBobSalary(double Salary) {itsSalary = Salary;}
private:
int itsAge, itsYears;
double itsSalary;
};
class Martha
{
public:
Martha();
void input_martha();
void output_martha();
int getMarthaAge() {return itsAge;}
int getMarthYearOnJob() {return itsYears;}
double getMarthaSalary() {return itsSalary;}
void setMarthaAge(int Age) {itsAge = Age;}
void setMarthaYearsOnJob(int YOJ) {itsYears = YOJ;}
void setMarthaSalary(double Salary) {itsSalary = Salary;}
private:
int itsAge, itsYears;
double itsSalary;
};
Bob bob;
Martha martha;
int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "This program will show the user two different employees for Widegets Inc.\n";
cout << "These two employees are Bob and Martha,\n";
cout << "and you will be asked to input some data for each one.\n";
cout << "The this program will output that data you have given it. Ready?\n";
bob.input_bob();
martha.input_martha();
bob.output_bob();
martha.output_martha();
return 0;
}
Bob::Bob()
{
itsAge = 0;
itsYears = 0;
itsSalary = 0;
}
Martha::Martha()
{
itsAge = 0;
itsYears = 0;
itsSalary = 0;
}
void Bob::input_bob()
{
cout << "Type in Bob's age: ";
cin >> itsAge;
cout << "Type in Bob's number of years on the job: ";
cin >> itsYears;
cout << "Type in Bob's hourly wage: $";
cin >> itsSalary;
}
void Martha::input_martha()
{
cout << "Type in Martha's age: ";
cin >> itsAge;
cout << "Type in Martha's number of years on the job: ";
cin >> itsYears;
cout << "Type in Martha's hourly wage: $";
cin >> itsSalary;
}
void Martha:utput_martha()
{
cout << "\nMartha is " << martha.getMarthaAge() << " years old.\n";
cout << "Martha has been with Widgets Inc. for " << martha.getMarthYearOnJob() << " years.\n";
cout << "Martha's current hourly wage is $" << martha.getMarthaSalary() << " dollars and hour.\n";
}
void Bob:utput_bob()
{
cout << "\nBob is " << bob.getBobAge() << " years old.\n";
cout << "Bob has been with Widgets Inc. for " << bob.getBobYearOnJob() << " years.\n";
cout << "Bob's current hourly wage is $" << bob.getBobSalary() << " dollars and hour.\n";
}