Problems with my structure code?

For some reason the only output that I'm getting is the following: http://imgur.com/2jrXCem Does anyone have any idea why? I just learned structures a few days ago and I'm assuming that i'm calling the member function wrong. Thanks for the help.

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
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<iostream>
#include<string>
using namespace std;
const int  W_H=40;

class Employee {

public:
  // fname is the Employee's first name, lname is their last name, title is their position, id is their identification number, and s is their salary.
  void set(string f_name, string l_name, string title, int id, float salary);
 // this method is returning an employee's first name
 string getFirstName();
 // retrieves last name of employee
 string getLastName();
 // sets the salary of the employee
 void setSalary(float h_rate, float h_work);
 // retrieves the title of an employee
 string getTitle();
 // returns the ID of an employee
 int getID();
 // retrieves the salary of an employee
 float getSalary();

private:
 string f_name; // First Name
 string l_name; // Last Name
 int id;        // Identification Number
 string title;  // The position of the worker
 float salary;  // Hourly rate of employee
};

void Employee::set(string n, string l, string t, int id, float s){
    n=f_name;
    l=l_name;
    t=title;
   this->id =id;
    s=salary;
}

void Employee::setSalary(float h_rate, float h_work){
 float OT, m_pay, m_OT, total;
 total= h_rate*h_work;
 float pay;
 if (h_work<=40)
    pay= total;
 else if (h_work>40)
    pay=1.5*total;
 //else if (title="Manager")
    //pay= 2*total;
 //else if (title="Manager" && h_work>40)
    //pay= 2.5*total;
 else if (h_work>40)
    pay= 1.5*total;
}
string Employee::getFirstName() {
    return f_name;
}
string Employee::getLastName() {
    return l_name;
}
string Employee::getTitle() {
    return title;
}
int Employee::getID(){
   return id;
}
float Employee::getSalary(){
  return salary;
}


int main() {
Employee e1, e2, e3;
e1.set("Bob", "Smith", "Manager", 201, 15.00);
e2.set("Steve", "Camp", "Entry", 611, 10.50);
e3.set("Jackie", "Marie", "Entry", 650, 12.85);
cout << e1.getFirstName() << " " << e1.getLastName() << " salary is: " << endl;
e1.setSalary (15.00, 40);
cout << e2.getFirstName() << " " << e2.getLastName() << " salary is: " << endl;
e2.setSalary(10.50, 50);
cout << e3.getFirstName() << " " << e3.getLastName() << " salary is: " << endl;
e3.setSalary (12.85, 60);

return 0;
}

  
Last edited on
i know that i have a few functions in the implementation as notes, still need to work on those but e2 and e3 should still show up since they arent managers.
1
2
3
4
5
6
7
void Employee::set(string n, string l, string t, int id, float s){
    n=f_name;
    l=l_name;
    t=title;
   this->id =id;
    s=salary;
}


You have the assignments mixed up. You should be changing the data member, not the parameter.

1
2
3
4
5
6
7
void Employee::set(string n, string l, string t, int id, float s){
    f_name=n;
    l_name=l;
    title=t;
   this->id =id;
    salary=s;
}


Also, shouldn't you be calling getSalary() when you print the information?
cout << e1.getFirstName() << " " << e1.getLastName() << " salary is: " /*<< e1.getSalary() ?*/<< endl;
thanks for the help! i made some stupid mistakes and was able to fix them :)
Topic archived. No new replies allowed.