School Project (cannot reach instructor)

PLEASE PLEASE PLEASE do not simply give me the answer. I am posting to this forum because my teacher is unreachable at the moment, and I have an assignment due next week.

That out of the way: my problem.

I am trying to complete a problem on classes. Between some help I received previously, and similar exercises in the book, I derived the attached. The issue is not in compiling or linking, but rather in producing meaningful outputs. The outputs I want are specified in the two objects I declare in main. The only other output is a simple calculation, which will be easy once I get the program to read the values initialized in the two objects. Any help you offer would be useful. Nevertheless, I am rather new at this. I have a rather good ("Highschool") understanding of Programing, but some of the more advanced terminology still evades me. So, while any help is still good, help written or explained at my level would be most beneficial.

As a final note, the assignment is due by next Thursday, the 26th, and I will not be able to get in contact with my teacher before around the 23rd, so I would like to get the majority of the bugs worked out before then. As far as intellectual property and sources go, I will be transparent about where the help originated.

Thank you.

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
#include <iostream>
#include <string>

using namespace std;

class Employee // from Hint
{ 
     public:
             Employee(string First,string Last,double Salary) 
             {
             SetFirst(First);
             SetLast(Last);
             SetBaseSalary(Salary);
             SetSalary(Salary);
             } 
             // functions for geting and setting first and last names and salaries
             void SetFirst(string First)
             {
                  FirstName = First;
             }
             
             string GetFirst(string First)
             {
                    FirstName = First;
                    return FirstName;
             }
            
             void SetLast(string Last)
             {
                  LastName = Last;
             }
             
             string GetLast(string LastName)
             {
                    return LastName;
             }
             
             void SetBaseSalary (double Salary)
             {
                 SalaryAmount = Salary;//Salary from Main does not pass through this properly.  if the salary for lisa is replaced with 1.1 the output is still 20.01
             }
             
             double GetBaseSalary (double SalaryAmount)
             {
                    return SalaryAmount;
             }
                    
             void SetSalary(double Salary)
             {
                  SalaryAmount = Salary * 1.1;
             }
             
             double GetSalary(double SalaryAmount)
             {
                    return SalaryAmount;
             }             
     private:
            
            string FirstName;
            string LastName;
            double SalaryAmount;
};

int main ()
{
// Inputs
string First = "Bruton";
string Last = "Gaster";
double Salary = 20.01;
Employee Emp1 ("Lisa", "Roberts", 54000.0); // Declare first employee object (the funtion is not reading any values put in this declaration.  
                                            // If line 69 read string First = "Bruton", the out put for Emp1 would be Bruton, not Lisa.
Employee Emp2 ("Mark", "Stein", 48000.0); // Declare second employee object
cout << "Employees' Yearly Salaries:" << endl;
cout << Emp1.GetFirst(First) << " " << Emp1.GetLast(Last) << ": $" << Emp1.GetBaseSalary(Salary) << endl;
cout << Emp2.GetFirst(First) << " " << Emp2.GetLast(Last) << ": $" << Emp2.GetBaseSalary(Salary) << endl;
cout << endl; // displays employee names and base salaries on different lines with an extra line at the end. 
    
// Output
cout << "Employees' Yearly Salaries After Ten Percent Raise:" << endl;
cout << Emp1.GetFirst(First) << Emp1.GetLast(Last) << ": $" << Emp1.GetSalary(Salary) << endl;
cout << Emp2.GetFirst(First) << Emp2.GetLast(Last) << ": $" << Emp2.GetSalary(Salary) << endl;
cout << endl; // displays employee names and salaries on different lines with an extra line at the end. 
                
system("pause"); 
return 0;
}
When you have "getters" (ie. functions that only retrieve values from an object) you typically want to make them const:

1
2
3
4
double GetSalaray(double salaryAmount) const
{
    return SalaryAmount ;
}


This indicates to the compiler and users of the class that GetSalary will not modify the object it is invoked for. Had you done so, your compiler would've issued an error when it ran into:

1
2
3
4
5
             string GetFirst(string First)
             {
                    FirstName = First;
                    return FirstName;
             }


If this were a const function, it wouldn't allow you to modify the object in the body of the function.

Also, "getters" should take no arguments.

1
2
3
4
string GetFirst()
{
    return FirstName ;
}
Topic archived. No new replies allowed.