Employee List
Mar 26, 2013 at 4:57am UTC
So I'm trying to make an employee list that holds the information so I can then delete or add from that array. I'm getting some errors regarding overloading function and I have no idea whats wrong.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#include "employeelist.h"
const Employee & employeelist::operator [](int index) const
{
return ( (this ->Employees)[index] );
}
Employee & employeelist::operator [](int index)
{
return ( (this ->Employees)[index] );
}
employeelist & employeelist::operator = (const employeelist & oneList)
{
this ->quantity = oneList.quantity;
for (int i=0; i<oneList.quantity; i++)
(*this )[i] = oneList[i];
return (*this );
}
int employeelist::quantityOfEmployees() const
{
return (this ->quantity);
}
bool employeelist::isEmpty() const
{
return (this ->quantity == 0);
}
bool employeelist::includes(Employee & oneEmployee) const
{
bool included = false ;
for (int i=0; i<this ->quantity && !included; i++)
{
if ( (*this )[i] == Employee)
{
included = true ;
oneEmployee = (*this )[i];
}
}
return (included);
}
bool employeelist::includes(Employee & oneEmployee) const
{
bool included = false ;
for (int i=0; i<this ->quantity && !included; i++)
{
if ( (*this )[i] == Employee)
{
included = true ;
oneEmployee = (*this )[i];
}
}
return (included);
}
employeelist & employeelist::operator + (const Employee & oneEmployee)
{
if ( !(this ->isFull() ) && !(this ->includes(oneEmployee) ) )
{
(*this )[this ->quantity] = oneEmployee;
++(this ->quantity);
}
return (*this );
}
employeelist::employeelist()
{
this ->quantity = 0;
}
employeelist::employeelist(const employeelist & oneList)
{
(*this ) = oneList;
}
employeelist::~employeelist()
{
}
bool employeelist::isFull() const
{
return (this ->quantity == MAX_LIB);
}
ostream & operator << (ostream & out, const employeelist & oneList)
{
if ( oneList.isEmpty() )
out << "There are no Employees." << endl;
else
{
out << "Book List:" << endl;
for (int i=0; i<oneList.quantity; i++)
out << (i+1) << ". " << oneList[i] << endl;
}
return (out);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#pragma once
#include "Employee.h"
#include <iostream>
using namespace std;
const int MAX_LIB = 80;
class employeelist
{
private :
Employee Employees[MAX_LIB];
int quantity;
public :
employeelist(void );
employeelist(const employeelist & oneList);
~employeelist();
employeelist & operator = (const employeelist & oneList);
int quantityOfEmployees() const ;
int indexOf(const Employee & oneEmployee) const ;
const Employee & operator [](int index) const ;
Employee & operator [](int index);
bool isFull() const ;
bool isEmpty() const ;
bool includes(const Employee & oneEmployee) const ;
bool includes(const int , Employee & oneEmployee) const ;
bool includes(const string, Employee & oneEmployee) const ;
employeelist & operator + (const Employee & oneEmployee);
employeelist & operator - (const Employee & oneEmployee);
friend ostream & operator << (ostream & out, const employeelist & oneList);
};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#pragma once
#include<iostream>
#include"Date.h"
#include<string>
using namespace ::std;
class Employee
{
private :
string firstName;
Date birthDate;
string lastName;
double salary;
public :
void showInfo() const ;
void askInfo();
const string & getfistName()const ;
const string & getlastName()const ;
const Date & getbirthDate()const ;
const double & getsalary() const ;
Employee ( const string & firstName,
const string & lastName,
const Date & birthDate);
Employee (const Employee & oneEmployee);
Employee & operator = (const Employee & oneEmployee);
bool operator == (const Employee & oneEmployee)const ;
void askfirstName();
void asklastName();
void askbirthDate();
void asksalary();
~Employee();
friend ostream & operator << (ostream & out, const Employee & anEmployee);
friend istream & operator >> (istream & in, Employee & anEmployee);
};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
#include"Employee.h"
Employee::Employee(const string & firstName, const string & lastName, const Date & birthDate)
: firstName (firstName),
lastName (lastName),
birthDate (birthDate)
{
}
Employee::Employee ( const Employee & oneEmployee)
: firstName(oneEmployee.firstName),
lastName(oneEmployee.lastName),
birthDate(oneEmployee.birthDate)
{
}
Employee::~Employee()
{
}
Employee & Employee::operator =(const Employee & oneEmployee)
{
this ->firstName=oneEmployee.firstName;
this ->lastName=oneEmployee.lastName;
this ->birthDate=oneEmployee.birthDate;
return (*this );
}
void Employee::showInfo() const
{
cout<<"\tFirst Name:" << (this ->firstName)<<endl;
cout<<"\tLast Name:" << this ->lastName<<endl;
cout<<"\tBirth Date:" << this ->birthDate<<endl;
}
void Employee::askInfo()
{
cout <<"\tFirst Name:" ;
cin >>this ->firstName;
cout <<"\tLast Name:" ;
cin >> this ->lastName;
cout <<"\tBirthDate:" ;
cin >>this ->birthDate;
cout<<"\tSalary:" ;
cin>>this ->salary;
}
void Employee::askfirstName()
{
cout << "What is the First Name:" ;
cin >> this ->firstName;
}
void Employee::asklastName()
{
cout <<"What is the Last Name:" ;
cin >> this ->lastName;
}
void Employee::askbirthDate()
{
cout<<"What is the Birth Date:" ;
cin>>this ->birthDate;
}
ostream& operator << (ostream& out, const Employee & anEmployee)
{
out<<"\tFirst Name:" << anEmployee.getfistName()<<endl;
out<<"\tLast Name:" << anEmployee.getlastName()<<endl;
out<<"\tBirth Date:" << anEmployee.getbirthDate()<<endl;
out<<"\tSalary:" << anEmployee.getsalary()<<endl;
return (out);
}
istream& operator >> (istream& in, Employee & anEmployee)
{
cout <<"\tFirst Name:" ;
in >>anEmployee.firstName;
cout <<"\tLast Name:" ;
in >> anEmployee.lastName;
cout <<"\tBirthDate:" ;
in >>anEmployee.birthDate;
cout<<"\tSalary:" ;
in>>anEmployee.salary;
return (in);
}
const string & Employee::getlastName()const
{
return (this ->lastName);
}
const string & Employee::getfistName() const
{
return (this ->firstName);
}
const Date & Employee::getbirthDate() const
{
return (this ->birthDate);
}
void Employee::asksalary()
{
cout<<"Enter salary: " ;
cin>>this ->salary;
}
const double & Employee::getsalary() const
{
return (this ->salary);
}
Mar 26, 2013 at 4:57am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
#include "Date.h"
// Private Member Functions.
void Date::askDay()
{
bool validFeb, valid30, valid31;
cout << "Enter a day: " ;
cin >> this ->day;
validFeb = ((this ->month == 2) && ((this ->isLeapYear() && this ->day <= 29) || (!(this ->isLeapYear()) && this ->day <= 28)) && (this ->day > 0));
valid30 = ((this ->month != 2) && ((this ->month % 2 == 0 && this ->month <= 6) || (this ->month % 2 != 0 && this ->month >= 9)) && (this ->day > 0 && this ->day <= 30));
valid31 = ((this ->month != 2) && ((this ->month % 2 == 0 && this ->month >= 8) || (this ->month % 2 != 0 && this ->month <= 7 )) && (this ->day > 0 && this ->day <= 31));
while ( !validFeb && !valid30 && !valid31)
{
cout << "ERROR: Invalid value." << endl << endl;
cout << "Enter a day: " ;
cin >> this ->day;
validFeb = ((this ->month == 2) && ((this ->isLeapYear() && this ->day <= 29) || (!(this ->isLeapYear()) && this ->day <= 28)) && (this ->day > 0));
valid30 = ((this ->month != 2) && ((this ->month % 2 == 0 && this ->month <= 6) || (this ->month % 2 != 0 && this ->month >= 9)) && (this ->day > 0 && this ->day <= 30));
valid31 = ((this ->month != 2) && ((this ->month % 2 == 0 && this ->month >= 8) || (this ->month % 2 != 0 && this ->month <= 7)) && (this ->day > 0 && this ->day <= 31));
}
}
void Date::askMonth()
{
cout << "Enter the month: " ;
cin >>this ->month;
while (this ->month < 1 || this ->month > 12)
{
cout << "ERROR: Invalid value." << endl << endl;
cout << "Enter the month: " ;
cin >> this ->month;
}
}
void Date::askYear()
{
char d;
cout << "Enter the year: " ;
cin >> this ->year;
while (this ->year < 0)
{
cout << "ERROR: Invalid value." << endl << endl;
cout << "Enter the year: " ;
cin >> this ->year;
}
cout << endl << "Is AC(press 1; otherwise BC): " ;
cin >> d;
if (d != '1' )
this ->setBC();
}
// Accesors and Mutators.
void Date::setDay(int day)
{
this ->day = day;
}
void Date::setMonth(int month)
{
this ->month = month;
}
void Date::setYear(int year)
{
this ->year = year;
}
int Date::getDay()const
{
return (this ->day);
}
int Date::getMonth()const
{
return (this ->month);
}
int Date::getYear()const
{
return (this ->year);
}
void Date::showDay()const
{
cout << this ->day;
}
void Date::showMonth()const
{
cout << this ->month;
}
void Date::showYear()const
{
cout << ((this ->isAC()) ? this ->year : -(this ->year)) << ((this ->isAC()) ? "AC" : "BC" );
}
void Date::showDate()const
{
cout << this ->month << '/' << this ->day << '/' << ((this ->isAC()) ? this ->year : -(this ->year)) << ((this ->isAC()) ? " AC" : " BC" );
}
void Date::setBC()
{
if (this ->year > 0)
this ->year *= -1;
}
void Date::setAC()
{
if (this ->year < 0)
this ->year *= -1;
}
bool Date::isBC()const
{
return (this ->year < 0);
}
bool Date::isAC()const
{
return (this ->year >= 0);
}
bool Date::isLeapYear()const
{
return ((this ->year % 400 == 0) || (this ->year % 100 != 0 && this ->year % 4 == 0));
}
void Date::askDate()
{
this ->askYear();
this ->askMonth();
this ->askDay();
}
// Operator Overloadings.
ostream &operator <<(ostream &Out, const Date &aDate)
{
aDate.showDate();
return (Out);
}
istream &operator >>(istream &In, Date &aDate)
{
aDate.askDate();
return (In);
}
Date &Date::operator =(const Date &aDate)
{
this ->day = aDate.day;
this ->month = aDate.month;
this ->year = aDate.year;
return (*this );
}
bool Date::operator ==(const Date & aDate)const
{
return (this ->day == aDate.day &&
this ->month == aDate.month &&
this ->year == aDate.year);
}
bool Date::operator !=(const Date &aDate)const
{
return (!((*this ) == aDate));
}
bool Date::operator >(const Date &aDate)const
{
return ((this ->year > aDate.year) ||
(this ->year == aDate.year && this ->month > aDate.month) || (this ->year == aDate.year && this ->month == aDate.month && this ->day > aDate.day));
}
bool Date::operator <(const Date &aDate)const
{
return (!((*this ) > aDate || (*this ) == aDate));
}
// Constructors and Destructors.
Date::Date(int month, int day, int year)
{
this ->day = day;
this ->month = month;
this ->year = year;
}
Date::Date(const Date &aDate)
{
this ->day = aDate.day;
this ->month = aDate.month;
this ->year = aDate.year;
}
Date::~Date()
{
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#ifndef DATE_H
#define DATE_H
#include <iostream>
using namespace std;
class Date
{
private :
int day;
int month;
int year;
void askDay();
void askMonth();
void askYear();
public :
void setDay(int day);
void setMonth(int month);
void setYear(int year);
int getDay()const ;
int getMonth()const ;
int getYear()const ;
void setAC();
void setBC();
bool isAC()const ;
bool isBC()const ;
bool isLeapYear()const ;
void askDate();
void showDay()const ;
void showMonth()const ;
void showYear()const ;
void showDate()const ;
Date& operator =(const Date& aDate);
bool operator ==(const Date& aDate)const ;
bool operator !=(const Date& aDate)const ;
bool operator >(const Date& aDate)const ;
bool operator <(const Date& aDate)const ;
friend ostream& operator <<(ostream& out, const Date& aDate);
friend istream& operator >>(istream& in, Date& aDate);
Date(int month = 1, int day = 1, int year = 1);
Date(const Date& aDate);
~Date();
};
#endif
Mar 26, 2013 at 5:01am UTC
Errors I'm getting
1>------ Rebuild All started: Project: Payroll, Configuration: Debug Win32 ------
1> employeelist.cpp
1>c:\users\zekk ragnos\documents\visual studio 2012\projects\payroll\payroll\employeelist.cpp(33): error C2511: 'bool employeelist::includes(Employee &) const' : overloaded member function not found in 'employeelist'
1> c:\users\zekk ragnos\documents\visual studio 2012\projects\payroll\payroll\employeelist.h(10) : see declaration of 'employeelist'
1>c:\users\zekk ragnos\documents\visual studio 2012\projects\payroll\payroll\employeelist.cpp(48): error C2511: 'bool employeelist::includes(Employee &) const' : overloaded member function not found in 'employeelist'
1> c:\users\zekk ragnos\documents\visual studio 2012\projects\payroll\payroll\employeelist.h(10) : see declaration of 'employeelist'
1>c:\users\zekk ragnos\documents\visual studio 2012\projects\payroll\payroll\employeelist.cpp(73): error C2512: 'Employee' : no appropriate default constructor available
1>c:\users\zekk ragnos\documents\visual studio 2012\projects\payroll\payroll\employeelist.cpp(78): error C2512: 'Employee' : no appropriate default constructor available
1> Employee.cpp
1> driver.cpp
1> Date.cpp
1> Generating Code...
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Topic archived. No new replies allowed.