Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstdlib>
- using namespace std;
- /////////////////////////////////////////////////
- void registerr();
- void vxod();
- void reading_users();
- bool check_login(string);
- void guest(string);
- void admin(string);
- void reading_toys();
- void add_toy(string user_login);
- void visit(string user_login, int l);
- void users_visit(string user_login);
- void search(string user_login);
- void age_search(string user_login);
- int kol();
- int kol_users();
- void change_admin(string user_login);
- void name_search(string user_login);
- void cost(string user_login);
- void sort_toy(string user_login);
- void delete_toy(string user_login);
- void redact_toy(string user_login);
- void sort2_toy(string user_login);
- //////////////////////////////////////////////////////
- struct Users {
- string login;
- string password;
- int rights;
- }users[100000];
- struct Buses {
- int number;
- string bus_type;
- string destination;
- int arrive_time;
- int depart_time;
- }buses[100000];
- int main() {
- int vibor;
- setlocale(LC_ALL, "RUS");
- cout << "Меню:" << endl;
- cout << "1.Регистрация" << endl;
- cout << "2.Вход" << endl;
- cout << "3.Просмотр игрушек." << endl;
- while(!(cin>>vibor) || cin.get() != '\n')
- {
- system("cls");
- cout << "Не корректный ввод" << endl;
- cin.clear();
- cin.sync();
- main();
- }
- switch (vibor) {
- case 1: {system("cls"); registerr(); }
- case 2: {system("cls"); vxod(); }
- case 3: {system("cls"); visit("Guest", 0); }
- default: {system("cls");
- cout << "Не корректный ввод" << endl;
- main();
- }
- }
- }
- void reading_users() {
- ifstream fin("users.txt");
- for (int i = 0; i < 100; i++) {
- fin >> users[i].login >> users[i].password >> users[i].rights;
- }
- fin.close();
- }
- void registerr() {
- bool flag;
- reading_users();
- string user_login;
- string user_pass;
- cout << "Введите ваш новый логин:" << endl;
- cin >> user_login;
- cout << "Введите ваш новый пароль:" << endl;
- cin >> user_pass;
- flag = check_login(user_login);
- if (flag == false) {
- system("cls");
- cout << "Человек уже с таким логином существует!" << endl;
- int v;
- cout << "Вернуться в главное меню?" << endl;
- cout << "1.да" << endl;
- cout << "2.нет" << endl;
- while(!(cin>>v) || cin.get() != '\n')
- {
- system("cls");
- cout << "Не корректный ввод" << endl;
- cin.clear();
- cin.sync();
- main();
- }
- switch (v) {
- case 1: {system("cls");
- main(); }
- case 2: {system("cls");
- registerr(); }
- default: {system("cls");
- cout << "Некорректный ввод!" << endl;
- main(); }
- }
- }
- else {
- ofstream fout("users.txt", ios::app);
- fout << user_login << " " << user_pass << " " << 1 << endl;
- system("cls");
- cout << "Регистрация прошла успешно." << endl;
- main();
- }
- }
- void vxod() {
- reading_users();
- string user_login;
- string user_pass;
- cout << "Введите ваш логин:" << endl;
- cin >> user_login;
- cout << "Введите ваш пароль:" << endl;
- cin >> user_pass;
- for (int i = 0; i < 100; i++) {
- if (user_login == users[i].login && user_pass == users[i].password) {
- if (users[i].rights == 1) {
- system("cls");
- guest(user_login);
- }
- if (users[i].rights == 2) {
- system("cls");
- admin(user_login);
- }
- }
- }
- system("cls");
- cout << "Вы ввели не корректный логин/пароль!" << endl;
- main();
- }
- bool check_login(string user_login) {
- bool flag = true;
- for (int i = 0; i < 100; i++) {
- if (user_login == users[i].login) flag = false;
- }
- return flag;
- }
- void guest(string user_login) {
- int vibor;
- int l = 1;
- cout << "Здравстуйте " << user_login << " , вы вошли как гость." << endl << endl;
- cout << "Меню гостя:" << endl;
- cout << "1.Просмотр игрушек." << endl;
- cout << "2.Поиск игрушки." << endl;
- cout << "3.Сортировка по цене." << endl;
- cout << "4.Сортировка по возрасту." << endl;
- cout << "5.Выход." << endl;
- while(!(cin>>vibor) || cin.get() != '\n')
- {
- system("cls");
- cout << "Не корректный ввод" << endl;
- cin.clear();
- cin.sync();
- guest(user_login);
- }
- switch (vibor) {
- case 1: {system("cls");
- visit(user_login, l); }
- case 2: {system("cls");
- search(user_login); }
- case 3: {system("cls");
- sort_toy(user_login); }
- case 4: {system("cls");
- sort2_toy(user_login); }
- case 5: {system("cls");
- main(); }
- default: {system("cls");
- cout << "Не корректный ввод" << endl;
- guest(user_login);
- }
- }
- }
- void admin(string user_login) {
- int l = 2;
- cout << "Здравстуйте " << user_login << " , вы вошли как админ." << endl << endl;
- int vibor;
- cout << "Меню администратора:" << endl;
- cout << "1.Просмотр игрушек." << endl;
- cout << "2.Просмотр пользователей." << endl;
- cout << "3.Изменить права пользователя." << endl;
- cout << "4.Добавить игрушку." << endl;
- cout << "5.Удалить игрушку." << endl;
- cout << "6.Редактировать игрушку." << endl;
- cout << "7.Выход." << endl;
- while(!(cin>>vibor) || cin.get() != '\n')
- {
- system("cls");
- cout << "Не корректный ввод" << endl;
- cin.clear();
- cin.sync();
- admin(user_login);
- }
- switch (vibor) {
- case 1: {system("cls");
- visit(user_login, l); }
- case 2: {system("cls");
- users_visit(user_login); }
- case 3: {system("cls");
- change_admin(user_login); }
- case 4: {system("cls");
- add_toy(user_login); }
- case 5: {system("cls");
- delete_toy(user_login); }
- case 6: {system("cls");
- redact_toy(user_login); }
- case 7: {system("cls");
- main(); }
- default: {system("cls");
- cout << "Не корректный ввод" << endl;
- admin(user_login);
- }
- }
- }
- void reading_toys() {
- ifstream fin("routes.txt");
- for (int i = 0; i < 100; i++) {
- fin >> buses[i].number >> buses[i].bus_type >> buses[i].destination >> buses[i].arrive_time >> buses[i].depart_time;
- }
- fin.close();
- }
- void visit(string user_login, int l) {
- setlocale(LC_ALL, "RUS");
- reading_toys();
- int n=kol();
- for (int i = 0; i < n - 1; i++) {
- if (toys[i].name == "") { cout << "Игрушек в магазине нет." << endl; break; }
- cout << toys[i].name << " " << toys[i].cost << "$ " << toys[i].kol << "шт. от " << toys[i].age << " лет." << endl;
- }
- system("pause");
- system("cls");
- if (l == 1) {
- guest(user_login);
- }
- if (l == 2) {
- admin(user_login);
- }
- if (l == 0) {
- main();
- }
- }
- void search(string user_login) {
- int number;
- cout << "Поиск игрушки:" << endl;
- cout << "1.По названию." << endl;
- cout << "2.По возрастным границам." << endl;
- cout << "3.По ценовым границам" << endl;
- cout << "4.Выход в меню" << endl;
- while(!(cin>>number) || cin.get() != '\n')
- {
- system("cls");
- cout << "Не корректный ввод" << endl;
- cin.clear();
- cin.sync();
- search(user_login);
- }
- switch (number) {
- case 1: {system("cls");
- name_search(user_login); }
- case 2: {system("cls");
- age_search(user_login); }
- case 3: {system("cls");
- cost(user_login); }
- case 4: {system("cls");
- guest(user_login); }
- default: {system("cls");
- cout << "Не корректный ввод" << endl;
- search(user_login);
- }
- }
- }
- int kol() {
- ifstream FileInput("routes.txt", ifstream::in);
- int n = 0;
- while (FileInput)
- {
- string Lines;
- getline(FileInput, Lines);
- n++;
- }
- FileInput.close();
- return n;
- }
- void name_search(string user_login) {
- reading_toys();
- string name;
- cout << "Введите название игрушки." << endl;
- cin >> name;
- bool chanse = false;
- for (int i = 0; i < 100; i++) {
- if (name == toys[i].name) {
- cout << toys[i].name << " " << toys[i].cost << "$ " << toys[i].kol << "шт. от " << toys[i].age << " лет" << endl;
- chanse = true;
- }
- }
- if (chanse == false) {
- cout << "Поиск не дал результатов." << endl;
- }
- string vibor;
- cout << "Вернуться в меню? y/n" << endl;
- cin >> vibor;
- if (vibor == "y") {
- system("cls");
- guest(user_login);
- }
- else {
- system("cls");
- name_search(user_login);
- }
- }
- void age_search(string user_login) {
- bool chahce = false;
- reading_toys();
- int age;
- cout << "Сколько лет ребёнку?" << endl;
- cin >> age;
- for (int i = 0; i < 100; i++) {
- if (age >= toys[i].age && toys[i].age != 0) {
- cout << toys[i].name << " " << toys[i].cost << "$ " << toys[i].kol << "шт от " << toys[i].age << " лет" << endl;
- chahce = true;
- }
- }
- if (chahce == false) {
- cout << "Поиск не дал результатов." << endl;
- }
- string vibor;
- cout << "Вернуться в меню? y/n" << endl;
- cin >> vibor;
- if (vibor == "y") {
- system("cls");
- guest(user_login);
- }
- else {
- system("cls");
- age_search(user_login);
- }
- }
- void cost(string user_login) {
- bool chahce = false;
- reading_toys();
- int cost1, cost2;
- cout << "Цена от и до?" << endl;
- cin >> cost1 >> cost2;
- for (int i = 0; i < 100; i++) {
- if (cost1 <= toys[i].cost && toys[i].cost <= cost2) {
- cout << toys[i].name << " " << toys[i].cost << "$ " << toys[i].kol << "шт от " << toys[i].age << " лет" << endl;
- chahce = true;
- }
- }
- if (chahce == false) {
- cout << "Поиск не дал результатов." << endl;
- }
- string vibor;
- cout << "Вернуться в меню? y/n" << endl;
- cin >> vibor;
- if (vibor == "y") {
- system("cls");
- guest(user_login);
- }
- else {
- system("cls");
- cost(user_login);
- }
- }
- void users_visit(string user_login) {
- setlocale(LC_ALL,"RUS");
- reading_users();
- int n=kol_users();
- for (int i = 0; i < n - 1; i++) {
- cout << users[i].login << " " << users[i].password << " ";
- if(users[i].rights==1) cout <<"Гость" << endl;
- if(users[i].rights==2) cout <<"Админ" << endl;
- }
- system("pause");
- system("cls");
- admin(user_login);
- }
- int kol_users() {
- ifstream FileInput("users.txt", ifstream::in);
- int n = 0;
- while (FileInput)
- {
- string Lines;
- getline(FileInput, Lines);
- n++;
- }
- FileInput.close();
- return n;
- }
- void change_admin(string user_login) {
- reading_users();
- int n=kol_users();
- bool flag = true;
- string login_user;
- cout << "Введите логин пользователя для изменения прав." << endl;
- cin >> login_user;
- for (int i = 0; i < 100; i++) {
- if (login_user == users[i].login) {
- flag = false;
- if (users[i].rights == 1) {
- users[i].rights = 2;
- cout << "Права " << login_user << " изменены на админ." << endl;
- ofstream fout("users.txt");
- for (int i = 0; i < n - 1; i++) {
- fout << users[i].login << " " << users[i].password << " " << users[i].rights << endl;
- }
- fout.close();
- break;
- }
- if (users[i].rights == 2) {
- users[i].rights = 1;
- cout << "Права " << login_user << " изменены на гость." << endl;
- ofstream fout("users.txt");
- for (int i = 0; i < n - 1; i++) {
- fout << users[i].login << " " << users[i].password << " " << users[i].rights << endl;
- }
- fout.close();
- break;
- }
- }
- }
- if (flag == true) {
- cout << "Пользователь с таким логином не был найден." << endl;
- }
- if (user_login == login_user) {
- system("pause");
- system("cls");
- main();
- }
- system("pause");
- system("cls");
- admin(user_login);
- }
- void add_toy(string user_login) {
- int n=kol();
- cout << "Введите номер рейса:" << endl;
- cin >> buses[n-1].number;
- cout << "Введите тип автобуса:" << endl;
- while(!(cin >> buses[n-1].bus_type) || cin.get() != '\n')
- {
- cout << "Не корректный ввод" << endl;
- cout << "Введите номер рейса:" << endl;
- cin.clear();
- cin.sync();
- }
- cout << "Введите пункт назначения:" << endl;
- while(!(cin >> buses[n-1].destination) || cin.get() != '\n')
- {
- cout << "Не корректный ввод" << endl;
- cout << "Введите пункт назначения:" << endl;
- cin.clear();
- cin.sync();
- }
- cout << "Введите время отправления автобуса:" << endl;
- while(!(cin >> buses[n-1].depart_time) || cin.get() != '\n')
- {
- cout << "Не корректный ввод" << endl;
- cout << "Введите время отправления автобуса:" << endl;
- cin.clear();
- cin.sync();
- }
- cout << "Введите время прибытия автобуса:" << endl;
- while(!(cin>>buses[n-1].arrive_time) || cin.get() != '\n')
- {
- cout << "Некорректный ввод" << endl;
- cout << "Введите время прибытия автобуса:" << endl;
- cin.clear();
- cin.sync();
- }
- ofstream fout("routes.txt");
- for (int i = 0; i < n; i++) {
- fout << buses[i].number << " " << buses[i].bus_type << " " << buses[i].destination << " " << buses[i].depart_time << buses[i].arrive_time << endl;
- }
- fout.close();
- system("pause");
- system("cls");
- admin(user_login);
- }
- void sort_toy(string user_login){
- int n=kol();
- reading_toys();
- for (int i = 0; i < n-1; i++) {
- for (int j = i+1; j < n-1; j++){
- if(toys[i].cost<toys[j].cost)
- {
- swap(toys[i].age,toys[j].age);
- swap(toys[i].cost,toys[j].cost);
- swap(toys[i].kol,toys[j].kol);
- swap(toys[i].name,toys[j].name);
- }
- }
- }
- for (int i = 0; i < n - 1; i++) {
- if (toys[i].name == "") { cout << "Игрушек в магазине нет." << endl; break; }
- cout << toys[i].name << " " << toys[i].cost << "$ " << toys[i].kol << "шт. от " << toys[i].age << " лет." << endl;
- }
- system("pause");
- system("cls");
- reading_toys();
- guest(user_login);
- }
- void delete_toy(string user_login){
- int n=kol();
- reading_toys();
- cout <<"Введите название игрушки, которую хотите удалить:"<<endl;
- int num;
- cin >> num;
- bool flag=true;
- cout <<"Игрушка:"<<endl;
- for (int i=0;i<n-1;i++){
- if(num==buses[i].number){
- cout << buses[i].number << " " << buses[i].bus_type << "$ " << buses[i].destination << "шт. от " << buses[i].depart_time << " лет." << buses[i].arrive_time << endl;
- flag=false;
- cout <<"Удалить y/n?"<<endl;
- string otvet;
- cin >> otvet;
- if(otvet !="y"){
- system("cls");
- admin(user_login);
- }
- buses[i].number=0;
- buses[i].bus_type="0";
- buses[i].destination="0";
- buses[i].depart_time=0;
- buses[i].arrive_time=0;
- }
- }
- if (flag==true){
- cout <<"Игрушки с таким названием не существует."<<endl;
- }
- else{
- ofstream fout("toys.txt");
- for (int i=0;i<n;i++){
- if (toys[i].name!="0"&&toys[i].kol!=0&&toys[i].cost!=0&&toys[i].age!=0){
- fout << toys[i].name << " " << toys[i].cost << " " << toys[i].kol << " " << toys[i].age << endl;
- }
- }
- cout<<"Удаление прошло успешно."<<endl;
- fout.close();
- }
- system("pause");
- system("cls");
- admin(user_login);
- }
- void redact_toy(string user_login){
- int b;
- int n=kol();
- reading_toys();
- bool flag=true;
- cout <<"Введите название игрушки, которую хотите редактировать:"<<endl;
- string name;
- cin >> name;
- cout <<"Игрушка:"<<endl;
- for (int i=0;i<n-1;i++){
- if(name==toys[i].name){
- b=i;
- flag=false;
- cout << toys[i].name << " " << toys[i].cost << "$ " << toys[i].kol << "шт. от " << toys[i].age << " лет." << endl;
- }
- }
- if (flag==true){
- cout <<"Игрушки с таким названием не существует."<<endl;
- system("pause");
- system("cls");
- admin(user_login);
- }
- start :int vibor;
- cout << "Меню редактирования:" << endl;
- cout << "1.Изменить название." << endl;
- cout << "2.Изменить стоймость." << endl;
- cout << "3.Изменить кол-во игрушки." << endl;
- cout << "4.Изменить допустимый возраст." << endl;
- cout << "5.Выход." << endl;
- while(!(cin>>vibor) || cin.get() != '\n')
- {
- system("cls");
- cout << "Не корректный ввод" << endl;
- cin.clear();
- cin.sync();
- goto start;
- }
- switch (vibor) {
- case 1: {
- cout <<"Введите новое название игрушки."<<endl;
- cin >> toys[b].name;
- cout <<"Название игрушки успешно изменено."<<endl;
- ofstream fout("toys.txt");
- for (int i = 0; i < n-1; i++) {
- fout << toys[i].name << " " << toys[i].cost << " " << toys[i].kol << " " << toys[i].age << endl;
- }
- fout.close();
- cout << toys[b].name << " " << toys[b].cost << "$ " << toys[b].kol << "шт. от " << toys[b].age << " лет." << endl;
- system("pause");
- system("cls");
- reading_toys();
- admin(user_login);
- }
- case 2: {
- cout <<"Введите новую стоимость игрушки."<<endl;
- cin >> toys[b].cost;
- cout <<"Cтоимость игрушки успешно изменена."<<endl;
- ofstream fout("toys.txt");
- for (int i = 0; i < n-1; i++) {
- fout << toys[i].name << " " << toys[i].cost << " " << toys[i].kol << " " << toys[i].age << endl;
- }
- fout.close();
- cout << toys[b].name << " " << toys[b].cost << "$ " << toys[b].kol << "шт. от " << toys[b].age << " лет." << endl;
- system("pause");
- system("cls");
- reading_toys();
- admin(user_login);
- }
- case 3: {
- cout <<"Введите новое кол-во игрушек."<<endl;
- cin >> toys[b].kol;
- cout <<"Кол-во игрушек успешно изменено."<<endl;
- ofstream fout("toys.txt");
- for (int i = 0; i < n-1; i++) {
- fout << toys[i].name << " " << toys[i].cost << " " << toys[i].kol << " " << toys[i].age << endl;
- }
- fout.close();
- cout << toys[b].name << " " << toys[b].cost << "$ " << toys[b].kol << "шт. от " << toys[b].age << " лет." << endl;
- system("pause");
- system("cls");
- reading_toys();
- admin(user_login);
- }
- case 4: {
- cout <<"Введите новый допустимый возраст для игрушеки."<<endl;
- cin >> toys[b].age;
- cout <<"Допустимый возраст для игрушеки успешно изменен."<<endl;
- ofstream fout("toys.txt");
- for (int i = 0; i < n-1; i++) {
- fout << toys[i].name << " " << toys[i].cost << " " << toys[i].kol << " " << toys[i].age << endl;
- }
- fout.close();
- cout << toys[b].name << " " << toys[b].cost << "$ " << toys[b].kol << "шт. от " << toys[b].age << " лет." << endl;
- system("pause");
- system("cls");
- reading_toys();
- admin(user_login);
- }
- case 5: {system("cls");
- admin(user_login); }
- default: {system("cls");
- cout << "Не корректный ввод" << endl;
- redact_toy(user_login);
- }
- }
- }
- void sort2_toy(string user_login){
- int n=kol();
- reading_toys();
- for (int i = 0; i < n-1; i++) {
- for (int j = i+1; j < n-1; j++){
- if(toys[i].age > toys[j].age)
- {
- swap(toys[i].age,toys[j].age);
- swap(toys[i].cost,toys[j].cost);
- swap(toys[i].kol,toys[j].kol);
- swap(toys[i].name,toys[j].name);
- }
- }
- }
- for (int i = 0; i < n - 1; i++) {
- if (toys[i].name == "") { cout << "Игрушек в магазине нет." << endl; break; }
- cout << toys[i].name << " " << toys[i].cost << "$ " << toys[i].kol << "шт. от " << toys[i].age << " лет." << endl;
- }
- system("pause");
- system("cls");
- reading_toys();
- guest(user_login);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement