#include <iostream>
#include <ctime>
#include <string>
#include <time.h>
#include<iomanip>
using namespace std;
string namegenerator()
{
char name[26], c = 'a';
for (int i = 0; i < 26; i++)
{
name[i] = c;
c++;
}
/* string af = "a" + 'b';*/
/* std::string s;
s += c;
std::cout << s << '\n';*/
string all = string(1, name[rand() % 27]) + string(1, name[rand() % 27]) + string(1, name[rand() % 27]) + string(1, name[rand() % 27]);
return all;
}
struct info
{
string last_name;
string group;
short physical;
short compucter;
short history;
};
struct midllelevel
{
string first_name;
string last_name;
string patronymic;
bool gender;
string position;
short day;
short month;
short year;
bool isCorrect()
{
bool result = false;
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
if ((day <= 31) && (day > 0))
result = true;
break;
}
case 4:
case 6:
case 9:
case 11:
{
if ((day <= 30) && (day > 0))
result = true;
break;
}
case 2:
{
if (year % 4 != 0)
{
if ((day <= 28) && (day > 0))
result = true;
}
else
if (year % 400 == 0)
{
if ((day <= 29) && (day > 0))
result = true;
}
else
if ((year % 100 == 0) && (year % 400 != 0))
{
if ((day == 28) && (day > 0))
result = true;
}
else
if ((year % 4 == 0) && (year % 100 != 0))
if ((day <= 29) && (day > 0))
result = true;
break;
}
default:
result = false;
}
return result;
}
};
struct PERSON
{
string Name;
string FAC;
string GROUP;
};
struct DATE
{
PERSON CEO;
short day;
short year;
short month;
bool isCorrect()
{
bool result = false;
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
if ((day <= 31) && (day > 0))
result = true;
break;
}
case 4:
case 6:
case 9:
case 11:
{
if ((day <= 30) && (day > 0))
result = true;
break;
}
case 2:
{
if (year % 4 != 0)
{
if ((day <= 28) && (day > 0))
result = true;
}
else
if (year % 400 == 0)
{
if ((day <= 29) && (day > 0))
result = true;
}
else
if ((year % 100 == 0) && (year % 400 != 0))
{
if ((day == 28) && (day > 0))
result = true;
}
else
if ((year % 4 == 0) && (year % 100 != 0))
if ((day <= 29) && (day > 0))
result = true;
break;
}
default:
result = false;
}
return result;
}
};
int main()
{
setlocale(0, "");
srand(time(NULL));
int swit;
while (1)
{
cout << "введите уровень сложности \n1 - базовый\n2 - средний\n3 - сложный" << endl;
cin >> swit;
if (swit == 1 || swit == 2 || swit == 3)
break;
cin.clear(); // на случай, если предыдущий ввод завершился с ошибкой
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
if (swit == 1)
{
int number;
while (1)
{
cout << "введите количество студентов" << endl;
cin >> number;
if (number > 0)
break;
else {
cout << "неправильный ввод" << endl;
cin.clear(); // на случай, если предыдущий ввод завершился с ошибкой
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
}
info* students = new info[number];
for (size_t i = 0; i < number; i++)
{
students[i].compucter = rand() % 6;
students[i].history = rand() % 6;
students[i].physical = rand() % 6;
students[i].last_name = namegenerator();
students[i].group = namegenerator();
}
int good = 0;
float meanphy = 0;
for (size_t i = 0; i < number; i++)
{
if (students[i].compucter == 5)
{
cout << "информатика " << students[i].compucter << endl;
cout << "история " << students[i].history << endl;
cout << "физика " << students[i].physical << endl;
cout << "фамилия " << students[i].last_name << endl;
cout << "группа " << students[i].group << endl;
cout << "_______________________" << endl;
good++;
}
meanphy += students[i].physical;
}
meanphy /= number;
cout << "средняя оценка по физике " << meanphy << endl;
}
else if (swit == 2)
{
int number;
while (1)
{
cout << "введите количество работников" << endl;
cin >> number;
if (number > 0)
{
break;
}
else
{
cout << "введите число корректно " << endl;
cin.clear(); // на случай, если предыдущий ввод завершился с ошибкой
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
}
midllelevel* arbaiten = new midllelevel[number];
float patr = 0;
for (size_t i = 0; i < number; i++)
{
int year = 0, month = 0, day = 0;
arbaiten[i].first_name = namegenerator();
arbaiten[i].gender = rand() % 2;
arbaiten[i].last_name = namegenerator();
arbaiten[i].position = namegenerator();
arbaiten[i].patronymic = namegenerator();
arbaiten[i].year = 2000 + rand() % 20;
arbaiten[i].month = 1 + rand() % 12;
arbaiten[i].day = rand() % 32;
while (1)
{
if (arbaiten[i].isCorrect() == false)
{
arbaiten[i].year = 2000 + rand() % 20;
arbaiten[i].month = 1 + rand() % 12;
arbaiten[i].day = rand() % 32;
}
else
{
break;
}
}
//365.2421897
}
double* stazh = new double[number], meanstazh = 0;
short day = 6, month = 3, year = 2020;
for (size_t i = 0; i < number; i++)
{
stazh[i] = (year - arbaiten[i].year) * 365.2421897 + (month - arbaiten[i].month) * 30, 4167 + (day - arbaiten[i].day);
meanstazh += stazh[i];
}
meanstazh /= number;
for (size_t i = 0; i < number; i++)
{
if (stazh[i] > meanstazh)
{
cout << "имя: " << arbaiten[i].first_name << endl;
cout << "отчество: " << arbaiten[i].patronymic << endl;
cout << "фамилия : " << arbaiten[i].last_name << endl;
if (arbaiten[i].gender == true)
{
cout << "пол: мужской" << endl;
}
else
{
cout << "пол: женский" << endl;
}
cout << "должность: " << arbaiten[i].position << endl;
cout << "дата приема на роботу: " << arbaiten[i].day << "." << arbaiten[i].month << "." << arbaiten[i].year << endl;
cout << "_________________________" << endl;
}
}
}
else if (swit == 3)
{
DATE* VUZ = new DATE[10];
unsigned long long int massive[10];
string gruppa[4] = { "AT","AR","AE","AM" };
string facult[4] = { "ICS","JGS","SLV","AFS" };
unsigned long long int realtime = time(NULL);
for (size_t i = 0; i < 10; i++)
{
VUZ[i].CEO.Name = namegenerator();
VUZ[i].CEO.FAC = facult[rand() % 4];
VUZ[i].CEO.GROUP = gruppa[rand() % 4];
while (1)
{
if (VUZ[i].isCorrect() == false)
{
VUZ[i].day = rand() % 32;
VUZ[i].month = rand() % 13;
VUZ[i].year = 1970 + rand() % 50;
massive[i] = realtime - (86400 * VUZ[i].day + 86400 * 30.4167 * VUZ[i].month + 86400 * 30.4167 * 12 * (VUZ[i].year - 1970));//86400 sec in 1 day
}
else
{
break;
}
}
}
for (size_t j = 0; j < 10; j++)
{
for (size_t i = 0; i < 9; i++)
{
if (massive[i] < massive[i + 1])
{
swap(massive[i], massive[i + 1]);
swap(VUZ[i], VUZ[i + 1]);
}
}
}
for (size_t i = 0; i < 10; i++)
{
cout << setw(6) << VUZ[i].CEO.Name << " ";
cout << setw(6) << VUZ[i].CEO.FAC << " ";
cout << setw(6) << VUZ[i].CEO.GROUP << " ";
cout << setw(6) << VUZ[i].day << " ";
cout << setw(6) << VUZ[i].month << " ";
cout << setw(6) << VUZ[i].year << endl;
}
cout << "___________________________________________" << endl;
//по группам отсортировать не получится тк группы будут одинаковые на разных факультетах
for (size_t j = 0; j < 10; j++)
{
for (size_t i = 1; i < 10; i++)
{
if (VUZ[i].CEO.FAC == "ICS" && VUZ[i - 1].CEO.FAC != "ICS")
{
swap(VUZ[i], VUZ[i - 1]);
}
if (VUZ[i].CEO.FAC == "JGS" && VUZ[i - 1].CEO.FAC != "ICS" && VUZ[i - 1].CEO.FAC != "JGS")
{
swap(VUZ[i], VUZ[i - 1]);
}
if (VUZ[i].CEO.FAC == "SLV" && VUZ[i - 1].CEO.FAC != "ICS" && VUZ[i - 1].CEO.FAC != "JGS" && VUZ[i - 1].CEO.FAC != "SLV")
{
swap(VUZ[i], VUZ[i - 1]);
}
if (VUZ[i].CEO.FAC == "AFS" && VUZ[i - 1].CEO.FAC != "ICS" && VUZ[i - 1].CEO.FAC != "JGS" && VUZ[i - 1].CEO.FAC != "SLV" && VUZ[i - 1].CEO.FAC != "AFS")
{
swap(VUZ[i], VUZ[i - 1]);
}
}
}
for (size_t j = 0; j < 10; j++)
{
for (size_t i = 1; i < 10; i++)
{
if (VUZ[i].CEO.FAC == "ICS" && VUZ[i - 1].CEO.FAC == "ICS" && VUZ[i].CEO.Name < VUZ[i-1].CEO.Name)
{
swap(VUZ[i], VUZ[i - 1]);
}
if (VUZ[i].CEO.FAC == "JGS" && VUZ[i - 1].CEO.FAC != "ICS" && VUZ[i - 1].CEO.FAC == "JGS" && VUZ[i].CEO.Name < VUZ[i-1].CEO.Name)
{
swap(VUZ[i], VUZ[i - 1]);
}
if (VUZ[i].CEO.FAC == "SLV" && VUZ[i - 1].CEO.FAC != "ICS" && VUZ[i - 1].CEO.FAC != "JGS" && VUZ[i - 1].CEO.FAC == "SLV" && VUZ[i].CEO.Name < VUZ[i-1].CEO.Name)
{
swap(VUZ[i], VUZ[i - 1]);
}
if (VUZ[i].CEO.FAC == "AFS" && VUZ[i - 1].CEO.FAC != "ICS" && VUZ[i - 1].CEO.FAC != "JGS" && VUZ[i - 1].CEO.FAC != "SLV" && VUZ[i - 1].CEO.FAC == "AFS" && VUZ[i].CEO.Name < VUZ[i-1].CEO.Name)
{
swap(VUZ[i], VUZ[i - 1]);
}
}
}
for (size_t i = 0; i < 10; i++)
{
cout << setw(6) << VUZ[i].CEO.Name << " ";
cout << setw(6) << VUZ[i].CEO.FAC << " ";
cout << setw(6) << VUZ[i].CEO.GROUP << " ";
cout << setw(6) << VUZ[i].day << " ";
cout << setw(6) << VUZ[i].month << " ";
cout << setw(6) << VUZ[i].year << endl;
}
cout << "___________________________________________" << endl;
}
return 0;
}