employee.h(53) : error C2270: 'getFirstName' : modifiers not allowed on nonmember functions
(how do I use this function then with inheritence?)
employee.h(54) : error C2065: 'firstName' : undeclared identifier
(isn't this declared already or did I do it wrong?)
hourly.h(64) : error C2352: 'employee::setName' : illegal call of non-static member function
(how do I call this then?)
Here is the code:
//Class hourly #ifndef H_Hourly #define H_Hourly #include "employee.h" //inheriting from the class employee #include <iostream> using namespace std; class hourly:public employee { public: void print() const; //Function to output the first name, last name and hours worked. //Postcondition: Outputs // firstName lastName hours worked are 99.99 double calculateHoursWorked() const; //Function to calculate and return the hours worked. //Postcondition: Hours worked is calculated and returned void setNameHours(string first, string last, double dayOne, double dayTwo, double dayThree, double dayFour, double dayFive); //Function to set the first name, last name and hours worked //each day according to the parameters. //Postcondition: firstName=first; lastName=last; dayOneHours=dayOne; //dayTwoHours=dayTwo; dayThreeHours=dayThree; dayFourHours=dayFour; //dayFiveHours=dayFive. hourly (string first="", string last="", double dayOne=0, double dayTwo=0, double dayThree=0, double dayFour=0, double dayFive=0); //Constructor with parameters //sets the first name, last name, dayOneHours, dayTwoHours, dayThreeHours, //dayFourHours, and dayFiveHours according to the parameters. If no value is //specified the default values are assumed. //Postcondition: firstName=first; lastName=last; dayOneHours=dayOne; //dayTwoHours=dayTwo; dayThreeHours=dayThree; dayFourHours=dayFour; //dayFiveHours=dayFive. double dayOneHours; double dayTwoHours; double dayThreeHours; double dayFourHours; double dayFiveHours; private: }; void hourly::print() const { employee::print(); //print name of employee cout<<"'s hours worked are:"<<calculateHoursWorked()<<endl; } double hourly::calculateHoursWorked() const { return (dayOneHours+dayTwoHours+dayThreeHours+dayFourHours+dayFiveHours); } void employee::setNameHours(string first, string last, double dayOne, double dayTwo, double dayThree, double dayFour, double dayFive) { employee::setName(first, last); dayOneHours=dayOne; dayTwoHours=dayTwo; dayThreeHours=dayThree; dayFourHours=dayFour; dayFiveHours=dayFive; } hourly::hourly (string first, string last, double dayOne, double dayTwo, double dayThree double dayFour, double dayFive) :employee(first, last) { dayOneHours=dayOne; dayTwoHours=dayTwo; dayThreeHours=dayThree; dayFourHours=dayFour; dayFiveHours=dayFive; } #endif
//Class employee #ifndef H_Employee #define H_Employee #include <iostream> #include <string> using namespace std; class employee { public: void print() const; //Function to output the first name and last name in the form of //firstName lastName. void setName(string first, string last); //Function to set firstName and lastName according to the parameters. //Postcondition: firstName=first; lastName=last string getFirstName() const; //Function to return the first name. //Postcondition: The value of firstName is returned. string getLastName() const; //Function to return the last name. //Postcondition: The value of lastName is returned. employee(string first="", string last=""); //Constructor //Sets firstName and lastName according to the parameters. //The default values of the parameters are null strings. //Postcondition firstName=first; lastName=last; string firstName; //variable to store the first name string lastName; //variable to store the last name private: }; void employee::print() const { cout<<firstName<<" "<<lastName; } void employee::setName(string first, string last) { firstName=first; lastName=last; } string getFirstName() const { return firstName; } string getLastName() const { return lastName; } employee(string first="", string last="") { firstName=first; lastName=last; } #endif
main.cpp
#include <iostream> #include "hourly.h" using namespace std; int main() { cout << "This is a program to test if the inheritence for hourly" << " and employee classes work. Now printing sample data: " <<endl; hourly testEmployee; testEmployee.setNameHours(Jane, Smith, 8, 8, 8, 7.5, 6.25); cout << "The name and hours of the employee are: "; testEmployee.print; return 0; }
If anyone could help with this, I would greatly appreciate it. There are other errors, too, but I need to get by these ones first. Thanks in advance.
-Andrea