Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Kursach2.cpp: главный файл проекта.
- #include "stdafx.h"
- #include "iostream"
- #include "fstream"
- #include "string"
- using namespace System;
- using namespace std;
- int AskUserNameAndPass();
- int CountsOfProviders();
- int StartMenu();
- void ReadProvider();
- void AddProvidersBook();
- void PrintProvidersBook();
- void SelectSort();
- void ShellSortName();
- void ShellSortCount();
- void ShellSortAverage();
- void ShellSortMaxSpeed();
- void ClearProvidersBook();
- void ChangeInformation();
- struct Provider
- {
- string NameOfProvider;
- int CountOfTariffs;
- long long int AverageCostTariffs;
- long long int MaxSpeedOfTarrifs;
- };
- Provider InformationAboutProvider[100];
- string UserName[5] =
- {
- "Admin",
- "User",
- "Guest",
- "Ghost",
- "Killer"
- };
- int CountOfProviders = 0;
- string Password[5] =
- {
- "administrator",
- "user",
- "guest",
- "ghost",
- "killer"
- };
- int main(array<System::String ^> ^args)
- {
- setlocale ( 0, "Rus" );
- if ( AskUserNameAndPass() == 1 )
- {
- do
- {
- ReadProvider();
- } while ( StartMenu() != 2 );
- }
- return 0;
- }
- int AskUserNameAndPass()
- {
- int Flag = 0;
- char UserChoice = ' ';
- string User;
- string Pass;
- cout << "Добро пожловать, введите имя пользователя: ";
- cin >> User;
- cout << "Введите пароль: ";
- cin >> Pass;
- for (int i = 0; i < 5; i++)
- {
- if ( User == UserName[i] )
- {
- if ( Pass == Password[i] )
- {
- cout << "Вход в систему успешен, добро пожаловать, " << User << endl;
- Flag = 1;
- }
- }
- }
- if ( Flag == 0 )
- {
- cout << "Вы ввели не верные данные! Хотите попробовать еще? y/n?";
- cin >> UserChoice;
- if ( UserChoice == 'y' )
- {
- return AskUserNameAndPass();
- }
- else
- {
- cout << "Работа программы завершена.";
- return 0;
- }
- }
- else
- {
- return 1;
- }
- }
- int CountsOfProviders()
- {
- CountOfProviders = 0;
- fstream WorkWithFile;
- WorkWithFile.open( "ProvidersBook.txt", ios::in );
- string text;
- while ( !WorkWithFile.eof() )
- {
- getline( WorkWithFile, text );
- CountOfProviders++;
- }
- WorkWithFile.close();
- return CountOfProviders - 1;
- }
- 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 << "Введите ваш выбор: ";
- cin >> UserSelect;
- switch ( UserSelect )
- {
- case 1:
- {
- AddProvidersBook();
- return 1;
- break;
- }
- case 2:
- {
- PrintProvidersBook();
- return 1;
- break;
- }
- case 3:
- {
- SelectSort();
- return 1;
- break;
- }
- case 4:
- {
- ClearProvidersBook();
- return 1;
- break;
- }
- case 5:
- {
- ChangeInformation();
- return 1;
- break;
- }
- case 6:
- {
- return 2;
- }
- default:
- {
- cout << "Попробуйте еще раз!" << endl;
- StartMenu();
- return 1;
- break;
- }
- }
- };
- void ReadProvider()
- {
- CountOfProviders = CountsOfProviders();
- int Numbers = 0;
- if ( CountOfProviders != 0 )
- {
- fstream WorkWithFile;
- WorkWithFile.open( "ProvidersBook.txt" );
- string text, HelpToWright = "";
- int LineCounter;
- while ( !WorkWithFile.eof() )
- {
- for (int i = 0; i < CountOfProviders; i++)
- {
- getline ( WorkWithFile, text );
- LineCounter = 1;
- for (int j = 0; j < text.length(); j++)
- {
- if ( text[j] != ' ' )
- {
- if ( LineCounter == 1 )
- {
- HelpToWright += text[j];
- }
- if ( LineCounter == 2 )
- {
- HelpToWright += text[j];
- }
- if ( LineCounter == 3 )
- {
- HelpToWright += text[j];
- }
- if ( LineCounter == 4 )
- {
- HelpToWright += text[j];
- }
- }
- else
- {
- if ( LineCounter == 1 )
- InformationAboutProvider[i].NameOfProvider = HelpToWright;
- if ( LineCounter == 2 )
- {
- Numbers = stoi(HelpToWright);
- InformationAboutProvider[i].CountOfTariffs = Numbers;
- }
- if ( LineCounter == 3 )
- {
- Numbers = stoi(HelpToWright);
- InformationAboutProvider[i].AverageCostTariffs = Numbers;
- }
- if ( LineCounter == 4 )
- {
- Numbers = stoi(HelpToWright);
- InformationAboutProvider[i].MaxSpeedOfTarrifs = Numbers;
- }
- Numbers = 0;
- HelpToWright = "";
- LineCounter++;
- }
- }
- }
- }
- WorkWithFile.close();
- }
- else
- {
- cout << "В данный момент файл пуст!" << endl;
- }
- };
- void AddProvidersBook()
- {
- CountOfProviders = CountsOfProviders() + 1;
- ofstream WorkWIthFile;
- WorkWIthFile.open( "ProvidersBook.txt", ios::app );
- cout << "Функция добавляет провайдера в список." << endl;
- cout << "Введите наименование провайдера: ";
- cin >> InformationAboutProvider[CountOfProviders].NameOfProvider;
- cout << "Введите количество тарифов: ";
- cin >> InformationAboutProvider[CountOfProviders].CountOfTariffs;
- cout << "Введите среднюю стоимость тарифов: ";
- cin >> InformationAboutProvider[CountOfProviders].AverageCostTariffs;
- cout << "Введите максимальную скорость которую предоставляет провайдер: ";
- cin >> InformationAboutProvider[CountOfProviders].MaxSpeedOfTarrifs;
- WorkWIthFile << InformationAboutProvider[CountOfProviders].NameOfProvider << " " << InformationAboutProvider[CountOfProviders].CountOfTariffs << " " << InformationAboutProvider[CountOfProviders].AverageCostTariffs << " " << InformationAboutProvider[CountOfProviders].MaxSpeedOfTarrifs << " " << endl;
- cout << "Данные успешно занесены в книгу!" << endl;
- WorkWIthFile.close();
- };
- void PrintProvidersBook()
- {
- CountOfProviders = CountsOfProviders();
- cout << "Провайдеров в списке: " << CountOfProviders << endl;
- for (int i = 0; i < CountOfProviders; i++)
- {
- cout << InformationAboutProvider[i].NameOfProvider << " " << InformationAboutProvider[i].CountOfTariffs << " " << InformationAboutProvider[i].AverageCostTariffs << " " << InformationAboutProvider[i].MaxSpeedOfTarrifs << 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:
- {
- ShellSortName();
- break;
- }
- case 2:
- {
- ShellSortCount();
- break;
- }
- case 3:
- {
- ShellSortAverage();
- break;
- }
- case 4:
- {
- ShellSortMaxSpeed();
- break;
- }
- default:
- {
- cout << "Попробуйте еще раз!" << endl;
- SelectSort();
- break;
- }
- }
- };
- void ClearProvidersBook()
- {
- fstream WorkWithFile;
- WorkWithFile.open ( "ProvidersBook.txt", ios::out );
- WorkWithFile.clear();
- WorkWithFile.close();
- };
- void ChangeInformation()
- {
- fstream WorkWithFile;
- WorkWithFile.open( "ProvidersBook.txt", ios::out );
- int NumberOfLine = 0;
- int NumberOfRed, UserChoice;
- for (int i = 0; i < CountOfProviders ; i++)
- {
- cout << NumberOfLine << InformationAboutProvider[i].NameOfProvider << " " << InformationAboutProvider[i].CountOfTariffs << " " << InformationAboutProvider[i].AverageCostTariffs << " " << InformationAboutProvider[i].MaxSpeedOfTarrifs << endl;
- NumberOfLine++;
- }
- cout << "Какую строку вы хотели бы редактировать: ";
- cin >> NumberOfRed;
- cout << "Введите наименование провайдера: " ;
- cin >> InformationAboutProvider[NumberOfRed].NameOfProvider;
- cout << "Введите количетсво тарифов: ";
- cin >> InformationAboutProvider[NumberOfRed].CountOfTariffs;
- cout << "Введите среднюю стоимость тарифов: ";
- cin >> InformationAboutProvider[NumberOfRed].AverageCostTariffs;
- cout << "Введите максимальную скорость ";
- cin >> InformationAboutProvider[NumberOfRed].MaxSpeedOfTarrifs;
- for (int i = 0; i < CountOfProviders ; i++)
- {
- cout << NumberOfLine << InformationAboutProvider[i].NameOfProvider << " " << InformationAboutProvider[i].CountOfTariffs << " " << InformationAboutProvider[i].AverageCostTariffs << " " << InformationAboutProvider[i].MaxSpeedOfTarrifs << endl;
- NumberOfLine++;
- }
- cout << "Перезаписать файл? 1/0 " << endl;
- cin >> UserChoice;
- if (UserChoice = 1 )
- {
- for (int i = 0; i < CountOfProviders; i++)
- {
- WorkWithFile << InformationAboutProvider[CountOfProviders].NameOfProvider << " " << InformationAboutProvider[CountOfProviders].CountOfTariffs << " " << InformationAboutProvider[CountOfProviders].AverageCostTariffs << " " << InformationAboutProvider[CountOfProviders].MaxSpeedOfTarrifs << " " << endl;
- }
- cout << "Сохранено" << endl;
- }
- else
- {
- cout << "Не записано" << endl;
- }
- WorkWithFile.close();
- };
- void ShellSortName()
- {
- CountOfProviders = CountsOfProviders();
- int Step = CountOfProviders;
- while ( Step > 0 )
- {
- for (int i = 0; i < ( CountOfProviders - Step ); i++)
- {
- int j = i ;
- while ( j >= 0 && InformationAboutProvider[j].NameOfProvider > InformationAboutProvider[ j + Step ].NameOfProvider )
- {
- Provider temp = InformationAboutProvider[j];
- InformationAboutProvider[j] = InformationAboutProvider[ j + Step ];
- InformationAboutProvider[ j + Step ] = temp;
- j--;
- }
- }
- Step = Step / 2;
- }
- for (int i = 0; i < CountOfProviders; i++)
- {
- cout << InformationAboutProvider[i].NameOfProvider << " " << InformationAboutProvider[i].CountOfTariffs << " " << InformationAboutProvider[i].AverageCostTariffs << " " << InformationAboutProvider[i].MaxSpeedOfTarrifs << endl;
- }
- };
- void ShellSortCount()
- {
- CountOfProviders = CountsOfProviders();
- int Step = CountOfProviders;
- while ( Step > 0 )
- {
- for (int i = 0; i < ( CountOfProviders - Step ); i++)
- {
- int j = i ;
- while ( j >= 0 && InformationAboutProvider[j].CountOfTariffs > InformationAboutProvider[ j + Step ].CountOfTariffs)
- {
- Provider temp = InformationAboutProvider[j];
- InformationAboutProvider[j] = InformationAboutProvider[ j + Step ];
- InformationAboutProvider[ j + Step ] = temp;
- j--;
- }
- }
- Step = Step / 2;
- }
- for (int i = 0; i < CountOfProviders; i++)
- {
- cout << InformationAboutProvider[i].NameOfProvider << " " << InformationAboutProvider[i].CountOfTariffs << " " << InformationAboutProvider[i].AverageCostTariffs << " " << InformationAboutProvider[i].MaxSpeedOfTarrifs << endl;
- }
- };
- void ShellSortAverage()
- {
- CountOfProviders = CountsOfProviders();
- int Step = CountOfProviders;
- while ( Step > 0 )
- {
- for (int i = 0; i < ( CountOfProviders - Step ); i++)
- {
- int j = i ;
- while ( j >= 0 && InformationAboutProvider[j].AverageCostTariffs > InformationAboutProvider[ j + Step ].AverageCostTariffs)
- {
- Provider temp = InformationAboutProvider[j];
- InformationAboutProvider[j] = InformationAboutProvider[ j + Step ];
- InformationAboutProvider[ j + Step ] = temp;
- j--;
- }
- }
- Step = Step / 2;
- }
- for (int i = 0; i < CountOfProviders; i++)
- {
- cout << InformationAboutProvider[i].NameOfProvider << " " << InformationAboutProvider[i].CountOfTariffs << " " << InformationAboutProvider[i].AverageCostTariffs << " " << InformationAboutProvider[i].MaxSpeedOfTarrifs << endl;
- }
- };
- void ShellSortMaxSpeed()
- {
- CountOfProviders = CountsOfProviders();
- int Step = CountOfProviders;
- while ( Step > 0 )
- {
- for (int i = 0; i < ( CountOfProviders - Step ); i++)
- {
- int j = i ;
- while ( j >= 0 && InformationAboutProvider[j].MaxSpeedOfTarrifs > InformationAboutProvider[ j + Step ].MaxSpeedOfTarrifs )
- {
- Provider temp = InformationAboutProvider[j];
- InformationAboutProvider[j] = InformationAboutProvider[ j + Step ];
- InformationAboutProvider[ j + Step ] = temp;
- j--;
- }
- }
- Step = Step / 2;
- }
- for (int i = 0; i < CountOfProviders; i++)
- {
- cout << InformationAboutProvider[i].NameOfProvider << " " << InformationAboutProvider[i].CountOfTariffs << " " << InformationAboutProvider[i].AverageCostTariffs << " " << InformationAboutProvider[i].MaxSpeedOfTarrifs << endl;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement