title: Passing class objects into function parameters c++
body: <p>I have read several of the previously asked questions on this topic, but can't seem to find the answer I'm looking for. When I run the program I receive no errors, but  I get a lot of garbage data. I know it's because I'm not passing the parameters right, but I'm new to c++ and specifically how to use pointers correctly. To make it simple: I am passing an employee object through <code>PrintCheck()</code>, which calls the <code>CalcSalary()</code> function, which must use <code>GetHours()</code> and <code>GetWage()</code> to access member data to do calculations and return the correct <code>salary</code>. Would appreciate any explanations as to why I am generating garbage data!</p>
  
  <p>I have a class:</p>
  
  <pre><code>class Employee
  {
  private:
      int employeeNumber;
      string name;
      string streetAddress;
      string phoneNumber;
      double hourlyWage;
      double hoursWorkedperWeek;
  public:
      Employee(void);
      Employee(int, string, string, string, double, double);
      int GetEmployeeNum() const;
      void SetEmployeeNum(int);
      string GetName() const;
      void SetName(string);
      string GetAddress() const;
      void SetAddress(string);
      string GetPhone() const;
      void SetPhone(string);
      double GetWage() const;
      void SetWage(double);
      double GetHours() const;
      void SetHours(double);
      double CalcPay(double, double);
  };
  </code></pre>
  
  <p>I also have a function that needs to interact with the class:</p>
  
  <pre><code>void PrintCheck(Employee&amp;);
  </code></pre>
  
  <p>My main function looks like:</p>
  
  <pre><code>void main()
  {
      Employee joe(1, "Joe Blo", "125 Cool St.", "555 555 5555", 10.00, 45); //create employee 1
      Employee jane(2, "Jane Doe", "521 Dumb St.", "1 800 555 5555", 12.50, 30); //create employee 2
      PrintCheck(joe); //print check
  }
  </code></pre>
  
  <p>The printcheck function looks like: </p>
  
  <pre><code>void PrintCheck(Employee&amp; a)
  {
  
      cout &lt;&lt; "Pay to the order of " &lt;&lt; a.GetName() &lt;&lt; "...................................";
      cout &lt;&lt; a.CalcPay(a.GetWage(), a.GetHours()) &lt;&lt; endl;
      cout &lt;&lt; "Hours worked: " &lt;&lt; a.GetHours() &lt;&lt; endl;
      cout &lt;&lt; "Hourly wage: " &lt;&lt; a.GetWage() &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Calcpay function is:</p>
  
  <pre><code>double Employee::CalcPay(double h, double w)
  {
      double salary = 0;
      int OT = 40;
      double timeandahalf = 1.5;
      double STATE = .075;
      double FED = .20;
      if (h &gt; OT) // overtime
      {
          salary = h * (w * timeandahalf); // calc time and a half
          salary = salary * STATE; // calc state deductions
          salary = salary * FED; // calc federal deductions
      }
      else 
      {
          salary = h * w; // calc salary
          salary = salary * STATE; // calc state deductions
          salary = salary * FED; // calc federal deductions
      }
      cout.setf(ios::fixed);
      cout.setf(ios::showpoint);
      cout.precision(PRECISION);
      return salary;
  }
  </code></pre>
  
  <p>My "get" functions all follow this pattern:</p>
  
  <pre><code>int Employee::GetEmployeeNum() const
  {
      return employeeNumber;
  }
  </code></pre>
  
  <p>My expected output would be:</p>
  
  <pre><code>Pay to the order of:  Joe Blo............ $salary.
  Hours worked: $hours.
  Hourly wage: $wage.
  </code></pre>
  
  <p>What I got:</p>
  
  <pre><code>Pay to the order of: ........................ 128509280503000000000000000000000000000.00 (this number is long, but I didn't feel like typing them all)
  Hours worked: -9723636237 (same, just tons of bs numbers)
  Hourly wage: (the exact same number as above)
  </code></pre>
  
  <p>My class constructor:</p>
  
  <pre><code>Employee::Employee(int en, string n, string a, string p, double w, double h)
  {
      int employeeNumber = en;
      string name = n;
      string streetAddress = a;
      string phoneNumber = p;
      double hourlyWage = w;
      double hoursWorkedperWeek = h;
  }
  Employee::Employee()
  {
  }
  </code></pre>