Question: Need help debugging my code in C++ first I will post the code followed by the error. // employee.h class Employee { public: Employee(int employeeNumber,

Need help debugging my code in C++ first I will post the code followed by the error.

// employee.h

class Employee { public: Employee(int employeeNumber, std::string name, std::string address, std::string phone, double hourlyWage, double hoursWorked); int getEmployeeNumber() const; const std::string getName() const; const std::string getAddress() const; const std::string getPhone() const; double getHourlyWage() const; double getHoursWorked() const; void setName(std::string& name); void setAddress(std::string& address); void setPhone(std::string& phone); void setHourlyWage(double hourlyWage); void setHoursWorked(double hoursWorked); double calcPay() const; void printCheck() const;

private: int empNum; std::string name; std::string address; std::string phone; double hourlyWage; double hoursWorked; };

_____________________

// employee.cpp

#include #include "employee.h"

using namespace std;

Employee::Employee(int employeeNumber, string name, string address, string phone, double hourlyWage, double hoursWorked) : name(name), address(address), phone(phone) { this->empNum = employeeNumber; this->hourlyWage = hourlyWage; this->hoursWorked = hoursWorked; }

int Employee::getEmployeeNumber() const { return empNum; }

const string Employee::getName() const { return name; }

const string Employee::getAddress() const { return address; }

const string Employee::getPhone() const { return phone; }

double Employee::getHourlyWage() const { return hourlyWage; }

double Employee::getHoursWorked() const { return hoursWorked; }

void Employee::setName(string& name) { this->name = name; }

void Employee::setAddress(string& address) { this->address = address; }

void Employee::setPhone(string& phone) { this->phone = phone; }

void Employee::setHourlyWage(double hourlyWage) { this->hourlyWage = hourlyWage; }

void Employee::setHoursWorked(double hoursWorked) { this->hoursWorked = hoursWorked; }

double Employee::calcPay() const { double baseHours = (hoursWorked >= 40.0 ? 40.0 : hoursWorked); double overTime = (hoursWorked >= 40.0 ? (hoursWorked - 40.0) : 0); double grossPay = (baseHours * hourlyWage) + (overTime * hourlyWage * 1.5);

double fedTax = grossPay * 0.20; double stateTax = grossPay * 0.075; return grossPay - fedTax - stateTax; }

// Uses void Employee::printCheck() const { cout.setf(ios::showpoint); cout.setf(ios::fixed); cout.precision(2);

cout << endl << "....................UVU Computer Science Dept................................." << endl << "Pay to the order of " << name << "....................................$" << calcPay() << endl << endl << "United Community Credit Union" << endl << ".............................................................................." << endl << endl << "Hours worked: " << hoursWorked << endl << "Hourly wage: " << hourlyWage << endl << endl; }

_____________________

// main.cpp

#include #include #include "employee.h"

using namespace std;

void printEmployeeInfo(const Employee& e);

int main() { Employee joe(37, "Joe Brown", "123 Main St.", "123-6788", 10.00, 45.00); Employee sam(38, "Sam Jones", "45 East State", "661-9000", 12.50, 30.00);

printEmployeeInfo(joe); joe.printCheck();

printEmployeeInfo(sam); sam.printCheck();

return 0; }

void printEmployeeInfo(const Employee& e) { cout << "Employee Name: " << e.getName() << endl << "Employee Number: " << e.getEmployeeNumber() << endl << "Address: " << e.getAddress() << endl << "Phone: " << e.getPhone() << endl; }

Error:

main.cpp: In function bool testPassed(std::ofstream&): main.cpp:20:30: error: invalid initialization of non-const reference of type std::__cxx11::string& {aka std::__cxx11::basic_string&} from an rvalue of type std::__cxx11::string {aka std::__cxx11::basic_string} emp.setName("Thomas Doggett");

In file included from /usr/include/c++/6/string:52:0, from /usr/include/c++/6/bits/locale_classes.h:40, from /usr/include/c++/6/bits/ios_base.h:41, from /usr/include/c++/6/ios:42, from /usr/include/c++/6/ostream:38, from /usr/include/c++/6/iostream:39, from main.cpp:2:

/usr/include/c++/6/bits/basic_string.h:454:7: note: after user-defined conversion: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator] basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()) ^~~~~~~~~~~~

In file included from main.cpp:4:0: employee.h:10:9: note: initializing argument 1 of void Employee::setName(std::__cxx11::string&) void setName(std::string& name); ^~~~~~~

main.cpp:21:29: error: invalid initialization of non-const reference of type std::__cxx11::string& {aka std::__cxx11::basic_string&} from an rvalue of type std::__cxx11::string {aka std::__cxx11::basic_string} emp.setAddr("Braintree, MA");

In file included from /usr/include/c++/6/string:52:0, from /usr/include/c++/6/bits/locale_classes.h:40, from /usr/include/c++/6/bits/ios_base.h:41, from /usr/include/c++/6/ios:42, from /usr/include/c++/6/ostream:38, from /usr/include/c++/6/iostream:39, from main.cpp:2:

/usr/include/c++/6/bits/basic_string.h:454:7: note: after user-defined conversion: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator] basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()) ^~~~~~~~~~~~

In file included from main.cpp:4:0: employee.h:11:9: note: initializing argument 1 of void Employee::setAddr(std::__cxx11::string&) void setAddr(std::string& address); ^~~~~~~

main.cpp:22:29: error: invalid initialization of non-const reference of type std::__cxx11::string& {aka std::__cxx11::basic_string&} from an rvalue of type std::__cxx11::string {aka std::__cxx11::basic_string} emp.setPhone("disconnected"); ^

In file included from /usr/include/c++/6/string:52:0, from /usr/include/c++/6/bits/locale_classes.h:40, from /usr/include/c++/6/bits/ios_base.h:41, from /usr/include/c++/6/ios:42, from /usr/include/c++/6/ostream:38, from /usr/include/c++/6/iostream:39, from main.cpp:2:

/usr/include/c++/6/bits/basic_string.h:454:7: note: after user-defined conversion: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator] basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()) ^~~~~~~~~~~~

In file included from main.cpp:4:0: employee.h:12:9: note: initializing argument 1 of void Employee::setPhone(std::__cxx11::string&) void setPhone(std::string& phone); ^~~~~~~~

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!