C++ Classes/Inheritance

I have to create a class (Employee) and a second class hourly that will inherit from the employee class.  Then write code to test the hourly class.  I have reached about as far as I can go.  I am getting an error and not sure why.  Please help.


#ifndef H_employee
#define H_employee

#include <fstream>
#include <string>

using namespace std;

class employee
{
private:
      string fName;
      string lName;
      string ID;

public:
      employee();
      employee(string FN, string LN, string ID);
      string getName() const;
      string getID() const;
      void setName(string FN, string LN);
      void setID(string Ident);
      ~employee();
};

#endif

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include "employee.h"

using namespace std;

employee::employee(string FN, string LN, string ID)
{
      fName = FN;
      lName = LN;
      ID = ID;
}

void employee::setName(string FN, string LN)
{
      fName = FN;
      lName = LN;
}

void employee::setID(string Ident)
{
      ID = Ident;
}

#ifndef H_hourlyEmployee
#define H_hourlyEmployee

#include <fstream>
#include <string>

using namespace std;

class HourlyEmployee : public employee
{
private:
      double Rate;
      double Hours;

public:
      HourlyEmployee();
      HourlyEmployee(string FN, string LN, string ID,
      double R, double H);
      double getRate() const;
      double getHours() const;
      ~HourlyEmployee();
};

#endif

#include <iostream>
#include <string>
#include "hourlyEmployee.h"

using namespace std;

HourlyEmployee::HourlyEmployee()
{
      setName("LLLLLLLLLLL", "FFFFFFFFFF");
      setID("000-00-0000");
      Rate = 0.0;
      Hours = 0.0;
}

double getRate() const
{
      return rate;
}

double getHours() const
{
      return hours;
}


#include "employee.h"
#include "HourlyEmployee.h"

void PrintEmployee(Employee toPrint, ostream& Out);
void PrintHourlyEmployee(HourlyEmployee toPrint, ostream& Out);

void main()
{
      employee Me("Tony", "Stewar", "202-20-2020");
      PrintEmployee(Me, cout);
      HourlyEmployee Steve("Steve", "Simpson", "000-00-0001",
      13.42, 7.5);
      PrintHourlyEmployee(Steve, cout);
      PrintEmployee(Steve, cout);
}


void PrintEmployee(employee toPrint, ostream& Out)
{
      Out << toPrint.getID();
      Out << '\t';
      Out << toPrint.getName();
      Out << '\n';
}

void PrintHourlyEmployee(HourlyEmployee toPrint, ostream& Out)
{
      Out.setf(ios::floatfield, ios::fixed);
      Out.setf(ios::showpoint);
      Out << toPrint.getID();
      Out << '\t';
      string Name = toPrint.getName();
      Out << Name;
      Out << setw(30 - Name.length())
      << setprecision(2) << toPrint.getRate();
      Out << setw(10) << setprecision(2) << toPrint.getHours();
      Out << '\n';
}


HourlyEmployee::HourlyEmployee()
: Employee("Anonymous", "Hourly", "777-77-7777") {
FName = "Anonymous";
LName = "Person";
ID = "000-00-0000";
Rate = 0.0;
Hours = 0.0;
}


HourlyEmployee::HourlyEmployee(string FN, string LN, string ID,
double R, double H)
: Employee(FN, LN, ID), Rate(R), Hours(H) {
}

joew08Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AxterCommented:
>>I am getting an error and not sure why.

What exactly is your error?
0
bachra04Commented:
are yu using Visual C when you get the error ?
0
seet82Commented:
what you are doing is like going to the clinic and tell the doc that you are not feeling well but not telling him how/where you are not feeling well

no one can help u if you don't tell other ppl what your error is

anyway, browse thru a bit of your code. the below code will not work
employee::employee(string FN, string LN, string ID)
{
     fName = FN;
     lName = LN;
     ID = ID; //should be replaced by this->ID=ID;
}
ID=ID is setting ID to ID, ie, setting the passed in ID to ID(which does nothing)
the correct way to do it is this->ID=ID;
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

pcgabeCommented:
You're getting AN error?  You should be getting DOZENS of errors.  Well, that's why you come to Experts-Echange, right?  ^_^

OK, this code needs a LOT of work.  A LOT A LOT.  It has so many inconsistencies....are you sure this was all written by a single person?

Here's a list of things to do:

#1) Remember: CASE MATTERS in C/C++.  Make sure that, once you define a class or variable (such as 'employee') you don't later refer to it by a different capitalization (such as "Employee").
#2) Spelling matters.  'fName' is not 'FName' is not 'FN'.
#3) If you declare it, you MUST define it.  I see a 'public: employee();' constructor declaration, but it is never implemented anywhere.
#4) When you implement the functions in a class, you have to tell the compiler that that is what you are doing.  'double getRate() const', for example, seems a bit vague to the poor confused compiler.  'double HourlyEmployee::getRate() const' would clear that up.

Finally, if you are going to post multiple source files, give us their names and where they begin and end.

Now, this doesn't list every bug in the above code (look at the 'HourlyEmployee::HourlyEmployee()' constructor), but it's a start.  ^_^  Fix these, and come back and post your updated code, and we'll help you some more.
0
DrAskeCommented:
class employee
{
private:
     string fName;
     string lName;
     string ID;

public:
     employee(); <-------- Must Be Defined
     employee(string FN, string LN, string ID);
     string getName() const; <---------  Must Be Defined
     string getID() const;      <---------  Must Be Defined
     void setName(string FN, string LN);
     void setID(string Ident);
     ~employee();     <---------- Must Be Defined
};

employee::employee(string FN, string LN, string Id)
{
     fName = FN;
     lName = LN;
     ID = Id; <-------- MODIFEID or use this->ID = ID; as seet82 said
}


class HourlyEmployee : public employee
{
private:
     double Rate;
     double Hours;

public:
     HourlyEmployee();
     HourlyEmployee(string FN, string LN, string ID,
     double R, double H);
     double getRate() const;
     double getHours() const;
     ~HourlyEmployee();<------ Remember the member functions must be defined
};
// When defining a class's member function outside the class, omiiting the class NAME and scope resolution operator on
//the function name is an ERROR!!
double HourlyEmployee::getRate() const // MODIFIED
{
      //return rate; MODIFIED
      return Rate;
}
double HourlyEmployee::getHours() const // MODIFIED
{
     //return hours; MODIFIED
      return Hours;
}

void PrintEmployee(Employee toPrint, ostream& Out); <-- first parameter Employee should be employee (case sensitive)

// Omit this function .. you have already defined HourlyEmployee constuctor
HourlyEmployee::HourlyEmployee()
: Employee("Anonymous", "Hourly", "777-77-7777") {
FName = "Anonymous";
LName = "Person";
ID = "000-00-0000";
Rate = 0.0;
Hours = 0.0;
}
// instead of Employee(FN, LN, ID) ---> employee(FN, LN, ID)
HourlyEmployee::HourlyEmployee(string FN, string LN, string ID,
double R, double H)
: Employee(FN, LN, ID), Rate(R), Hours(H) {
}

regards, ahmad;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AxterCommented:
Please copy and paste the error, instead of trying to translate it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.