#include <iostream>
#include <fstream>
#include <string.h>
#include "SortedType.h"
#include "ItemType.h"
ofstream outData;
enum CommandType {JOIN,QUIT,CHANGE,PROMOTE,DEMOTE,
PAYDAY,EMPLOYEES,UNEMPLOYED,DUMP,END};
void Join(SortedType&,SortedType&);
void GetCommand(CommandType&);
void Quit(SortedType&,SortedType&);
void Change(SortedType&);
void Unemployed(SortedType&);
void Dump(SortedType&,SortedType&);
void Employees(SortedType&);
void Payday(SortedType&,SortedType&);
void Demote(SortedType&);
void Promote(SortedType&);
void main()
{
using namespace std;
cout<<"Welcome to the Employee Program"<<endl;
CommandType command;
SortedType ourList,list2;
outData.open("data.dat");
GetCommand(command);
while(command != END)
{
switch(command)
{
case JOIN: Join(ourList,list2);break;
case QUIT: Quit(ourList,list2);break;
case CHANGE: Change(ourList);break;
case PROMOTE: Promote(ourList);break;
case DEMOTE: Demote(ourList);break;
case PAYDAY: Payday(ourList,list2);break;
case EMPLOYEES: Employees(ourList);break;
case UNEMPLOYED: Unemployed(list2);break;
case DUMP: Dump(ourList,list2);break;
}
GetCommand(command);
}
}
void GetCommand(CommandType& command)
{
cout<<"EMPLOYEE MENU PROGRAM"<<endl;
outData<<"EMPLOYEE MENU PROGRAM"<<endl;
cout<<"Type in a Capitial letter from the choices below then press ENTER"<<endl;
outData<<"Type in a Capitial letter from the choices below then press ENTER"<<endl;
cout<<endl;
outData<<endl;
cout<<" J: A person joins a new company."<<endl;
outData<<" J: A person joins a new company."<<endl;
cout<<" Q: A person quits a company."<<endl;
outData<<" Q: A person quits a company."<<endl;
cout<<" C: A person quits their job and joins a different company."<<endl;
outData<<" C: A person quits their job and joins a different company."<<endl;
cout<<" P: A person is promoted."<<endl;
outData<<" P: A person is promoted."<<endl;
cout<<" D: A person is demoted."<<endl;
outData<<" D: A person is demoted."<<endl;
cout<<" M: payday."<<endl;
outData<<" M: payday."<<endl;
cout<<" E: Print list of employees in a company."<<endl;
outData<<" E: Print list of employees in a company."<<endl;
cout<<" U: Print list of unemployeed people."<<endl;
outData<<" U: Print list of unemployeed people."<<endl;
cout<<" A: Print both employee and unemployeed list."<<endl;
outData<<" A: Print both employee and unemployeed list."<<endl;
cout<<" X: END OF PROGRAM"<<endl;
outData<<" X: END OF PROGRAM"<<endl;
char letter;
cin>>letter;
cout<<endl;
bool okay = false;
while(!okay)
{
okay = true;
switch(letter)
{
case 'J': command = JOIN; break;
case 'Q': command = QUIT; break;
case 'C': command = CHANGE; break;
case 'P': command = PROMOTE;break;
case 'D': command = DEMOTE;break;
case 'M': command = PAYDAY; break;
case 'E': command = EMPLOYEES; break;
case 'U': command = UNEMPLOYED; break;
case 'A': command = DUMP;break;
case 'X': command = END;break;
default: cout<<"Letter Entered was not one"
<<" of the choices above. ENTER"
<<" another Letter then press return: "<<endl;
outData<<"Letter Entered was not one"
<<" of the choices above. ENTER"
<<" another Letter then press return: "<<endl;
cin>>letter;
okay = false;
}
}
}
void Join(SortedType& ourList,SortedType& list2)
{
bool check;
string name,company;
cout<<"Enter the employee's name"<<endl;
outData<<"Enter the employee's name"<<endl;
cin>>name;
cout<<"Enter the company"<<endl;
outData<<"Enter the company"<<endl;
cin >> company;
ItemType obj(name,company);
int length = ourList.LengthIs();
list2.RetrieveItem(obj,check);
if(check)
list2.DeleteItem(obj);
for(int count = 0;count < length;count++)
{
ourList.GetNextItem(obj);
ourList.DeleteItem(obj);
obj.PromoteMe();
ourList.InsertItem(obj);
}
ourList.InsertItem(obj);
ourList.ResetList();
}
void Quit(SortedType& list2,SortedType& ourList)
{
cout<<"QUIT"<<endl;
string name,company;
cout<<"Enter the employee's name"<<endl;
outData<<"Enter the employee's name"<<endl;
cin>>name;
cout<<"Enter the company"<<endl;
outData<<"Enter the company"<<endl;
cin >> company;
ItemType obj(name,company);
int length = ourList.LengthIs();
ourList.DeleteItem(obj);
list2.InsertItem(obj);
for(int count = 0;count < length;count++)
{
ourList.GetNextItem(obj);
obj.DemoteMe();
ourList.InsertItem(obj);
}
}
void Change(SortedType& ourList)
{
cout<<"CHANGE"<<endl;
bool check = false;
string name,company;
while(!check)
{
check = true;
cout<<"Enter the employee's name"<<endl;
outData<<"Enter the employee's name"<<endl;
cin>>name;
cout<<"Enter the company"<<endl;
outData<<"Enter the company"<<endl;
cin >> company;
ItemType obj(name,company);
int length = ourList.LengthIs();
ourList.DeleteItem(obj);
for(int count = 0;count < length;count++)
{
ourList.GetNextItem(obj);
obj.PromoteMe();
ourList.InsertItem(obj);
}
ourList.ResetList();
}
int length = ourList.LengthIs();
ItemType obj(name,company);
for(int count = 0;count < length;count++)
{
ourList.GetNextItem(obj);
ourList.DeleteItem(obj);
obj.PromoteMe();
ourList.InsertItem(obj);
}
ourList.InsertItem(obj);
ourList.ResetList();
}
void Promote(SortedType& ourList)
{
string name,company;
cout<<"PROMOTE"<<endl;
cout<<"Enter the employee's name"<<endl;
outData<<"Enter the employee's name"<<endl;
cin>>name;
cout<<"Enter the company"<<endl;
outData<<"Enter the company"<<endl;
cin >> company;
ItemType obj(name,company);
ItemType obj2(name,company);
int length = ourList.LengthIs();
ourList.DeleteItem(obj);
ourList.GetNextItem(obj2);
ourList.DeleteItem(obj2);
ourList.InsertItem(obj2);
ourList.InsertItem(obj);
obj.PromoteMe();
obj2.DemoteMe();
/*else
{
cout<<"The person is already in the top position"
<<"They can not be promoted"<<endl;
outData<<"The person is already in the top position"
<<"They can not be promoted"<<endl;
}*/
}
void Demote(SortedType& ourList)
{
string name,company;
cout<<"DEMOTE"<<endl;
cout<<"Enter the employee's name"<<endl;
outData<<"Enter the employee's name"<<endl;
cin>>name;
cout<<"Enter the company"<<endl;
outData<<"Enter the company"<<endl;
cin >> company;
ItemType obj(name,company);
ItemType obj2(name,company);
int length = ourList.LengthIs();
//if(obj.rank < length)
//{
ourList.DeleteItem(obj);
ourList.GetNextItem(obj2);
ourList.DeleteItem(obj2);
ourList.InsertItem(obj2);
ourList.InsertItem(obj);
obj.DemoteMe();
obj2.PromoteMe();
//}
/*else
{
cout<<"The person is already in the bottom position"
<<"They can not be demoted"<<endl;
outData<<"The person is already in the bottom position"
<<"They can not be demoted"<<endl;
}*/
}
void Payday(SortedType& ourList, SortedType& list2)
{
cout<<"PAYDAY"<<endl;
outData<<"PAYDAY"<<endl;
string name,company;
ItemType obj(name,company);
bool okay = false;
int length = ourList.LengthIs();
ourList.ResetList();
for(int count = 0;count < length;count++)
{
ourList.GetNextItem(obj);
obj.PayMe(okay);
}
list2.ResetList();
int size = list2.LengthIs();
okay = true;
for(int k = 0;k < size;k++)
{
list2.GetNextItem(obj);
obj.PayMe(okay);
}
}
void Employees(SortedType& ourList)
{
string name,company;
ItemType obj(name,company);
cout<<"EMPLOYEES"<<endl;
outData<<"EMPLOYEES"<<endl;
cout<<"Enter the company's name:"<<endl;
outData<<"Enter the company's name:"<<endl;
cin>>company;
ourList.ResetList();
int length = ourList.LengthIs();
for(int count = 0;count < length;count++)
{
ourList.GetNextItem(obj);
obj.EPrint();
}
ourList.ResetList();
}
void Unemployed(SortedType& list2)
{
string name,company;
cout<<"UNEMPLOYED"<<endl;
ItemType obj(name,company);;
int length = list2.LengthIs();
list2.ResetList();
for(int count = 0;count < length;count++)
{
list2.GetNextItem(obj);
obj.UPrint();
}
list2.ResetList();
}
void Dump(SortedType& list2, SortedType& ourList)
{
string name,company;
ItemType obj(name,company);
cout<<"DUMP"<<endl;
int length = ourList.LengthIs();
cout<<"EMPLOYEES"<<endl;
for(int count = 0;count < length;count++)
{
ourList.GetNextItem(obj);
obj.EPrint();
}
int length2 = list2.LengthIs();
cout<<"UNEMPLOYED"<<endl;
for(int k = 0;k < length2;k++)
{
list2.GetNextItem(obj);
obj.UPrint();
}
}