- •Ф едеральное агенство воздушного транспорта (росавиация)
- •Аннотация
- •Оглавление
- •Цель курсовой работы
- •Задание на выполнение курсовой работы
- •Назначение и возможности разработанной системы
- •Программа системы
- •Структура программы
- •Схемы алгоритмов функций
- •Руководство по использованию программы
- •Листинг программ Файл Header.H
- •Файл Header.Cpp
- •Файл menu.Cpp
- •Исходные файлы с данными
- •Результат работы программы
Файл Header.Cpp
#include "Header.h"
void Database::addEmployee() {
for (int i = 0; i < size; i++) {
fout.open(a[db[i].department], ios::app, ios::binary);
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
fout.close();
}
}
void Database::showEmployees() {
string dep;
int buf = 0;
case2:
cout << "Enter the departament where you want to view employees" << endl;
cin >> dep;
for (auto iter{ a.cbegin() }; iter != a.cend(); ++iter) {
if (iter->first == dep) buf++;
}
if (buf == 0) {
cout << "No such department was found. Try entering another department" << endl;
goto case2;
}
vector<Employees> a;
for (int i = 0; i < db.size(); ++i) {
if (dep == db[i].department) {
a.push_back(db[i]);
}
}
Employees* b = new Employees[a.size()];
for (int i = 0; i < a.size(); ++i) {
b[i] = a[i];
}
for (int i = 0; i < a.size() - 1; i++) {
for (int j = 0; j < a.size() - i - 1; j++) {
if (b[j].name > b[j + 1].name)
swap(b[j], b[j + 1]);
}
}
for (int i = 0; i < a.size(); ++i) {
cout << b[i].name << " " << b[i].position << " " << b[i].year_of_birth << " " << b[i].salary << " " << b[i].employee_number << endl;
}
}
void Database::addEmployeeFromFile() {
string s = "C:\\adding.txt";
in.open(s);
for (int i = 0; i < size; ++i) {
Employees f;
in >> f.name;
in >> f.department;
in >> f.position;
in >> f.year_of_birth;
in >> f.salary;
in >> f.employee_number;
fout.open(a[f.department], ios::app, ios::binary);
fout << f.name << " " << f.department << " " << f.position << " " << f.year_of_birth << " " << f.salary << " " << f.employee_number << endl;
fout.close();
db.push_back(f);
}
in.close();
string f = "C:\\employees.txt";
fout.open(f);
for (int i = 0; i < db.size(); ++i) {
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
}
fout.close();
cout << "Employee was successfully added" << endl;
}
void Database::addEmployeeFromKeybord() {
Employees f;
cin >> f.name;
cin >> f.department;
cin >> f.position;
cin >> f.year_of_birth;
cin >> f.salary;
cin >> f.employee_number;
fout.open(a[f.department], ios::app, ios::binary);
fout << f.name << " " << f.department << " " << f.position << " " << f.year_of_birth << " " << f.salary << " " << f.employee_number << endl;
fout.close();
db.push_back(f);
string ff = "C:\\employees.txt";
fout.open(ff);
for (int i = 0; i < db.size(); ++i) {
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
}
fout.close();
cout << "Employee was successfully added" << endl;
}
void Database::modifySalaryFromKeybord() {
string dep;
int buf = 0;
case2:
cout << "Enter the departament you want to modify salary in" << endl;
cin >> dep;
for (auto iter{ a.cbegin() }; iter != a.cend(); ++iter) {
if (iter->first == dep) buf++;
}
if (buf == 0) {
cout << "No such department was found. Try entering another department" << endl;
goto case2;
}
string n;
int c;
cout << "Enter name and delta of salary" << endl;
cin >> n;
cin >> c;
string f = "C:\\employees.txt";
fout.open(f);
for (int i = 0; i < size - 1; ++i) {
if (db[i].department == dep && db[i].name == n) {
db[i].salary = db[i].salary + c;
}
}
for (int i = 0; i < size; ++i) {
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
}
fout.close();
fout.open(a[dep], ios::binary);
for (int i = 0; i < size; ++i) {
if (db[i].department == dep) {
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
}
}
fout.close();
cout << "Salary was successfully modified" << endl;
}
void Database::modifySalaryFromFile() {
string ff = "C:\\modify.txt";
string ss = "C:\\employees.txt";
char memory[1000];
in.open(ff);
int count1 = 0;
while (!in.eof()) {
count1++;
in.getline(memory, 1000);
}
in.close();
in.open(ff);
for (int i = 0; i < count1; ++i) {
Employees F1;
in >> F1.name;
in >> F1.department;
in >> F1.position;
in >> F1.year_of_birth;
in >> F1.salary;
in >> F1.employee_number;
for (int j = 0; j < size; ++j) {
if ((db[j].department == F1.department) && (db[j].name == F1.name)) {
db[j].salary = db[j].salary + F1.salary;
}
}
}
in.close();
fout.open(ss);
for (int i = 0; i < size; ++i) {
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
}
fout.close();
for (auto iter{ a.cbegin() }; iter != a.cend(); ++iter) {
fout.open(iter->second, ios::binary);
for (int i = 0; i < size; ++i) {
if (db[i].department == iter->first) {
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
}
}
fout.close();
}
cout << "Salary was successfully modified" << endl;
}
void Database::Search() {
cout << "Enter the department you want to do search in" << endl;
case2:
string dep;
cin >> dep;
int buf = 0;
for (auto iter{ a.cbegin() }; iter != a.cend(); ++iter) {
if (iter->first == dep) buf++;
}
if (buf == 0) {
cout << "No such department was found. Try entering another department" << endl;
goto case2;
}
int c = 9;
while (c != 0) {
case1:
cout << "\n\nEnter the number of variant you want to do search" << endl;
cout << "\n" <<
"|---------------------------------------------|\n"
"| MENU |\n"
"|---------------------------------------------|\n"
"| Position | 1 |\n"
"| Year of birth | 2 |\n"
"| Salary | 3 |\n"
"| Position and year of birth | 4 |\n"
"| Position and salary | 5 |\n"
"| Year of birth and salary | 6 |\n"
"| Position, year of birth and salary | 7 |\n"
"| Exit | 0 |\n"
"|---------------------------------------------|\n";
cin >> c;
switch (c)
{
case 1: {
cout << "Enter the position you want to find" << endl;
string pos;
int buf = 0;
cin >> pos;
for (int i = 0; i < size; ++i) {
if ((pos == db[i].position) && (dep == db[i].department)) {
cout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
buf++;
}
}
if (buf == 0) {
cout << "Person with such position was not found" << endl;
}
goto case1;
}
case 2: {
cout << "Enter the year of birth you want to find" << endl;
int year;
int buf = 0;
cin >> year;
for (int i = 0; i < size; ++i) {
if ((year == db[i].year_of_birth) && (dep == db[i].department)) {
cout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
buf++;
}
}
if (buf == 0) {
cout << "Person with such year of birth was not found" << endl;
}
goto case1;
}
case 3: {
cout << "Enter the salary you want to find" << endl;
int sal;
int buf = 0;
cin >> sal;
for (int i = 0; i < size; ++i) {
if ((sal == db[i].salary) && (dep == db[i].department)) {
cout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
buf++;
}
}
if (buf == 0) {
cout << "Person with such salary was not found" << endl;
}
goto case1;
}
case 4: {
cout << "Enter the position and year of birth you want to find" << endl;
string pos;
int year;
int buf = 0;
cin >> pos;
cin >> year;
for (int i = 0; i < size; ++i) {
if ((pos == db[i].position) && (year == db[i].year_of_birth) && (dep == db[i].department)) {
cout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
buf++;
}
}
if (buf == 0) {
cout << "Person with such position and year of birth was not found" << endl;
}
goto case1;
}
case 5: {
cout << "Enter the position and salary you want to find" << endl;
string pos;
int sal;
int buf = 0;
cin >> pos;
cin >> sal;
for (int i = 0; i < size; ++i) {
if ((pos == db[i].position) && (sal == db[i].salary) && (dep == db[i].department)) {
cout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
buf++;
}
}
if (buf == 0) {
cout << "Person with such position and salary was not found" << endl;
}
goto case1;
}
case 6: {
cout << "Enter the year of birth and salary you want to find" << endl;
int year;
int sal;
int buf = 0;
cin >> year;
cin >> sal;
for (int i = 0; i < size; ++i) {
if ((year == db[i].year_of_birth) && (sal == db[i].salary) && (dep == db[i].department)) {
cout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
buf++;
}
if (buf == 0) {
cout << "Person with such year of birth and salary was not found" << endl;
}
goto case1;
}
}
case 7: {
cout << "Enter the position, year of birth and salary you want to find" << endl;
string pos;
int year;
int sal;
int buf = 0;
cin >> pos;
cin >> year;
cin >> sal;
for (int i = 0; i < size; ++i) {
if ((pos == db[i].position) && (year == db[i].year_of_birth) && (sal == db[i].salary) && (dep == db[i].department)) {
cout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
buf++;
}
}
if (buf == 0) {
cout << "Person with such position, year of birth and salary was not found" << endl;
}
goto case1;
for (int i = 0; i < size - 1; ++i) {
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
}
fout.close();
fout.open(a[dep], ios::binary);
for (int i = 0; i < size - 1; ++i) {
if (db[i].department == dep) {
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
}
}
fout.close();
}
}
}
cout << "Employee was successfully found" << endl;
}
void Database::deletingFromKeybord() {
case1:
cout << "Enter the department you want to delete in" << endl;
string dep;
cin >> dep;
int buf = 0;
for (auto iter{ a.cbegin() }; iter != a.cend(); ++iter) {
if (iter->first == dep) buf++;
}
if (buf == 0) {
cout << "No such department was found. Try entering another department" << endl;
goto case1;
}
int c = 9;
while (c != 0) {
cout << "\n\nEnter the number of variant you want to do search" << endl;
cout << "\n" <<
"|---------------------------------------------|\n"
"| MENU |\n"
"|---------------------------------------------|\n"
"| Name | 1 |\n"
"| Position | 2 |\n"
"| Year of birth | 3 |\n"
"| Salary | 4 |\n"
"| Employee number | 5 |\n"
"| Exit | 0 |\n"
"|---------------------------------------------|\n";
cin >> c;
switch (c) {
case 1: {
cout << "Enter the name of employee you want to delete" << endl;
string n;
int buf = 0;
cin >> n;
for (int i = 0; i < db.size(); ++i) {
if (n == db[i].name && dep == db[i].department) {
db.erase(db.begin() + i);
buf++;
add2(dep);
}
}
if (buf == 0) {
cout << "Person with such name was not found" << endl;
}
goto case1;
}
case 2: {
cout << "Enter the position of employee you want to delete" << endl;
string pos;
int buf = 0;
cin >> pos;
for (int i = 0; i < db.size(); ++i) {
if (pos == db[i].position && dep == db[i].department) {
db.erase(db.begin() + i);
buf++;
add2(dep);
}
}
if (buf == 0) {
cout << "Person with such position was not found" << endl;
}
goto case1;
}
case 3: {
cout << "Enter the year of birth of employee you want to delete" << endl;
int year;
int buf = 0;
cin >> year;
for (int i = 0; i < db.size(); ++i) {
if (year == db[i].year_of_birth && dep == db[i].department) {
db.erase(db.begin() + i);
buf++;
add2(dep);
}
}
if (buf == 0) {
cout << "Person with such year of birth was not found" << endl;
}
goto case1;
}
case 4: {
cout << "Enter the salary of employee you want to delete" << endl;
int sal;
int buf = 0;
cin >> sal;
for (int i = 0; i < db.size(); ++i) {
if (sal == db[i].salary && dep == db[i].department) {
db.erase(db.begin() + i);
buf++;
add2(dep);
}
}
if (buf == 0) {
cout << "Person with such salary was not found" << endl;
}
goto case1;
}
case 5: {
cout << "Enter the employee number of employee you want to delete" << endl;
int num;
int buf = 0;
cin >> num;
for (int i = 0; i < db.size(); ++i) {
if (num == db[i].employee_number && dep == db[i].department) {
db.erase(db.begin() + i);
buf++;
add2(dep);
}
}
if (buf == 0) {
cout << "Person with such employee number was not found" << endl;
}
goto case1;
}
}
}
fout.open("C:\\employees.txt");
for (int i = 0; i < db.size(); ++i) {
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
}
fout.close();
fout.open(a[dep], ios::binary);
for (int i = 0; i < db.size(); ++i) {
if (db[i].department == dep) {
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
}
}
fout.close();
cout << "Employee was successfully deleted" << endl;
}
void Database::deletingFromFile() {
string del = "C:\\delete.txt";
string emp = "C:\\employees.txt";
char memory[1000];
in.open(del);
int count2 = 0;
while (!in.eof()) {
count2++;
in.getline(memory, 1000);
}
in.close();
in.open(del);
for (int i = 0; i < count2; ++i) {
Employees F1;
in >> F1.name;
in >> F1.department;
in >> F1.position;
in >> F1.year_of_birth;
in >> F1.salary;
in >> F1.employee_number;
for (int j = 0; j < db.size(); ++j) {
if ((db[j].department == F1.department) && (db[j].name == F1.name)) {
db.erase(db.begin() + j);
add2(F1.department);
}
}
}
in.close();
fout.open(emp);
for (int i = 0; i < db.size(); ++i) {
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
}
fout.close();
for (auto iter{ a.cbegin() }; iter != a.cend(); ++iter) {
fout.open(iter->second, ios::binary);
for (int i = 0; i < db.size(); ++i) {
if (db[i].department == iter->first) {
fout << db[i].name << " " << db[i].department << " " << db[i].position << " " << db[i].year_of_birth << " " << db[i].salary << " " << db[i].employee_number << endl;
}
}
fout.close();
}
cout << "Employee was successfully deleted" << endl;
}
bool cmp(pair<string, int>& a, pair<string, int>& b) {
return a.second < b.second;
}
void Database::Sort() {
typedef pair<string, int> Pair;
vector <Pair> vec;
for (auto& it : b) {
vec.push_back(it);
}
cout << vec[0].first;
sort(vec.begin(), vec.end(), cmp);
for (auto const& Pair : vec) {
cout << Pair.first << " " << Pair.second << endl;
}
cout << "Departments was successfully sorted" << endl;
}
