I have a simple program with three files(excluding the precompiled header). I have included the precompiled header in the .cpp files Yet it is giving these two errors that I don't seem to understand :
1>d:\practice\operatoroverloading\oopinheritance\oopinheritance\commisionemp.h(4): warning C4627: '#include ': skipped when looking for precompiled header use 1> Add directive to 'StdAfx.h' or rebuild precompiled header 1>d:\practice\operatoroverloading\oopinheritance\oopinheritance\commisionemp.h(35): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source? ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Here are the codes:
OOPInheritance.cpp
// OOPInheritance.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include "CommisionEmp.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
CommissionEmp employee("Dede","Kikadi","777-77-7777",5000,0.08);
cout<<fixed<<setprecision(2);
cout<<"Employee information obtained by get functions:\n"
<<"\n First name is" <<employee.getFirstName()
<<"\n Last name is "<<employee.getLastName()
<<"\nSocial security number is"
<<employee.getSocialSecurityNumber()
<<"\nGross sales is " <<employee.getGrossSales()
<<"\nCommission rate is " <<employee.getCommissionRate()<<endl;
employee.setGrossSales(8000);
employee.setCommissionRate(.1);
cout<<"\n Updated employee infromation output by print function : \n"<<endl;
employee.print();
cout<<"\n Employee's earning : ZAR"<<employee.earnings()<<endl;
return 0;
}
CommisionEmp.h:
#ifndef COMMISSION_H
#define COMMISSION_H
#include <string>
using namespace std;
class CommissionEmp{
public:
CommissionEmp(const string &, const string &, const string &, double=0.0, double =0.0);
void setFirstName(const string &);
string getFirstName() const;
void setLastName(const string &);
string getLastName() const;
void setSocialSecurityNumber(const string &);
string getSocialSecurityNumber() const;
void setGrossSales(double);
double getGrossSales() const;
void setCommissionRate(double);
double getCommissionRate() const;
double earnings()const;
void print() const;
private:
string firstName;
string lastName;
string socialSecurityNumber;
double grossSales;
double commissionRate;
};
#endif
CommissionEmp.cpp:
#include "stdafx.h"
#include <iostream>
#include "CommisionEmp.h"
using namespace std;
CommissionEmp::CommissionEmp(const string &first, const string &last, const string &ssn, double sales, double rate) :
firstName(first), lastName (last), socialSecurityNumber(ssn)
{
setGrossSales(sales);
setCommissionRate(rate);
}
void CommissionEmp::setFirstName(const string &first)
{
firstName=first;
}
string CommissionEmp::getFirstName()const {return firstName;}
void CommissionEmp::setLastName (const string &last)
{
lastName=last;
}
string CommissionEmp::getLastName()const {return lastName;}
void CommissionEmp::setSocialSecurityNumber (const string &ssn)
{
socialSecurityNumber=ssn;
}
string CommissionEmp::getSocialSecurityNumber()const {return socialSecurityNumber;}
void CommissionEmp::setGrossSales (double sales)
{
if(sales >= 0.0)
grossSales=sales;
else throw invalid_argument("Gross sales must be >=0.0");
}
double CommissionEmp::getGrossSales()const {return grossSales;}
void CommissionEmp::setCommissionRate (double rate)
{
if(rate>0.0 && rate <1.0)
commissionRate=rate;
else throw invalid_argument("Commission rate must be > 0.0 and < 1.0");
}
double CommissionEmp::getCommissionRate()const {return commissionRate;}
double CommissionEmp::earnings() const{
return commissionRate*grossSales;
}
void CommissionEmp::print() const{
cout<<"commission empoyee: " <<firstName <<' ' <<lastName
<<"\n social security number : "<<socialSecurityNumber
<<"\ngross sales: "<< grossSales
<<"\ncommission rate: "<<commissionRate;
}