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
|
main.cpp
#include "Teacher.h"
#include "Assistant.h"
#include "TA.h"
#include "Employee.h"
#include <stdio.h>
#include <crtdbg.h>
#include <string>
#include <iostream>
#include <sstream>
using namespace std;
int menu()
{
cout << "\n0. Quit\n1. New assistent\n2. New TA-personel\n3. New teacher\n4. Print all\n\nInput: ";
int choice=0;
cin >> choice;
cin.ignore();
return choice;
}
Employee** addEmployee(Employee** arr, Employee* e, int &nrOfEmployees)
{
nrOfEmployees++;
//cout << "\n\n" << nrOfEmployees << "\n\n";
Employee** temp = new Employee*[nrOfEmployees];
for(int i=0;i<nrOfEmployees-1;i++)
{
temp[i] = arr[i];
}
temp[nrOfEmployees-1] = e;
delete[] arr;
arr = new Employee*[nrOfEmployees];
for(int i=0;i<nrOfEmployees;i++)
{
arr[i] = temp[i];
}
delete temp;
return arr;
}
int main()
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
int choice=0, nrOfEmployees=0;
Employment* empl;
Employee* e;
Employee** personel = new Employee*[0];
do
{
string name, position, mainSubject, studyProgram;
int birthyear, wage, workingHours, pointsTaken;
bool isManager, isProgramManager, canCertify, hasSuperKey;
choice = menu();
switch(choice)
{
case 0:
for(int i=0; i<nrOfEmployees;i++)
{
delete personel[i]->getposition();
}
delete[] personel;
empl = NULL;
e = NULL;
delete empl;
delete e;
break;
case 1:
{
cout << "Name: ";
getline(cin,name);
cout << "Birthyear: ";
cin >> birthyear;
cin.ignore();
cout << "Position: ";
cin >> position;
cin.ignore();
cout << "Wage: ";
cin >> wage;
cin.ignore();
cout << "Program studied: ";
cin >> studyProgram;
cin.ignore();
cout << "Points taken: ";
cin >> pointsTaken;
cin.ignore();
empl = new Assistant(position, wage, studyProgram, pointsTaken);
e = new Employee(name, birthyear, empl);
personel = addEmployee(personel, e, nrOfEmployees);
}
break;
case 2:
{
cout << "Name: ";
getline(cin,name);
cout << "Birthyear: ";
cin >> birthyear;
cin.ignore();
cout << "Position: ";
cin >> position;
cin.ignore();
cout << "Wage: ";
cin >> wage;
cin.ignore();
cout << "Manager (1/0): ";
cin >> isManager;
cin.ignore();
cout << "Working hours: ";
cin >> workingHours;
cin.ignore();
cout << "Can certify (1/0): ";
cin >> canCertify;
cin.ignore();
cout << "Has superkey (1/0): ";
cin >> hasSuperKey;
cin.ignore();
empl = new TA(position, isManager, wage, workingHours, canCertify, hasSuperKey);
e = new Employee(name, birthyear, empl);
personel = addEmployee(personel, e, nrOfEmployees);
}
break;
case 3:
{
cout << "Name: ";
getline(cin,name);
cout << "Birthyear: ";
cin >> birthyear;
cin.ignore();
cout << "Position: ";
cin >> position;
cin.ignore();
cout << "Wage: ";
cin >> wage;
cin.ignore();
cout << "Manager (1/0): ";
cin >> isManager;
cin.ignore();
cout << "Working hours: ";
cin >> workingHours;
cin.ignore();
cout << "Main subject: ";
cin >> mainSubject;
cin.ignore();
cout << "Program manager (1/0): ";
cin >> isProgramManager;
cin.ignore();
empl = new Teacher(position, isManager, wage, workingHours, mainSubject, isProgramManager);
e = new Employee(name, birthyear, empl);
personel = addEmployee(personel, e, nrOfEmployees);
}
break;
case 4:
{
cout << endl;
for(int i=0;i<nrOfEmployees;i++)
{
cout << "Employee " << i+1<< ":\n" << personel[i]->toString() << endl;
}
}
break;
default:
break;
}
}while(choice!=0);
return 0;
}
|