Question

1: Constructor and Getters 0/5 Tests the parameterized constrictor and Getter functions Compilation failed main.cpp: In func2: Setters 0/5 Tests all Setters of Employee class Compilation failed main.cpp: In function bool testPassed (std::ofstream&)3: calcPay 075 Test calcPay for both regular and overtime hours Compilation failed main.cpp: In function bool testPassed (st4: read0 and write0 0/10 Tests the write0 and static read functions Compilation failed main.cpp: In function bool testPassedThis program has two options: 1 - Create a data file, or 2 Read data from a file and print paychecks. Please enter (1) to creUnited Community Credit Union Hours worked: 12.00 Hourly wage: 30.00 Employee Name: Mary Smith Employee Number: 1 Address: 12This program has two options: 1 - Create a data file, or 2 -Read data from a file and print paychecks Please enter (1) to cre

employee.h
----------

#include <stdio.h>
#include <iostream>
#include <fstream>

class Employee {
private:
int employeeNum;
std::string name;
std::string address;
std::string phoneNum;
double hrWage, hrWorked;

public:
Employee(int en, std::string n, std::string a, std::string pn, double hw, double hwo);
std::string getName();
void setName(std::string n);
int getENum();
std::string getAdd();
void setAdd(std::string a);
std::string getPhone();
void setPhone(std::string p);
double getWage();
void setWage(double w);
double getHours();
void setHours(double h);
double calcPay(double a, double b);
static Employee read(std::ifstream& in);
void write(std::ofstream& out);
};

employee.cpp
----------
//employee.cpp

#include "employee.h"
#include <iostream>
#include <string>
using namespace std;

Employee::Employee(int en, std::string n, std::string a, std::string pn, double hw, double hwo) {
this->employeeNum = en;
this->name = n;
this->address = a;
this->phoneNum = pn;
this->hrWage = hw;
this->hrWorked = hwo;

}

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

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

int Employee::getENum() {
return employeeNum;
}

string Employee::getAdd() {
return address;
}

void Employee::setAdd(string a) {
this->address = a;
}

string Employee::getPhone() {
return phoneNum;
}

void Employee::setPhone(string p) {
this->phoneNum = p;
}

double Employee::getWage() {
return hrWage;
}

void Employee::setWage(double w) {
this->hrWage = w;
}

double Employee::getHours() {
return hrWorked;
}

void Employee::setHours(double h) {
this->hrWorked = h;
}

double Employee::calcPay(double a, double b) {
const double x = 40.00;
double gross;
if(b > 40)
{
b -= x;
gross = (a * x) + ((a + (a / 2)) * b);
}
else {
gross = a * b;
}
double net = gross - (gross * .2) - (gross * .075);
return net;
}

Employee Employee::read(ifstream &in){
string name, addr, phone;
double wage, hours;
int id;

in >> id;
if(in.fail())
throw runtime_error("end of file");

in.ignore(); //get rid of newline before using getline()
getline(in, name);
getline(in, addr);
getline(in, phone);
in >> wage >> hours;

if(in.fail())
throw runtime_error("end of file");

return Employee(id, name, addr, phone, wage, hours);
}

void Employee::write(ofstream &out)
{
out << employeeNum << endl;
out << name << endl;
out << address << endl;
out << phoneNum << endl;
out << hrWage << endl;
out << hrWorked << endl;
}

main.cpp
========

#include "employee.h"
#include <iostream>
#include <iomanip>
using namespace std;

void PrintCalc(Employee a) {

cout << "Employee Name: "<< a.getName() << endl;
cout << "Employee Number: " << a.getENum() << endl;
cout << "Address: " << a.getAdd() << endl;
cout << "Phone: " << a.getPhone() << endl;
cout << "....................UVU COMPUTER SCIENCE Dept.................................\n\n";
cout << "Pay to the order of " << a.getName() << ".................................... $" << fixed << setprecision(2) << a.calcPay(a.getWage(), a.getHours()) << endl << endl;
cout << "United Community Credit Union\n";
cout << "..............................................................................\n";
cout << "Hours worked: " << fixed << setprecision(2) << a.getHours() << endl;
cout << "Hourly wage: " << a.getWage() << endl << endl;
}

void createFile()
{
string filename;
Employee joe(37, "Joe Brown", "123 Main St.", "123-6788", 45.00, 10.00);
Employee sam(21, "Sam Jones", "45 East State", "661-9000", 30.00, 12.00);
Employee mary(15, "Mary Smith", "12 High Street", "401-8900", 40.00, 15.00);

cout << "Please enter a file name: ";
cin >> filename;

ofstream out(filename.c_str());
joe.write(out);
sam.write(out);
mary.write(out);

out.close();
cout << "Data file created ... you can now run option 2." << endl;

}

void readFile()
{
string filename;
cout << "Please enter a file name: ";
cin >> filename;

ifstream in(filename.c_str());
if(in.fail())
throw runtime_error("Couldn't open file for input");
else
{
for(int i = 0; i < 3; i++)
{
Employee e = Employee::read(in);
PrintCalc(e);
}
in.close();
}

}
int main(int argc, const char * argv[]) {
int choice = 0;

cout << "This program has two options: " << endl;
cout << "1 - Create a data file, or" << endl;
cout << "2 - Read data from a file and print paychecks." << endl;
cout << "Please enter (1) to create a file or (2) to print checks: " ;
cin >> choice;

try {
if(choice == 1)
createFile();
else if(choice == 2)
readFile();
else
cout << "Invalid choice!" << endl;
} catch (runtime_error e) {
cout << e.what() << endl;
}


return 0;
}

It keep showing these errors and I need help correcting the code above

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hello,

The program doesn't have any error that you specified. Only error which I got was as follows in the main.cpp
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
The error is corrected by including the header file #include <string> in main.cpp and I was able to execute and see the output given in screenshots.

Apart from these, there are not error found. But anyway I have identified the cause for the error based on your screenshots. If you still facing the issue, implement the below solutions:

Constructor and Getters

emp is instance of Class Employee and this class doesn't have methods getEmployeeNumber(), getAddr(), getHourlyWage() and getHoursWorked()

Solution: Replace the following methods with below given methods:

  • getEmployeeNumber() with getENum()
  • getAddr() with getAdd()
  • getHourlyWage() with getWage()
  • getHoursWorked() with getHours()

Setters

emp is instance of Class Employee and this class doesn't have methods setAddr(), setHourlyWage() and setHoursWorked()

Solution: Replace the following methods with below given methods

  • setAddr("Braintree, MA") with setAdd("Braintree, MA")
  • setHourlyWage(0.99) with setWage(0.99)
  • setHoursWorked(5000.0) with setHours(5000.0)

calcPay

  • calcPay() takes two aurgments both of type double. But as per the error message, no parameters are passed to this method
    Solution: Pass two parameters of type double to method calcPay(). Example calcPay(10.0, 20.0)
  • emp is instance of Class Employee and this class doesn't have method setHoursWorked()
    Solution: Replace setHoursWorked(43.5) with setHours(43.5)

read() and write()

emp is instance of Class Employee and this class doesn't have methods getEmployeeNumber(), getAddr(), getHourlyWage(), getHoursWorked()

Solution: Replace the following methods with below given methods

  • getEmployeeNumber() with getENum()
  • getAddr() with getAdd()
  • getHourlyWage() with getWage()
  • getHoursWorked() with getHours()

Feel free to ask further doubts. Always here to clarify

Add a comment
Know the answer?
Add Answer to:
employee.h ---------- #include <stdio.h> #include <iostream> #include <fstream> class Employee { private: int employeeNum; std::string name;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person {...

    Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person { public: Person() { setData("unknown-first", "unknown-last"); } Person(string first, string last) { setData(first, last); } void setData(string first, string last) { firstName = first; lastName = last; } void printData() const { cout << "\nName: " << firstName << " " << lastName << endl; } private: string firstName; string lastName; }; class Musician : public Person { public: Musician() { // TODO: set this...

  • //Vehicle.h #pragma once #include<iostream> #include"Warranty.h" #include<string> using namespace std; class Vehicle{ protected:    string make; int year;   ...

    //Vehicle.h #pragma once #include<iostream> #include"Warranty.h" #include<string> using namespace std; class Vehicle{ protected:    string make; int year;    double mpg;    Warranty warranty;    static int numOfVehicles; public:    Vehicle();    Vehicle(string s, int y, double m, Warranty warranty);    Vehicle(Vehicle& v);    ~Vehicle();    string getMake();    int getYear();    double getGasMileage();    void setMake(string s);    void setYear(int y);    void setYear(string y);    void setGasMileage(double m);    void setGasMileage(string m);    void displayVehicle();    static int getNumVehicles();    Warranty getWarranty();    void setWarranty(Warranty& ); }; //Vehicle.cpp #include "Vehicle.h" #include <string> Vehicle::Vehicle() {    make = "unknown";    year =...

  • Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string;...

    Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string; class Account { public: Account(); Account(string, double); void deposit(double); bool withdraw(double); string getName() const; double getBalance() const; private: string name; double balance; }; #endif ////////////////////////////////////////////// //AccountManager.hpp #ifndef _ACCOUNT_MANAGER_HPP_ #define _ACCOUNT_MANAGER_HPP_ #include "Account.hpp" #include <string> using std::string; class AccountManager { public: AccountManager(); AccountManager(const AccountManager&); //copy constructor void open(string); void close(string); void depositByName(string,double); bool withdrawByName(string,double); double getBalanceByName(string); Account getAccountByName(string); void openSuperVipAccount(Account&); void closeSuperVipAccount(); bool getBalanceOfSuperVipAccount(double&) const;...

  • #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int...

    #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int charcnt(string filename, char ch); int main() { string filename; char ch; int chant = 0; cout << "Enter the name of the input file: "; cin >> filename; cout << endl; cout << "Enter a character: "; cin.ignore(); // ignores newline left in stream after previous input statement cin.get(ch); cout << endl; chcnt = charcnt(filename, ch); cout << "# of " «< ch« "'S:...

  • #include <iostream> #include <vector> #include <fstream> #include <time.h> #include <chrono> #include <sstream> #include <algorithm> class Clock...

    #include <iostream> #include <vector> #include <fstream> #include <time.h> #include <chrono> #include <sstream> #include <algorithm> class Clock { private: std::chrono::high_resolution_clock::time_point start; public: void Reset() { start = std::chrono::high_resolution_clock::now(); } double CurrentTime() { auto end = std::chrono::high_resolution_clock::now(); double elapsed_us = std::chrono::duration std::micro>(end - start).count(); return elapsed_us; } }; class books{ private: std::string type; int ISBN; public: void setIsbn(int x) { ISBN = x; } void setType(std::string y) { type = y; } int putIsbn() { return ISBN; } std::string putType() { return...

  • Convert to use functions where possible #include<iostream> #include<string> using namespace std; int main() {    string...

    Convert to use functions where possible #include<iostream> #include<string> using namespace std; int main() {    string first, last, job;    double hours, wages, net, gross, tax, taxrate = .40;    double oPay, oHours;    int deductions;    // input section    cout << "Enter First Name: ";    cin >> first;    cout << "Enter Last Name: ";    cin >> last;    cin.ignore();    cout << "Enter Job Title: ";    getline(cin, job);    cout << "Enter Hours Worked:...

  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...

  • #include <iostream> using namespace std; class Circle{ // private member variable named radius private: double radius;...

    #include <iostream> using namespace std; class Circle{ // private member variable named radius private: double radius; // get function for radius public: double getRadius(){ return radius; } // set function for radius void setRadius(double rad){ radius=rad; } // returning area = 3.14159 * radius * radius double getArea(){ return (3.14159 * radius * radius); } }; // Sample run int main() { // Declaring object of Circle Circle myCircle; myCircle.setRadius(5); // printing radius of circle cout<<"Radius of circle is: "<<(myCircle.getRadius())<<endl;...

  • #include <iostream> #include <string> using std::string; using std::cout; using std::endl; void testAnswer(string testname, int answer, int...

    #include <iostream> #include <string> using std::string; using std::cout; using std::endl; void testAnswer(string testname, int answer, int expected) { if (answer == expected) cout << "PASSED: " << testname << " expected and returned " << answer << "\n"; else cout << "FAILED: " << testname << " returned " << answer << " but expected " << expected << "\n"; } // Implement printArray here void printArray(int array[],int b) { for(int i = 0; i<b;i++) { std::cout<< array[i] << "...

  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT