Hey guys I'm having some trouble figuring out what is going on I'd appreciate if anyone could help here is the instructions.
5. The SalesEmployee constructor
a. uses a_commission and a_sales arguments to initialize the commission and sales
member variables respectively
b. calls the SalariedEmployee constructor and passes to it name and salary -
remember that this is a constructor call that takes two arguments
6. The SalariedEmployee constructor
a. uses a_salary to initialize the salary member variable
b. calls the Employee constructor and passes to it name
7. The WagedEmployee constructor
a. uses a_wage and a_hours to initialize the wage and hours member variables
respectively
b. calls the Employee constructor and passes to it name
8. The Employee constructor
a. should initialize the name member variable
9. The SalesEmployee operator<<
a. should call the SalariedEmployee operator<< to print the salary
b. should print the commission and sales
10. The SalariedEmployee operator<<
a. should call the Employee operator<< to print the name
b. should print the salary
11. The WagedEmployee operator<<
a. should call the Employee operator<< to print the name
b. should print the wage and hours
12. The Employee operator<<
a. should print the name

Here is my code so far:

//Driver.cpp
#include "Employee.h"
#include "SalariedEmployee.h"
#include "SalesEmployee.h"
#include "WagedEmployee.h"
#include <iostream>
#include <string>
using namespace std;


void prompt(char* message, string& variable);
void prompt(char* message, double& number);


int main()
{
    while (true)
    {
        cout << endl;
        cout << "1. Waged Employee" << endl;
        cout << "2. Salaried Employee" << endl;
        cout << "3. Sales Employee" << endl;
        cout << "4. Exit" << endl << endl;
        cout << "Choose an Employee or an Action: ";

        char c;
        cin >> c;
        cin.ignore();               // discard new-line (see the 2nd version of prompt)

        string  name;               // variables used by all employee types

        switch (c)
        {
        case '1' :
            {
                double  wage;
                double  hours;
                prompt("Name", name);
                prompt("Wage", wage);
                prompt("Hours", hours);
                WagedEmployee* we = new WagedEmployee(name, wage, hours);
                cout << *we << endl;
                break;
            }

        case '2' :
            {
                double  salary;
                prompt("Name", name);
                prompt("Salary", salary);
                SalariedEmployee* se = new SalariedEmployee(name, salary);
                cout << *se << endl;
                break;
            }

        case '3' :
            {
                double  salary;
                double  commission;
                double  sales;
                prompt("Name", name);
                prompt("Salary", salary);
                prompt("Commission", commission);
                prompt("Sales", sales);
                SalesEmployee* se = new SalesEmployee(name, salary, commission, sales);
                cout << *se << endl;
                break;
            }

        case '4' :
            exit(0);
        }
    }

    return 0;
}


void prompt(char* message, string& variable)
{
    cout << message << ": ";
    getline(cin, variable);
}


void prompt(char* message, double& number)
{
    cout << message << ": ";
    cin >> number;
    cin.get();      // discard \n following number
}



#ifndef _EMPLOYEE_H_
#define _EMPLOYEE_H_
#include <iostream>
#include <string>

using namespace std;

class Employee
{

    private:
        string name;

    public:
        Employee(string a_name) : name(a_name){}

        friend  ostream& operator<<(ostream& out, Employee& me){
        out << me.name << endl;
        return out;
    }  
};

#endif



#ifndef _SALARIEDEMPLOYEE_H_
#define _SALARIEDEMPLOYEE_H_
#include <string>
#include <iostream>
#include "Employee.h"

using namespace std;

class SalariedEmployee : public Employee
{

    private:
        double salary;

    public: 
        SalariedEmployee(string name, double salary) : Employee(name), salary(a_salary){}

        friend  ostream& operator<<(ostream& out, SalariedEmployee& me){
        out << (Employee &)me << "\n Wage: " << me.salary << endl;
        return out;
    }

};

#endif


#ifndef _WAGEDEMPLOYEE_H_
#define _WAGEDEMPLOYEE_H_
#include <string>
#include <iostream>
#include "SalariedEmployee.h"
#include "Employee.h"

using namespace std;

class WagedEmployee : public Employee
{

    private:
        double wage;
        double hours;

    public: 
        WagedEmployee(string name, double a_wage, double a_hours) : Employee(name), wage(a_wage), hours(a_hours){}

        friend  ostream& operator<<(ostream& out, WagedEmployee& me){
        out << (Employee&)me << "\n Wage: " << me.wage << "\n Hours: " << me.hours << endl;
        return out;
    }
};

#endif



#ifndef _SALESEMPLOYEE_H_
#define _SALESEMPLOYEE_H_
#include <string>
#include <iostream>
#include "SalariedEmployee.h"
#include "WagedEmployee.h"
#include "Employee.h"

using namespace std;

class SalesEmployee : public SalariedEmployee
{

    private:
        double commission;
        double sales;

    public:
        SalesEmployee(string name, double salary, double a_commission, double a_sales) : SalariedEmployee(name), commission(a_commission), sales(a_sales){}

        friend ostream& operator<<(ostream& out, SalesEmployee& me){
        out << (SalariedEmployee&)me << "\n Salary: " << me.salary << "\n Wage: " << me.commission << "\n Sales: " << me.sales << endl;
        return out;
    }
};

#endif

Recommended Answers

All 4 Replies

You need to pass the salary on line 195 to the SalariedEmployee constructor

here is the error visual studio is giving me if it helps

1>------ Build started: Project: lab8, Configuration: Debug Win32 ------
1>Build started 11/7/2012 4:51:20 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\lab8.unsuccessfulbuild".
1>ClCompile:
1>  driver.cpp
1>c:\users\cody\documents\visual studio 2010\projects\lab8\lab8\salariedemployee.h(16): error C2065: 'a_salary' : undeclared identifier
1>c:\users\cody\documents\visual studio 2010\projects\lab8\lab8\salesemployee.h(19): error C2664: 'SalariedEmployee::SalariedEmployee(const SalariedEmployee &)' : cannot convert parameter 1 from 'std::string' to 'const SalariedEmployee &'
1>          Reason: cannot convert from 'std::string' to 'const SalariedEmployee'
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\cody\documents\visual studio 2010\projects\lab8\lab8\salesemployee.h(22): error C2248: 'SalariedEmployee::salary' : cannot access private member declared in class 'SalariedEmployee'
1>          c:\users\cody\documents\visual studio 2010\projects\lab8\lab8\salariedemployee.h(13) : see declaration of 'SalariedEmployee::salary'
1>          c:\users\cody\documents\visual studio 2010\projects\lab8\lab8\salariedemployee.h(9) : see declaration of 'SalariedEmployee'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.23
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is your first erorr: SalariedEmployee(string name, double salary) : Employee(name), salary(a_salary){}. As you can see salary and a_salary are not the same. You need to change one of them to match the other. I already cover the second error in my first post.

I got it thanks a lot :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.