Answers 831
D
34: Employee John;
35: Employee Sally;
36:
37: John.SetAge(30);
38: John.SetYearsOfService(5);
39: John.SetSalary(50000);
40:
41: Sally.SetAge(32);
42: Sally.SetYearsOfService(8);
43: Sally.SetSalary(40000);
44:
45: cout << “At AcmeSexist company, John and Sally have “;
46: cout << “the same job.\n\n”;
47:
48: cout << “John is “ << John.GetAge() << “ years old.” << endl;
49: cout << “John has been with the firm for “ ;
50: cout << John.GetYearsOfService() << “ years.” << endl;
51: cout << “John earns $” << John.GetSalary();
52: cout << “ dollars per year.\n\n”;
53:
54: cout << “Sally, on the other hand is “ << Sally.GetAge();
55: cout << “ years old and has been with the company “;
56: cout << Sally.GetYearsOfService();
57: cout << “ years. Yet Sally only makes $” << Sally.GetSalary();
58: cout << “ dollars per year! Something here is unfair.”;
59: }
- The following is one possible answer:
float Employee::GetRoundedThousands() const
{
return Salary / 1000;
} - The following is one possible answer:
class Employee
{
public:
Employee(int age, int years, int salary);
int GetAge() const;
void SetAge(int age);
int GetYearsOfService() const;
void SetYearsOfService(int years);
int GetSalary() const;
void SetSalary(int salary);
private:
int itsAge;
int itsYearsOfService;
int itsSalary;
};
32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 831