I have been working on this code and I can't get it to work any help out there? I am a new user and would really appreciate it if somebody can correct whats going wrong with it.

// DEBUG10-4
// PartTimeEmployee derives from Employee
// Employees make $800 per week
// PartTimeEmployees make $7.85 per hour
#include<iostream>
#include<string>
using namespace std;
class Employee
{
   protected:
      string firstName;
      string lastName;
      double salary;
   public:
       Employee(string, string);
       void showEmployee();
       void setData();
       string getfirstName();
       string getlastName();
 };
Employee::Employee(string first, string last)
{
    firstName = firstName;
    lastName = lastName;
    salary = 800;
 };
void Employee::setData()
{
     cout<<"Enter Employee's first name ";
     cin>>firstName;
     cout<<"Enter last name ";
     cin>>lastName;
     salary = 800;
     }
void Employee::showEmployee()
{
   cout<<firstName<<" "<<lastName<<
	   " Salary $"<<salary<<endl;
}
string Employee::getlastName()
{
  return lastName;
}
string Employee::getfirstName()
{
  return firstName;
 }
class  PartTimeEmployee : public  Employee
{
  public:
     PartTimeEmployee(string, string);
};
PartTimeEmployee::PartTimeEmployee(string first, string last) :
    Employee(first,last)
 {
   salary = 7.85;
 }

int main()
 {
    const int NUMEMPS = 3;
    string first;
    string last;
    Employee workers(first,  last);
    int x;
    for(x = 0; x < NUMEMPS; ++x)
    {
        Employee temp;
        char pt;
        temp.setData();
        cout<<"Is employee part time - y or n? ";
        cin>>pt;
        if(pt = 'y')
        {
          PartTimeEmployee tempPartTime(temp.getfirstName(), temp.getlastName());
          temp = tempPartTime;
        }
       workers[NUMEPS] = temp;
     }
    cout<<endl<<"Employees: "<<endl;  
    for(x = 0; x <= NUMEMPS; ++x)
      workers[NUMEMPS].showEmployee();
      
      system("pause");
}

HELP PLEASEEE!!!!

Recommended Answers

All 3 Replies

"It doesn't work" isn't helpful. Be specific about how it doesn't work and we'll be in a better position to tell you why it doesn't work.

good point well in the int main section of the coding i got everything else to work so far but it doesn't read the employee and I know I need to read the number of employees. I also know that I declared it as string from the class employee from the top. SO... in tail I need to debug the bottom part of the code to make it read the number of employees i just need to run three

I changed several things in your class, so you'll want to find and study what I did. Your approach in main has some subtle issues, so rather than walk you through it bit by bit, I simply wrote my own version for you to use as a template:

// DEBUG10-4
// PartTimeEmployee derives from Employee
// Employees make $800 per week
// PartTimeEmployees make $7.85 per hour
#include<iostream>
#include<string>
using namespace std;
class Employee
{
protected:
    string firstName;
    string lastName;
    double salary;
public:
    Employee();
    Employee(string, string);
    void showEmployee();
    void setData();
    string getfirstName();
    string getlastName();
};
Employee::Employee()
{
    salary = 0;
}
Employee::Employee(string first, string last)
{
    firstName = first;
    lastName = last;
    salary = 800;
};
void Employee::setData()
{
    cout<<"Enter Employee's first name ";
    cin>>firstName;
    cout<<"Enter last name ";
    cin>>lastName;
    salary = 800;
}
void Employee::showEmployee()
{
    cout<<firstName<<" "<<lastName<<
        " Salary $"<<salary<<endl;
}
string Employee::getlastName()
{
    return lastName;
}
string Employee::getfirstName()
{
    return firstName;
}
class  PartTimeEmployee : public  Employee
{
public:
    PartTimeEmployee(string, string);
};
PartTimeEmployee::PartTimeEmployee(string first, string last) :
    Employee(first,last)
{
    salary = 7.85;
}

int main()
{
    const int NUMEMPS = 3;

    Employee workers[NUMEMPS];

    for ( int i = 0; i < NUMEMPS; i++ ) {
        workers[i].setData();

        // Clean up leftovers from setData()
        cin.ignore ( 80, '\n' );

        cout<<"Is the employee part-time? (y/n): ";

        if ( cin.get() == 'y' ) {
            workers[i] = PartTimeEmployee (
                workers[i].getfirstName(), workers[i].getlastName() );
        }

        // Clean up leftovers from cin.get()
        cin.ignore ( 80, '\n' );
    }

    cout<<"Employees:\n";

    for ( int i = 0; i < NUMEMPS; i++ )
        workers[i].showEmployee();

    cin.get();
}
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.