Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // AlenaKursach.cpp: главный файл проекта.
- #include "stdafx.h"
- #include "iostream"
- #include "fstream"
- #include "string"
- using namespace System;
- using namespace std;
- struct Resort
- {
- string PlaceOfResort;
- string CityOfResort;
- string PriceOfResort;
- string StayPrice;
- };
- struct Access
- {
- string login;
- string password;
- };
- Resort InformationAboutResort[100];
- Access LogAndPassInfo;
- int StartMenu();
- void ReadResort();
- void AddResortBook();
- void ReadResortBook();
- void SelectSort();
- void ClearResortBook();
- int LoginAndPassword();
- void ChangeUserAccess();
- int CountsOfResort();
- void ShekerSortPlace();
- void ShekerSortCity();
- void ShekerSortPrice();
- void ShekerSortStay();
- void ChangeInformation();
- int CountOfResort = 0;
- int main(array<System::String ^> ^args)
- {
- setlocale( 0, "Rus" );
- if ( LoginAndPassword() == 1 )
- {
- do
- {
- ReadResort();
- } while ( StartMenu() != 2 );
- }
- else
- {
- cout << "Неверное имя польователя или пароль!";
- }
- return 0;
- }
- int StartMenu()
- {
- int UserSelect;
- cout << "Добро пожаловать в справочник курортов! Что бы вы хотели сделать?" << endl;
- cout << "1) Добавление курорта в книгу." << endl;
- cout << "2) Вывод справочника на экран." << endl;
- cout << "3) Вывод сортированного справочника " << endl;
- cout << "4) Очистить курортную книгу." << endl;
- cout << "5) Изменить данные входа." << endl;
- cout << "6) Изменить данные." << endl;
- cout << "7) Выход из программы." << endl;
- cout << "Введите ваш выбор: ";
- cin >> UserSelect;
- switch ( UserSelect )
- {
- case 1:
- {
- AddResortBook();
- return 1;
- break;
- }
- case 2:
- {
- ReadResortBook();
- return 1;
- break;
- }
- case 3:
- {
- SelectSort();
- return 1;
- break;
- }
- case 4:
- {
- ClearResortBook();
- return 1;
- break;
- }
- case 5:
- {
- ChangeUserAccess();
- return 1;
- break;
- }
- case 6:
- {
- ChangeInformation();
- return 1;
- }
- case 7:
- {
- cout << "Досвидания, спасибо за использование программы!" << endl;
- return 2;
- break;
- }
- default:
- {
- cout << "Попробуйте еще раз!" << endl;
- StartMenu();
- return 1;
- break;
- }
- }
- }
- void AddResortBook()
- {
- CountOfResort = CountsOfResort() + 1;
- ofstream WorkWithFile;
- WorkWithFile.open( "ResortBook.txt", ios::app );
- cout << " Функция добавляет курорт в список" << endl;
- cout << "Введите наименование курорта:";
- cin >> InformationAboutResort[CountOfResort].PlaceOfResort;
- cout << endl;
- cout << "Введите город курорта: ";
- cin >> InformationAboutResort[CountOfResort].CityOfResort;
- cout << endl;
- cout << "Введите стоимость поездки ";
- cin >> InformationAboutResort[CountOfResort].PriceOfResort;
- cout << endl;
- cout << "Введите стоимость проживания ";
- cin >> InformationAboutResort[CountOfResort].StayPrice;
- cout << endl;
- WorkWithFile << InformationAboutResort[CountOfResort].PlaceOfResort << " " << InformationAboutResort[CountOfResort].CityOfResort << " " << InformationAboutResort[CountOfResort].PriceOfResort << " " << InformationAboutResort[CountOfResort].StayPrice << " " << endl;
- cout << "Данные занесены в книгу!" << endl;
- WorkWithFile.close();
- };
- void ReadResortBook()
- {
- CountOfResort = CountsOfResort();
- cout << "Курортов в списке: " << CountOfResort << endl;
- for (int i = 0; i < CountOfResort ; i++)
- {
- cout << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
- }
- };
- void SelectSort()
- {
- int MetodOfSort;
- cout << "По какому параметру произвести сортировку? " << endl;
- cout << "1) Наименование курорта." << endl;
- cout << "2) Город курорта." << endl;
- cout << "3) Стоимость поездки." << endl;
- cout << "4) Стоимость проживания." << endl;
- cout << "Ваш выбор: ";
- cin >> MetodOfSort;
- cout << endl;
- switch ( MetodOfSort )
- {
- case 1:
- {
- ShekerSortPlace();
- break;
- }
- case 2:
- {
- ShekerSortCity();
- break;
- }
- case 3:
- {
- ShekerSortPrice();
- break;
- }
- case 4:
- {
- ShekerSortStay();
- break;
- }
- default:
- {
- cout << "Попробуйте еще раз!" << endl;
- SelectSort();
- break;
- }
- }
- };
- void ClearResortBook()
- {
- fstream WorkWithFile;
- WorkWithFile.open( "ResortBook.txt", ios::out );
- WorkWithFile.clear();
- WorkWithFile.close();
- };
- int LoginAndPassword()
- {
- fstream WorkWithFile;
- WorkWithFile.open( "UserAccess.txt", ios::in );
- WorkWithFile.read( (char*)&LogAndPassInfo, sizeof( LogAndPassInfo ) );
- string UserName, Password;
- cout << " Добро пожаловать в программу, введите имя пользователя и пароль для входа в систему! " << endl;
- cout << "Имя пользователя: ";
- cin >> UserName;
- cout << endl;
- cout << "Пароль: ";
- cin >> Password;
- if ( UserName == LogAndPassInfo.login && Password == LogAndPassInfo.password )
- {
- return 1;
- }
- else
- {
- return 2;
- }
- }
- void ChangeUserAccess()
- {
- fstream WorkWithFile;
- WorkWithFile.open( "UserAccess.txt", ios::out );
- WorkWithFile.clear();
- cout << "Введите новое имя пользователя: ";
- cin >> LogAndPassInfo.login;
- cout << endl;
- cout << "Введите новый пароль: ";
- cin >> LogAndPassInfo.password;
- cout << endl;
- WorkWithFile.write( (char*)&LogAndPassInfo, sizeof ( LogAndPassInfo ) );
- WorkWithFile.close();
- }
- int CountsOfResort()
- {
- CountOfResort = 0;
- fstream WorkWithFile;
- WorkWithFile.open( "ResortBook.txt", ios::in );
- string text;
- while ( !WorkWithFile.eof() )
- {
- getline ( WorkWithFile, text);
- CountOfResort++;
- }
- WorkWithFile.close();
- return CountOfResort - 1;
- };
- void ReadResort()
- {
- CountOfResort = CountsOfResort();
- if ( CountOfResort != 0 )
- {
- fstream WorkWithFile;
- WorkWithFile.open( "ResortBook.txt" );
- string text, HelpToWrhite="";
- int LineCounter;
- while ( !WorkWithFile.eof() )
- {
- for (int i = 0; i < CountOfResort; i++)
- {
- getline ( WorkWithFile, text );
- LineCounter = 1;
- for (int j = 0; j < text.length(); j++)
- {
- if ( text[j] != ' ' )
- {
- if ( LineCounter == 1 )
- {
- HelpToWrhite += text[j];
- }
- if ( LineCounter == 2 )
- {
- HelpToWrhite += text[j];
- }
- if ( LineCounter == 3 )
- {
- HelpToWrhite += text[j];
- }
- if ( LineCounter == 4 )
- {
- HelpToWrhite += text[j];
- }
- }
- else
- {
- if ( LineCounter == 1 )
- InformationAboutResort[i].PlaceOfResort = HelpToWrhite;
- if ( LineCounter == 2 )
- InformationAboutResort[i].CityOfResort = HelpToWrhite;
- if ( LineCounter == 3 )
- InformationAboutResort[i].PriceOfResort = HelpToWrhite;
- if ( LineCounter == 4)
- InformationAboutResort[i].StayPrice = HelpToWrhite;
- HelpToWrhite = "";
- LineCounter ++;
- }
- }
- }
- }
- WorkWithFile.close();
- }
- else
- {
- cout << "В данный момент файл пуст!" << endl;
- }
- };
- void ShekerSortPlace()
- {
- Resort HelpToSort;
- CountOfResort = CountsOfResort();
- int left, right;
- left = 0;
- right = CountOfResort - 1;
- int flag = 1;
- while( ( left < right ) && flag > 0 )
- {
- flag = 0;
- for( int i = left; i < right; i++ )
- {
- if( InformationAboutResort[i].PlaceOfResort > InformationAboutResort[i+1].PlaceOfResort )
- {
- HelpToSort = InformationAboutResort[i];
- InformationAboutResort[i] = InformationAboutResort[i+1];
- InformationAboutResort[i+1] = HelpToSort;
- flag = 1;
- }
- }
- right--;
- for( int i = right; i > left; i-- )
- {
- if( InformationAboutResort[i-1].PlaceOfResort > InformationAboutResort[i].PlaceOfResort )
- {
- HelpToSort = InformationAboutResort[i];
- InformationAboutResort[i] = InformationAboutResort[i-1];
- InformationAboutResort[i-1] = HelpToSort;
- flag = 1;
- }
- }
- left++;
- }
- for (int i = 0; i < CountOfResort ; i++)
- {
- cout << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
- }
- }
- void ShekerSortCity()
- {
- Resort HelpToSort;
- CountOfResort = CountsOfResort();
- int left, right;
- left = 0;
- right = CountOfResort - 1;
- int flag = 1;
- while( ( left < right ) && flag > 0 )
- {
- flag = 0;
- for( int i = left; i < right; i++ )
- {
- if( InformationAboutResort[i].CityOfResort > InformationAboutResort[i+1].CityOfResort )
- {
- HelpToSort = InformationAboutResort[i];
- InformationAboutResort[i] = InformationAboutResort[i+1];
- InformationAboutResort[i+1] = HelpToSort;
- flag = 1;
- }
- }
- right--;
- for( int i = right; i > left; i-- )
- {
- if( InformationAboutResort[i-1].CityOfResort > InformationAboutResort[i].CityOfResort )
- {
- HelpToSort = InformationAboutResort[i];
- InformationAboutResort[i] = InformationAboutResort[i-1];
- InformationAboutResort[i-1] = HelpToSort;
- flag = 1;
- }
- }
- left++;
- }
- for (int i = 0; i < CountOfResort ; i++)
- {
- cout << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
- }
- }
- void ShekerSortPrice()
- {
- Resort HelpToSort;
- CountOfResort = CountsOfResort();
- int left, right;
- left = 0;
- right = CountOfResort - 1;
- int flag = 1;
- while( ( left < right ) && flag > 0 )
- {
- flag = 0;
- for( int i = left; i < right; i++ )
- {
- if( InformationAboutResort[i].PriceOfResort > InformationAboutResort[i+1].PriceOfResort )
- {
- HelpToSort = InformationAboutResort[i];
- InformationAboutResort[i] = InformationAboutResort[i+1];
- InformationAboutResort[i+1] = HelpToSort;
- flag = 1;
- }
- }
- right--;
- for( int i = right; i > left; i-- )
- {
- if( InformationAboutResort[i-1].PriceOfResort > InformationAboutResort[i].PriceOfResort )
- {
- HelpToSort = InformationAboutResort[i];
- InformationAboutResort[i] = InformationAboutResort[i-1];
- InformationAboutResort[i-1] = HelpToSort;
- flag = 1;
- }
- }
- left++;
- }
- for (int i = 0; i < CountOfResort ; i++)
- {
- cout << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
- }
- }
- void ShekerSortStay()
- {
- Resort HelpToSort;
- CountOfResort = CountsOfResort();
- int left, right;
- left = 0;
- right = CountOfResort - 1;
- int flag = 1;
- while( ( left < right ) && flag > 0 )
- {
- flag = 0;
- for( int i = left; i < right; i++ )
- {
- if( InformationAboutResort[i].StayPrice > InformationAboutResort[i+1].StayPrice )
- {
- HelpToSort = InformationAboutResort[i];
- InformationAboutResort[i] = InformationAboutResort[i+1];
- InformationAboutResort[i+1] = HelpToSort;
- flag = 1;
- }
- }
- right--;
- for( int i = right; i > left; i-- )
- {
- if( InformationAboutResort[i-1].StayPrice > InformationAboutResort[i].StayPrice )
- {
- HelpToSort = InformationAboutResort[i];
- InformationAboutResort[i] = InformationAboutResort[i-1];
- InformationAboutResort[i-1] = HelpToSort;
- flag = 1;
- }
- }
- left++;
- }
- for (int i = 0; i < CountOfResort ; i++)
- {
- cout << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
- }
- }
- void ChangeInformation()
- {
- fstream WorkWithFile;
- WorkWithFile.open( "ResortBook.txt", ios::out );
- int NumberOfLine = 0;
- int NumberOfRed, UserChoice;
- for (int i = 0; i < CountOfResort ; i++)
- {
- cout << NumberOfLine << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
- NumberOfLine++;
- }
- cout << "Какую строку вы хотели бы редактировать: ";
- cin >> NumberOfRed;
- cout << "Введите наименование курота: " ;
- cin >> InformationAboutResort[NumberOfRed].PlaceOfResort;
- cout << "Введите горорд: ";
- cin >> InformationAboutResort[NumberOfRed].CityOfResort;
- cout << "Введите стоимость поездки: ";
- cin >> InformationAboutResort[NumberOfRed].PriceOfResort;
- cout << "Введите стоитимость проживания: ";
- cin >> InformationAboutResort[NumberOfRed].StayPrice;
- for (int i = 0; i < CountOfResort ; i++)
- {
- cout << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
- NumberOfLine++;
- }
- cout << "Перезаписать файл? 1/0 " << endl;
- cin >> UserChoice;
- if (UserChoice = 1 )
- {
- for (int i = 0; i < CountOfResort; i++)
- {
- WorkWithFile << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << " " << endl;
- }
- cout << "Сохранено" << endl;
- }
- else
- {
- cout << "Не записано" << endl;
- }
- WorkWithFile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement