/********************************
ASSIGNMENT: (1) write a program that
declares a class called "employee" with these
data members: itsAge, itsYearsOfService, itsSalary.
(2) write the code for a method of employee
class that reports how many thousand of dollars
the employee earns, rounded to nearest 1,000
HOD: Teach ur self c++ in 21days
STUDENT: Xarmzon.
********** †*******************/
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <ctime>
usingnamespace std;
class employee
{
public:
int getAge(){
return itsAge;
}
void setAge(int age){
itsAge = age;
}
int getYearsOfService(){
return itsYearsOfService;
}
void setYearsOfService(int yearsOfS){
itsYearsOfService = yearsOfS;
}
int getSalary(){
return itsSalary;
}
void setSalary(int salary){
itsSalary = salary;
}
private:
int itsAge;
int itsYearsOfService;
int itsSalary;
};
int main()
{
string name;
employee age;
age.setAge(20);
employee year;
year.setYearsOfService(6);
cout << "Enter your name: ";
getline (cin, name);
cout << name << " is "<< age.getAge() << " years of age and " << year.getYearsOfService() << " years of age in service." <<endl;
}
I don't think there is any bug in your program (tell me where if there is any), but it seems you don't understand what you can do with your class employee, so here is some explanation.
With your class, it's enough to declare a single object and this object will have all the data members you've declared in the class: itsAge, itsYearsOfService, itsSalary.