help with this assignment

I need help in part(2) question
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  
/********************************

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>

using namespace 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;


}
Last edited on
Hi xarmzon,

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.

So you must proceed like this:

1
2
3
employee someEmployee;
someEmployee.setAge(20);
someEmployee.setYearsOfService(6);


And now, you can access the different data members, using:
 
cout << someEmployee.getAge() << "  " << someEmployee.getYearsIfService() << endl;



Does it make sens ?
yes! have done that before. my problem is question 2
Last edited on
What do you have so far ?
Topic archived. No new replies allowed.