Jun 8, 2011 at 12:51am UTC
# include <iostream>
# include <string>
# include <iomanip>
# include "datesg.cpp"
using namespace std;
class Employee
{
public:
Employee( const string &, const string &, const string &,
const Date &, const Date &, double = 0.0, double = 0.0);
~Employee();
void setFirstName( const string & );
string getFirstName() const;
void setLastName( const string & );
string getLastName() const;
void setSocialSecurityNumber( const string & );
string getSocialSecurityNumber() const;
void setDepartmentCode(int);
int getDepartmentCode() const;
void setGrossSales(double);
double getGrossSales() const;
void setCommissionRate(double);
double getCommissionRate() const;
double getCommissionRateBonus()const;
double earnings() const;
void print() const;
private:
string firstName;
string lastName;
string socialSecurityNumber;
int departmentCode;
double grossSales;
double commissionRate;
const Date birthDate;
const Date currentDate;
};
Employee::Employee(
const string &first, const string &last, const string &ssn,const Date &dateOfBirth,
const Date ¤tDate, double sales, double rate)
: firstName(first), lastName(last), socialSecurityNumber(ssn),birthDate( dateOfBirth )
{
setGrossSales(sales);
setCommissionRate(rate);
cout << "Commission Employee constructor: " << endl;
print();
cout << "\n\n";
}
Employee::~Employee()
{
cout << "Commission Employee Destructor: " << endl;
print();
cout << "\n\n";
}
void Employee::setFirstName( const string &first)
{
firstName = first;
}
string Employee:: getFirstName() const
{
return firstName;
}
void Employee::setLastName( const string &last)
{
lastName = last;
}
string Employee::getLastName() const
{
return lastName;
}
void Employee::setSocialSecurityNumber( const string &ssn)
{
socialSecurityNumber = ssn;
}
string Employee::getSocialSecurityNumber() const
{
return socialSecurityNumber;
}
void Employee::setGrossSales( double sales)
{
grossSales = (sales < 0.0) ? 0.0 : sales;
}
double Employee::getGrossSales() const
{
return grossSales;
}
void Employee::setCommissionRate( double rate)
{
commissionRate = (rate > 0.0 && rate < 1.0) ? rate : 0.0;
}
double Employee::getCommissionRate() const
{
return commissionRate;
}
double Employee::getCommissionRateBonus()const
{
return commissionRate * grossSales + 100;
}
void Employee::setDepartmentCode(int code)
{
departmentCode = (code>= 1 && code <= 999) ? code : 1;
}
int Employee::getDepartmentCode() const
{
return departmentCode;
}
double Employee::earnings() const
{
if ( birthDate.getMonth() == currentDate.getMonth() )
{
return getCommissionRateBonus();
}
else
return getCommissionRate() * getGrossSales();
}
void Employee::print() const
{
cout << "commission employee: "
<< getFirstName() << ' ' << getLastName()
<< "\nsocial security number: " << getSocialSecurityNumber()
<< "\ngross sales: " << getGrossSales()
<< "\ncommission rate: " << getCommissionRate()
<< "\nearnings: " << earnings()
<< "\ndepartmentcode: " << getDepartmentCode()
<< "\nbirth date: " ; birthDate.print();
cout << endl;
}
int main()
{
Date birth(3,24,1987);
Employee employee("Bob", "Lewis", 333-33-3333, 5000, .04, 300, 12, birth);
cout << "commission employee: "
<< employee.getFirstName() << ' ' << employee.getLastName()
<< "\nsocial security number: " << employee.getSocialSecurityNumber()
<< "\ngross sales: " << employee.getGrossSales()
<< "\ncommission rate: " << employee.getCommissionRate()
<< "\nearnings: " << employee.earnings()
<< "\ndepartmentcode: " << employee.getDepartmentCode()
<< "\nbirth date: " << Date.birthDate();
cout << endl;
employee.print();
return 0;
}
ok, the program works but i need help with the main, any help would surely be appreciated! :)
Jun 8, 2011 at 1:09am UTC
ok i believe i dont need all of that in main but just a simple
Employee employee;
employee.print();
system("pause");
but why still doesnt it work?
Jun 8, 2011 at 2:27am UTC
What exactly are you trying to do?
Jun 8, 2011 at 2:37am UTC
1.) Put your code in the [ code ] brackets.
2.) Look up what polymorphism is.
Jun 8, 2011 at 2:48pm UTC
i just want to be able to insert some information about an employee and display the birthdate and other information. when i try it the first way as i show, it gives me two errors, one being that the parameter doesnt hold 8 parameters and the second, birthDate isnt part of employee. is it because birthDate is declared as private? ive been having trouble with this and ive looked it up many times already.
Jun 8, 2011 at 2:51pm UTC
heres my date class:
class Date
{
public:
Date( int = 1, int = 1, int = 1900 );
void setDate(int, int, int);
static bool leapYear(int);
bool endOfMonth(int) const;
void print() const;
~Date();
int getMonth() const;
private:
int month;
int day;
int year;
static const int days[];
};
const int Date::days[]=
{0,31,28,31,30,31,30,31,31,30,31,30,31};
Date::Date( int m, int d, int y)
{
setDate(m, d, y);
}
void Date::setDate(int m, int d, int y)
{
month = (m >= 1 && m <=12) ? m : 1;
year = (y >=1900 && y <= 2100) ? y: 1900;
if (month == 2 && leapYear(year))
day = (d >=1 && d <= 29) ? d : 1;
else
day = (d >= 1 && d <= days[month]) ? d : 1;
}
bool Date::leapYear( int testYear )
{
if (testYear % 400 ==0 ||
(testYear % 100 != 0 && testYear % 4 == 0))
return true;
else
return false;
}
bool Date::endOfMonth(int testDay) const
{
if (month == 2 && leapYear(year))
return testDay == 29;
else
return testDay == days[month];
}
void Date::print() const
{
cout << month << '/' << day << '/' << year;
}
Date::~Date()
{
cout << "Date object destructor for date ";
print();
cout << endl;
}
int Date::getMonth() const
{
return month;
}
Jun 8, 2011 at 3:05pm UTC
Put your code in tages [code]...[/1code]
remove the 1.
You need a default constructor for employee in your class declaration.
Employee();
Jun 8, 2011 at 3:24pm UTC
ok i will try that :) thank you
Jun 8, 2011 at 5:04pm UTC
Last edited on Jun 8, 2011 at 5:06pm UTC