- #1
- 350
- 0
Since I don't know how to use the code on physics forums, I'll just type the problem I'm working on
I'm supposed to write a program with the class Employee that makes two employees; sets their age, yearsOfService, and Salary; and prints their values
# include <iostream>
using namespace std;
class Employee
{
public:
int GetAge() const;
void SetAge(int age);
int GetYearsOfService()const;
void SetYearsOfService(int years);
int GetSalary()const;
void SetSalary(int salary);
private:
int Age;
int YearsOfService;
int Salary;
};
int Employee::GetAge()
{
return Age;
}
void Employee::SetAge(int age)
{
Age = age;
}
int Employee::GetYearsOfService()
{
return YearsOfService;
}
void Employee::SetYearsOfService(int years)
{
YearsOfService = years;
}
int Employee::GetSalary()
{
return Salary;
}
void Employee::SetAge(int salary)
{
Salary = salary;
}
int main()
{
Employee John;
Employee Sally;
John.SetAge(30);
John.SetYearsOfService(5);
John.SetSalary(50000);
Sally.SetAge(32);
Sally.SetYearsOfService(8);
Sally.SetSalary(40000);
cout << "At a company, John and Sally work.\n";
cout << "John is " << John.GetAge() << " years old and has been working for";
cout << John.GetYearsOfService() << " years and is paid" << John.GetSalary() << "annually.\n\n";
cout << "Sally is" << Sally.GetAge() << " years old and has been working for";
cout << Sally.GetYearsOfService() << " years and is paid" << John.GetSalary() << "annually.\n\n";
return 0;
}
I really need help with this. I copied the exact code in the back of my textbook that provides the answer for this code, and I still got errors. So I changed it a bit and I'm still getting errors. I would greatly appreciate any help!
I'm supposed to write a program with the class Employee that makes two employees; sets their age, yearsOfService, and Salary; and prints their values
# include <iostream>
using namespace std;
class Employee
{
public:
int GetAge() const;
void SetAge(int age);
int GetYearsOfService()const;
void SetYearsOfService(int years);
int GetSalary()const;
void SetSalary(int salary);
private:
int Age;
int YearsOfService;
int Salary;
};
int Employee::GetAge()
{
return Age;
}
void Employee::SetAge(int age)
{
Age = age;
}
int Employee::GetYearsOfService()
{
return YearsOfService;
}
void Employee::SetYearsOfService(int years)
{
YearsOfService = years;
}
int Employee::GetSalary()
{
return Salary;
}
void Employee::SetAge(int salary)
{
Salary = salary;
}
int main()
{
Employee John;
Employee Sally;
John.SetAge(30);
John.SetYearsOfService(5);
John.SetSalary(50000);
Sally.SetAge(32);
Sally.SetYearsOfService(8);
Sally.SetSalary(40000);
cout << "At a company, John and Sally work.\n";
cout << "John is " << John.GetAge() << " years old and has been working for";
cout << John.GetYearsOfService() << " years and is paid" << John.GetSalary() << "annually.\n\n";
cout << "Sally is" << Sally.GetAge() << " years old and has been working for";
cout << Sally.GetYearsOfService() << " years and is paid" << John.GetSalary() << "annually.\n\n";
return 0;
}
I really need help with this. I copied the exact code in the back of my textbook that provides the answer for this code, and I still got errors. So I changed it a bit and I'm still getting errors. I would greatly appreciate any help!