what is the error?

#include<iostream>
#include<string>
using namespace std;
class personType{
public:
void print() const;
void setName(string first, string last);
string getFirstName() const;
string getLastName() const;
personType(string first = "" , string last = "");
private:
string firstName;
string lastName;
};
void personType::print() const {
cout<<firstName<<" "<<lastName;
}
void personType::setName(string first,string last)
{
firstName=first;
lastName=last;
}
string personType::getLastName() const
{
return lastName;
}
personType::personType(string first, string last)
{
firstName=first;
lastName=last;
}
class partTimeEmployee: public personType
{
public:
void print() const;
double calculatePay()const;
void setNameRateHours(string first = "" , string last = "" , double rate = 0 , double hours = 0);
private:
double payRate;
double hoursWorked;
};
void partTimeEmployee::print() const
{
personType::print(); //print te name of the employee
cout<<"'s wages are: $"<<calculatePay()<<endl;
}
double partTimeEmployee::calculatePay() const
{
return (payRate*hoursWorked);
}
void partTimeEmployee::setNameRateHours(string first,string last,double rate, double hours)
{
personType::setName(first,last);
payRate=rate;
hoursWorked=hours;
}

partTimeEmployee::partTimeEmployee(string first, string last, double rate, double hours)

:personType(first, last);

{
if (rate>=0)
payRate=rate;
else
payRate=0;
if (hours>=0)
hoursWorked=hours;
else
hoursWorked=0;
}
int main()
{
partTimeEmployee newEmp ("john", "smith", 15.34, 67);
newEmp.print();
return 0;
}
Last edited on
Please, use the code tags and indentation http://www.cplusplus.com/articles/jEywvCM9/

Why don't you tell us what errors do you get? (Fails to compile, link, run, or unexpected result?)
For starters you havent declared your partTimeEmployee contructor in the class.

also:
1
2
3
partTimeEmployee::partTimeEmployee(string first, string last, double rate, double hours)

:personType(first, last);  
the error in this part .. it gives me nothing when i run the program

partTimeEmployee::partTimeEmployee(string first, string last, double rate, double hours)

:personType(first, last);

{
if (rate>=0)
payRate=rate;
else
payRate=0;
if (hours>=0)
hoursWorked=hours;
else
hoursWorked=0;
}
int main()
{
partTimeEmployee newEmp ("john", "smith", 15.34, 67);
newEmp.print();
return 0;
}
I don't think that the semicolon is allowed at the end of the initializer list. However, that should give a compiler error.

Furthermore, you can do construction by initialization:
1
2
3
4
5
partTimeEmployee::partTimeEmployee( string first, string last, double rate, double hours )
: personType( first, last ),
  payRate( 0 < rate ? rate : 0 ),
  hoursWorked( 0 < hours ? hours : 0 )
{}


Same for the base:
1
2
3
4
personType::personType( string first, string last )
: firstName( std::move(first) ),
  lastName( std::move(last) )
{}
Topic archived. No new replies allowed.