Here is the code with most of the syntax errors and the non-standard sections removed:
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
|
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
class Date
{
public:
private:
int year;
int month;
int day;
};
class Employee
{
public:
Employee();
void input();
private:
Date emp_year;
Date emp_month;
Date emp_day;
enum occupation {accountant, laborer, plumber, cook, director, clerk};
int emp_number;
double emp_salary;
};
int main()
{
Employee e1, e2, e3;
char choice;
do
{
cout<<"Enter the first employee.\n";
e1.input();
cout<<"Do you wish to enter three more employees? (y/n)\n";
cin>>choice;
}while(choice=='y');
cout<<"Have a nice day\n";
exit(1);
return 0;
}
Employee::Employee(){}
void Employee::input()
{
char symbol;
cout<<"Enter the employee number: ";
cin>>emp_number;
while(emp_number)
{
cout<<"employee number can't be less than zero, enter again: ";
cin>>emp_number;
}
cout<<"Enter the employee's start date in the format 'mm/dd/yyyy': ";
cin>>emp_year;//problem here!
}
|
The problem now is that you're trying to gather input from cin and place that input into an object of type Date.
cin>>emp_year;
he compiler has no idea what it means to gather input and store it into an object of type Date. It knows how to do this for an int, or a double, of a float, or a char, or any other built-in variable, but how is it supposed to know what to do with a Date object?
Your choices are to either write the operator
>>
for the Date object yourself, or to only use it to input data into types the compiler already knows how to deal with. For example:
cin>>emp_year.year;
would gather data and put it into the
year
variable inside a
Date
object. As year is of type
int, the compiler already knows how to do this.
While I am here, this looks insane:
1 2 3
|
Date emp_year;
Date emp_month;
Date emp_day;
|
So each Employee has THREE Date objects. One is named emp_year, one is named emp_month, and one is named emp_day? It looks to me like you actually only want one Date object, and you want to store inside that single Date object a year, a month and a day. Making three separate Date objects and giving them these names suggests that you don't actually understand what classes are for.