Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include<locale.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <conio.h>
- #include <string>
- #include <windows.h>
- #include <cstdio>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- int index_admin; //фиксирут номер админа, под которым заходим в систему
- int index_user; //фиксирует номер пользователя, под которым заходим в систему
- int flag_out=0; //флаг для выхода из программы
- int kol_admin=0; //количество зареганных админов в базе
- int kol_user=0; //количество зареганных пользователей в базе
- int kol_people=0; //количество участников в базе
- //структура для паролей
- struct reg{
- string login;
- string password;
- } admin[10000],user[10000];
- struct inf{ //структура для участников
- struct f_i_o{ //подструктура для ФИО
- string family;
- string name;
- string otch;
- } fio;
- string country;
- string team;
- int age;
- double ttime;
- } a[10000]; //в массиве а хранятся данные о участниках
- void Form_inf_people(){ //формируем файл inf_people.txt, в который записываем все данные о участниках
- ofstream out1("inf_people.txt"); //открываем файл
- for (int j=1; j<=kol_people; j++)
- out1<<a[j].country<<" "<<a[j].team<<" "<<a[j].fio.family<<" "<<a[j].fio.name<<" "<<a[j].fio.otch<<" "<<a[j].age<<" "<<a[j].ttime<<endl; //выводим в файл инфу
- out1.close(); //закрываем файл
- }
- void open_file(){ //выводим содержимое файла
- struct inf mas;
- cout<<"Содержимое файла с данными о людях:"<<endl;
- cout<<setw(15)<<left<<"Страна"<<setw(15)<<left<<"Команда"<<setw(15)<<left<<"Фамилия"<<setw(15)<<left<<"Имя"<<setw(15)<<left<<"Отчество"<<setw(15)<<left<<"Возраст"<<setw(15)<<left<<"Время заезда"<<endl;
- ifstream in1("inf_people.txt");
- for (int i=1; i<=kol_people; i++){
- in1>>mas.country>>mas.team>>mas.fio.family>>mas.fio.name>>mas.fio.otch>>mas.age>>mas.ttime;
- cout<<setw(15)<<left<<mas.country<<setw(15)<<left<<mas.team<<setw(15)<<left<<mas.fio.family<<setw(15)<<left<<mas.fio.name<<setw(15)<<left<<mas.fio.otch<<setw(15)<<left<<mas.age<<setw(15)<<left<<mas.ttime<<endl;
- }
- in1.close();
- }
- void new_people(){ //добавляем нового участника
- int n;
- cout<<endl<<"Введите количество человек, которое вы хотите добавить: ";
- cin>>n;
- for (int j=1; j<=n; j++){
- kol_people++;
- cout<<"Введите страну"<<endl;
- cin>>a[kol_people].country;
- cout<<"Введите название команды"<<endl;
- cin>>a[kol_people].team;
- cout<<"Введите фамилию"<<endl;
- cin>>a[kol_people].fio.family;
- cout<<"Введите имя"<<endl;
- cin>>a[kol_people].fio.name;
- cout<<"Введите отчество"<<endl;
- cin>>a[kol_people].fio.otch;
- cout<<"Введите возраст участника"<<endl;
- cin>>a[kol_people].age;
- cout<<"Введите время заезда участника"<<endl;
- cin>>a[kol_people].ttime;
- cout<<endl;
- }
- Form_inf_people();
- }
- void del_people(){ //удаляем участника по фамилии
- string ss;
- cout<<endl<<"Введите фамилию человека, которого хотите удалить"<<endl;
- cin>>ss;
- int index=(-1);
- for (int j=1; j<=kol_people; j++)
- if (a[j].fio.family==ss) { index=j; break; }
- if (index==(-1)) cout<<"Такой фамилии в списке нет! Повторите свой выбор!"<<endl;
- else {
- for (int j=index; j<=kol_people-1; j++)
- a[j]=a[j+1];
- kol_people--;
- cout<<"Человек успешно удалён"<<endl;
- }
- Form_inf_people();
- }
- void sort_people(){
- int r;
- struct inf w;
- cout<<"Выберите критерий сортировки:"<<endl;
- cout<<"1) Сортировать по фамилии (по возрастанию)"<<endl;
- cout<<"2) Сортировать по фамилии (по убыванию)"<<endl;
- cout<<"3) Сортировать по времени заезда (по возрастанию)"<<endl;
- cout<<"4) Сортировать по времени заезда (по убыванию)"<<endl;
- cout<<"5) Сортировать по возрасту (по возрастанию)"<<endl;
- cout<<"6) Сортировать по возрасту (по убыванию)"<<endl;
- cout<<"Ваш выбор:"<<endl;
- cin>>r;
- cout<<endl;
- int f=0;
- while (1==1){
- switch (r){
- case 1:
- for (int ii=1; ii<=kol_people-1; ii++)
- for (int jj=1; jj<=kol_people-ii; jj++)
- if (a[jj].fio.family>=a[jj+1].fio.family) {
- w=a[jj];
- a[jj]=a[jj+1];
- a[jj+1]=w;
- }
- f=1;
- break;
- case 2:
- for (int ii=1; ii<=kol_people-1; ii++)
- for (int jj=1; jj<=kol_people-ii; jj++)
- if (a[jj].fio.family<=a[jj+1].fio.family) {
- w=a[jj];
- a[jj]=a[jj+1];
- a[jj+1]=w;
- }
- f=1;
- break;
- case 3:
- for (int ii=1; ii<=kol_people-1; ii++)
- for (int jj=1; jj<=kol_people-ii; jj++)
- if (a[jj].ttime>=a[jj+1].ttime) {
- w=a[jj];
- a[jj]=a[jj+1];
- a[jj+1]=w;
- }
- f=1;
- break;
- case 4:
- for (int ii=1; ii<=kol_people-1; ii++)
- for (int jj=1; jj<=kol_people-ii; jj++)
- if (a[jj].ttime<=a[jj+1].ttime) {
- w=a[jj];
- a[jj]=a[jj+1];
- a[jj+1]=w;
- }
- f=1;
- break;
- case 5:
- for (int ii=1; ii<=kol_people-1; ii++)
- for (int jj=1; jj<=kol_people-ii; jj++)
- if (a[jj].age>=a[jj+1].age) {
- w=a[jj];
- a[jj]=a[jj+1];
- a[jj+1]=w;
- }
- f=1;
- break;
- case 6:
- for (int ii=1; ii<=kol_people-1; ii++)
- for (int jj=1; jj<=kol_people-ii; jj++)
- if (a[jj].age<=a[jj+1].age) {
- w=a[jj];
- a[jj]=a[jj+1];
- a[jj+1]=w;
- }
- f=1;
- break;
- default:
- cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
- }
- if (f==1) break;
- }
- Form_inf_people();
- open_file();
- }
- void editing_people(){
- string s;
- int f=0;
- cout<<endl<<"Введите фамилию для редактирования данных:"<<endl;
- cin>>s;
- for (int t=1; t<=kol_people; t++)
- if (a[t].fio.family==s) {
- cout<<"Введите новые данные"<<endl;
- cout<<"Введите страну"<<endl;
- cin>>a[t].country;
- cout<<"Введите название команды"<<endl;
- cin>>a[t].team;
- cout<<"Введите фамилию"<<endl;
- cin>>a[t].fio.family;
- cout<<"Введите имя"<<endl;
- cin>>a[t].fio.name;
- cout<<"Введите отчество"<<endl;
- cin>>a[t].fio.otch;
- cout<<"Введите возраст участника"<<endl;
- cin>>a[t].age;
- cout<<"Введите время заезда участника"<<endl;
- cin>>a[t].ttime;
- f=1;
- break;
- }
- if (f==0) cout<<"Такой фамилии нет!!!"<<endl;
- else {
- Form_inf_people();
- open_file();
- }
- }
- void search_people(){
- int tt;
- string s;
- cout<<"Введите фамилию человека, данные о котором вы хотите получить"<<endl;
- cin>>s;
- cout<<endl;
- int ff=0;
- for (int t=1; t<=kol_people; t++)
- if (s==a[t].fio.family) { if (tt==0) cout<<setw(15)<<left<<"Страна"<<setw(15)<<left<<"Команда"<<setw(15)<<left<<"Фамилия"<<setw(15)<<left<<"Имя"<<setw(15)<<left<<"Отчество"<<setw(15)<<left<<"Возраст"<<setw(15)<<left<<"Время заезда"<<endl;
- cout<<setw(15)<<left<<a[t].country<<setw(15)<<left<<a[t].team<<setw(15)<<left<<a[t].fio.family<<setw(15)<<left<<a[t].fio.name<<setw(15)<<left<<a[t].fio.otch<<setw(15)<<left<<a[t].age<<setw(15)<<left<<a[t].ttime<<endl;
- ff=1;
- tt=1;
- break;
- }
- if (ff==0) cout<<"Такой фамилии нет в базе!!!"<<endl;
- }
- void filtration(){ //фильтрируем данные по различным критериям
- int z, tt, age_x, age_y;
- string country, team;
- double time_x, time_y;
- cout<<"Выберите критерий фильтрации"<<endl;
- cout<<"1) По стране"<<endl;
- cout<<"2) По названию команды"<<endl;
- cout<<"3) По возрасту: меньше либо равному x, но большему либо равному y"<<endl;
- cout<<"4) По времени заезда: меньше либо равному x, но большему либо равному y"<<endl;
- int f=0;
- while (1==1){
- tt=0;
- cout<<"Ваш выбор"<<endl;
- cin>>z;
- cout<<endl;
- switch(z){
- case 1:
- cout<<"Введите страну: ";
- cin>>country;
- for (int t=1; t<=kol_people; t++)
- if (a[t].country==country) {
- if (tt==0) cout<<setw(15)<<left<<"Страна"<<setw(15)<<left<<"Команда"<<setw(15)<<left<<"Фамилия"<<setw(15)<<left<<"Имя"<<setw(15)<<left<<"Отчество"<<setw(15)<<left<<"Возраст"<<setw(15)<<left<<"Время заезда"<<endl;
- cout<<setw(15)<<left<<a[t].country<<setw(15)<<left<<a[t].team<<setw(15)<<left<<a[t].fio.family<<setw(15)<<left<<a[t].fio.name<<setw(15)<<left<<a[t].fio.otch<<setw(15)<<left<<a[t].age<<setw(15)<<left<<a[t].ttime<<endl;
- tt=1;
- }
- if (tt==0) cout<<"Таких людей нет!"<<endl;
- f=1;
- break;
- case 2:
- cout<<"Введите название команды: ";
- cin>>team;
- for (int t=1; t<=kol_people; t++)
- if (a[t].team==team) {
- if (tt==0) cout<<setw(15)<<left<<"Страна"<<setw(15)<<left<<"Команда"<<setw(15)<<left<<"Фамилия"<<setw(15)<<left<<"Имя"<<setw(15)<<left<<"Отчество"<<setw(15)<<left<<"Возраст"<<setw(15)<<left<<"Время заезда"<<endl;
- cout<<setw(15)<<left<<a[t].country<<setw(15)<<left<<a[t].team<<setw(15)<<left<<a[t].fio.family<<setw(15)<<left<<a[t].fio.name<<setw(15)<<left<<a[t].fio.otch<<setw(15)<<left<<a[t].age<<setw(15)<<left<<a[t].ttime<<endl;
- tt=1;
- }
- if (tt==0) cout<<"Таких людей нет!"<<endl;
- f=1;
- break;
- case 3:
- cout<<"Введите x и y: "<<endl;
- cin>>age_x>>age_y;
- for (int t=1; t<=kol_people; t++)
- if ( (a[t].age>=age_x) && (a[t].age<=age_y) ) {
- if (tt==0) cout<<setw(15)<<left<<"Страна"<<setw(15)<<left<<"Команда"<<setw(15)<<left<<"Фамилия"<<setw(15)<<left<<"Имя"<<setw(15)<<left<<"Отчество"<<setw(15)<<left<<"Возраст"<<setw(15)<<left<<"Время заезда"<<endl;
- cout<<setw(15)<<left<<a[t].country<<setw(15)<<left<<a[t].team<<setw(15)<<left<<a[t].fio.family<<setw(15)<<left<<a[t].fio.name<<setw(15)<<left<<a[t].fio.otch<<setw(15)<<left<<a[t].age<<setw(15)<<left<<a[t].ttime<<endl;
- tt=1;
- }
- if (tt==0) cout<<"Таких людей нет!"<<endl;
- f=1;
- break;
- case 4:
- cout<<"Введите x и y: "<<endl;
- cin>>time_x>>time_y;
- for (int t=1; t<=kol_people; t++)
- if ( (a[t].ttime>=time_x) && (a[t].ttime<=time_y) ) {
- if (tt==0) cout<<setw(15)<<left<<"Страна"<<setw(15)<<left<<"Команда"<<setw(15)<<left<<"Фамилия"<<setw(15)<<left<<"Имя"<<setw(15)<<left<<"Отчество"<<setw(15)<<left<<"Возраст"<<setw(15)<<left<<"Время заезда"<<endl;
- cout<<setw(15)<<left<<a[t].country<<setw(15)<<left<<a[t].team<<setw(15)<<left<<a[t].fio.family<<setw(15)<<left<<a[t].fio.name<<setw(15)<<left<<a[t].fio.otch<<setw(15)<<left<<a[t].age<<setw(15)<<left<<a[t].ttime<<endl;
- tt=1;
- }
- if (tt==0) cout<<"Таких людей нет!"<<endl;
- f=1;
- break;
- default:
- cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
- }
- if (f==1) break;
- }
- }
- void editing_admin(){ //смена логина\пароля админа
- int q;
- cout<<"1) Смена пароля"<<endl;
- cout<<"2) Смена логина"<<endl;
- int f=0;
- while (1==1){
- cout<<"Ваш выбор:"<<endl;
- cin>>q;
- cout<<endl;
- switch(q){
- case 1:
- cout<<"Введите новый пароль:"<<endl;
- cin>>admin[index_admin].password;
- cout<<endl<<"Ваш логин и пароль:"<<endl<<admin[index_admin].login<<" "<<admin[index_admin].password<<endl;
- f=1;
- break;
- case 2:
- cout<<"Введите новый логин:"<<endl;
- cin>>admin[index_admin].login;
- cout<<endl<<"Ваш логин и пароль:"<<endl<<admin[index_admin].login<<" "<<admin[index_admin].password<<endl;
- f=1;
- break;
- default:
- cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
- }
- if (f==1) break;
- }
- ofstream out1("registry_admin.txt");
- for (int ij=1; ij<=kol_admin; ij++)
- out1<<admin[ij].login<<" "<<admin[ij].password<<endl;
- out1.close();
- }
- void Menu_Admin(){
- flag_out=0;
- int x;
- int d=0;
- while (d==0){
- cout<<"1) Просмотреть данные"<<endl;
- cout<<"2) Добавить данные"<<endl;
- cout<<"3) Удалить данные"<<endl;
- cout<<"4) Сортировать данные"<<endl;
- cout<<"5) Редактировать данные"<<endl;
- cout<<"6) Поиск данных"<<endl;
- cout<<"7) Фильтрация данных"<<endl;
- cout<<"8) Смена пароля/логина"<<endl;
- cout<<"9) Выход из программы"<<endl;
- cout<<"10) Выход в Меню1"<<endl;
- cout<<"Ваш выбор:"<<endl;
- cin>>x;
- cout<<endl;
- switch(x){
- case 1:
- open_file();
- break;
- case 2:
- new_people();
- break;
- case 3:
- del_people();
- break;
- case 4:
- sort_people();
- break;
- case 5:
- editing_people();
- break;
- case 6:
- search_people();
- break;
- case 7:
- filtration();
- break;
- case 8:
- editing_admin();
- break;
- case 9:
- d=1;
- flag_out=1;
- break;
- case 10:
- d=1;
- break;
- default:
- cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
- }
- cout<<endl;
- if (d==1) break;
- }
- }
- void registry_admin(){ //регистрация нового админа
- kol_admin++;
- cout<<"Введиле логин:"<<endl;
- cin>>admin[kol_admin].login;
- cout<<"Введите пароль:"<<endl;
- cin>>admin[kol_admin].password;
- cout<<endl;
- ofstream out1("registry_admin.txt");
- for (int i=1; i<=kol_admin; i++)
- out1<<admin[i].login<<" "<<admin[i].password<<endl;
- out1.close();
- }
- void check_admin(){ //проверка верности логина и пароля при входе в систему
- string llogin, ppassword;
- cout<<"Введиле логин:"<<endl;
- cin>>llogin;
- cout<<"Введите пароль:"<<endl;
- cin>>ppassword;
- int flag=0;
- for (int i=1; i<=kol_admin; i++)
- if ( (admin[i].login==llogin) && (admin[i].password==ppassword) ) { flag=1; index_admin=i; }
- if (flag==0) cout<<"Вы ввели неверные логин и пароль"<<endl;
- else {cout<<"Пароль и логин верны, вы отправляетесь в Меню2"<<endl; Menu_Admin();}
- cout<<endl;
- }
- void code_Admin(){ //меню входа/регистрации в систему под админом
- int x;
- int d=0;
- while (d==0){
- if (flag_out==1) break;
- cout<<"1) Вход"<<endl;
- cout<<"2) Регистрация"<<endl;
- cout<<"3) Выход в Меню1"<<endl;
- cout<<"Ваш выбор:"<<endl;
- cin>>x;
- cout<<endl;
- switch(x){
- case 1:
- d=1;
- check_admin();
- break;
- case 2:
- d=1;
- registry_admin();
- break;
- case 3:
- d=1;
- break;
- default:
- cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
- }
- cout<<endl;
- if (d==1) break;
- }
- }
- void editing_user(){ //смена пароля\логина пользователя
- int q;
- cout<<"1) Смена пароля"<<endl;
- cout<<"2) Смена логина"<<endl;
- int f=0;
- while (1==1){
- cout<<"Ваш выбор:"<<endl;
- cin>>q;
- cout<<endl;
- switch(q){
- case 1:
- cout<<"Введите новый пароль:"<<endl;
- cin>>user[index_user].password;
- cout<<endl<<"Ваш логин и пароль:"<<endl<<user[index_user].login<<" "<<user[index_user].password<<endl;
- f=1;
- break;
- case 2:
- cout<<"Введите новый логин:"<<endl;
- cin>>user[index_user].login;
- cout<<endl<<"Ваш логин и пароль:"<<endl<<user[index_user].login<<" "<<user[index_user].password<<endl;
- f=1;
- break;
- default:
- cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
- }
- if (f==1) break;
- }
- ofstream out1("registry_user.txt");
- for (int ij=1; ij<=kol_user; ij++)
- out1<<user[ij].login<<" "<<user[ij].password<<endl;
- out1.close();
- }
- void Menu_User(){ //меню 2-го порядка для пользователя
- flag_out=0;
- int x;
- int d=0;
- while (d==0){
- cout<<"1) Просмотреть данные"<<endl;
- cout<<"2) Сортировать данные"<<endl;
- cout<<"3) Поиск данных"<<endl;
- cout<<"4) Фильтрация данных"<<endl;
- cout<<"5) Смена пароля/логина"<<endl;
- cout<<"6) Выход из программы"<<endl;
- cout<<"7) Выход в Меню1"<<endl;
- cout<<"Ваш выбор:"<<endl;
- cin>>x;
- cout<<endl;
- switch(x){
- case 1:
- open_file();
- break;
- case 2:
- sort_people();
- break;
- case 3:
- search_people();
- break;
- case 4:
- filtration();
- break;
- case 5:
- editing_user();
- break;
- case 6:
- d=1;
- flag_out=1;
- break;
- case 7:
- d=1;
- break;
- default:
- cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
- }
- cout<<endl;
- if (d==1) break;
- }
- }
- void registry_user(){ //регистрация нового пользователя
- kol_user++;
- cout<<"Введиле логин:"<<endl;
- cin>>user[kol_user].login;
- cout<<"Введите пароль:"<<endl;
- cin>>user[kol_user].password;
- cout<<endl;
- ofstream out1("registry_user.txt");
- for (int i=1; i<=kol_user; i++)
- out1<<user[i].login<<" "<<user[i].password<<endl;
- out1.close();
- }
- void check_user(){ //проверка правильности введённых логина и пароля
- string llogin, ppassword;
- cout<<"Введиле логин:"<<endl;
- cin>>llogin;
- cout<<"Введите пароль:"<<endl;
- cin>>ppassword;
- int flag=0;
- for (int i=1; i<=kol_user; i++)
- if ( (user[i].login==llogin) && (user[i].password==ppassword) ) { flag=1; index_user=i; }
- if (flag==0) cout<<"Вы ввели неверные логин и пароль"<<endl;
- else {cout<<"Пароль и логин верны, вы отправляетесь в Меню2"<<endl; Menu_User();}
- cout<<endl;
- }
- void code_User(){ //меню входа\регистрации в сисиему для пользователя
- int x;
- int d=0;
- while (d==0){
- if (flag_out==1) break;
- cout<<"1) Вход"<<endl;
- cout<<"2) Регистрация"<<endl;
- cout<<"3) Выход в Меню1"<<endl;
- cout<<"Ваш выбор:"<<endl;
- cin>>x;
- cout<<endl;
- switch(x){
- case 1:
- d=1;
- check_user();
- break;
- case 2:
- d=1;
- registry_user();
- break;
- case 3:
- d=1;
- break;
- default:
- cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
- }
- cout<<endl;
- if (d==1) break;
- }
- }
- int main()
- {
- bool Done = 0;
- int t;
- system("color F0");
- setlocale(LC_ALL, "Russian");
- while(Done!=1){
- if (flag_out==1) break;
- cout<<"Меню 1"<<endl;
- cout<<"1) Администратор"<<endl;
- cout<<"2) Пользователь"<<endl;
- cout<<"3) Выход"<<endl;
- cout<<"Ваш выбор:"<<endl;
- cin>>t;
- cout<<endl;
- switch(t){
- case 1:
- code_Admin();
- break;
- case 2:
- code_User();
- break;
- case 3:
- Done=1;
- break;
- default:
- cout<<"Такого пункта нет! Вы ввели неправильный вариант, попробуйте ввести ещё раз "<<endl;
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement