Advertisement
Guest User

Untitled

a guest
May 18th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. // AlenaKursach.cpp: главный файл проекта.
  2.  
  3. #include "stdafx.h"
  4. #include "iostream"
  5. #include "fstream"
  6. #include "string"
  7.  
  8. using namespace System;
  9. using namespace std;
  10.  
  11. struct Resort
  12. {
  13. string PlaceOfResort;
  14. string CityOfResort;
  15. int PriceOfResort;
  16. int StayPrice;
  17. };
  18.  
  19. struct Access
  20. {
  21. string login;
  22. string password;
  23. };
  24.  
  25. Resort InformationAboutResort;
  26. Access LogAndPassInfo;
  27.  
  28. int CountOfResort = 0;
  29.  
  30. int StartMenu();
  31. int UserAccess;
  32. void AddResortBook();
  33. void ReadResortBook();
  34. void SelectSort();
  35. void ClearResortBook();
  36. int LoginAndPassword();
  37. void ChangeUserAccess();
  38.  
  39.  
  40. int main(array<System::String ^> ^args)
  41. {
  42. setlocale( 0, "Rus" );
  43. if ( LoginAndPassword() == 1 )
  44. {
  45. do
  46. {
  47. } while ( StartMenu() != 2 );
  48. }
  49. else
  50. {
  51. cout << "Неверное имя польователя или пароль!";
  52. }
  53. return 0;
  54. }
  55.  
  56. int StartMenu()
  57. {
  58. int UserSelect;
  59. cout << "Добро пожаловать в справочник курортов! Что бы вы хотели сделать?" << endl;
  60. cout << "1) Добавление курорта в книгу!" << endl;
  61. cout << "2) Вывод справочника на экран." << endl;
  62. cout << "3) Вывод сортированного справочника " << endl;
  63. cout << "4) Очистить курортную книгу." << endl;
  64. cout << "5) Изменить данные входа." << endl;
  65. cout << "6) Выход из программы." << endl;
  66. cout << "Введите ваш выбор: ";
  67. cin >> UserSelect;
  68. switch ( UserSelect )
  69. {
  70. case 1:
  71. {
  72. AddResortBook();
  73. return 1;
  74. break;
  75. }
  76. case 2:
  77. {
  78. ReadResortBook();
  79. return 1;
  80. break;
  81. }
  82. case 3:
  83. {
  84. SelectSort();
  85. return 1;
  86. break;
  87. }
  88. case 4:
  89. {
  90. ClearResortBook();
  91. return 1;
  92. break;
  93. }
  94. case 5:
  95. {
  96. ChangeUserAccess();
  97. return 1;
  98. break;
  99. }
  100. case 6:
  101. {
  102. cout << "Досвидания, спасибо за использование программы!" << endl;
  103. return 2;
  104. break;
  105. }
  106. default:
  107. {
  108. cout << "Попробуйте еще раз!" << endl;
  109. StartMenu();
  110. return 1;
  111. break;
  112. }
  113. }
  114. }
  115.  
  116. void AddResortBook()
  117. {
  118. fstream WorkWithFile;
  119. WorkWithFile.open( "ResortBook.txt", ios::app );
  120. cout << " Функция добавляет курорт в список" << endl;
  121. cout << "Введите наименование курорта" << endl;
  122. cin >> InformationAboutResort.PlaceOfResort;
  123. cout << endl;
  124. cout << "Введите город курорта: ";
  125. cin >> InformationAboutResort.CityOfResort;
  126. cout << endl;
  127. cout << "Введите стоимость поездки ";
  128. cin >> InformationAboutResort.PriceOfResort;
  129. cout << endl;
  130. cout << "Введите стоимость проживания ";
  131. cin >> InformationAboutResort.StayPrice;
  132. cout << endl;
  133. WorkWithFile.write( (char*)&InformationAboutResort, sizeof( InformationAboutResort ) );
  134. cout << "Данные занесены в книгу!" << endl;
  135. WorkWithFile.close();
  136. };
  137.  
  138. void ReadResortBook()
  139. {
  140. fstream WorkWithFile;
  141. WorkWithFile.open( "ResortBook.txt", ios::in );
  142. do
  143. {
  144. WorkWithFile.read( (char*)&InformationAboutResort, sizeof( InformationAboutResort ) );
  145. if ( WorkWithFile.eof() )
  146. break;
  147. cout << InformationAboutResort.PlaceOfResort << " " << InformationAboutResort.CityOfResort << " " << InformationAboutResort.PriceOfResort << " " << InformationAboutResort.StayPrice << endl;
  148. } while ( true );
  149. WorkWithFile.close();
  150. };
  151.  
  152. void SelectSort()
  153. {
  154. cout << "a";
  155. };
  156.  
  157. void ClearResortBook()
  158. {
  159. fstream WorkWithFile;
  160. WorkWithFile.open( "ResortBook.txt", ios::out );
  161. WorkWithFile.clear();
  162. WorkWithFile.close();
  163. };
  164.  
  165. int LoginAndPassword()
  166. {
  167. fstream WorkWithFile;
  168. WorkWithFile.open( "UserAccess.txt", ios::in );
  169. WorkWithFile.read( (char*)&LogAndPassInfo, sizeof( LogAndPassInfo ) );
  170. string UserName, Password;
  171. cout << " Добро пожаловать в программу, введите имя пользователя и пароль для входа в систему! " << endl;
  172. cout << "Имя пользователя: ";
  173. cin >> UserName;
  174. cout << endl;
  175. cout << "Пароль: ";
  176. cin >> Password;
  177. if ( UserName == LogAndPassInfo.login && Password == LogAndPassInfo.password )
  178. {
  179. return 1;
  180. }
  181. else
  182. {
  183. return 2;
  184. }
  185. }
  186.  
  187. void ChangeUserAccess()
  188. {
  189. fstream WorkWithFile;
  190. WorkWithFile.open( "UserAccess.txt", ios::out );
  191. //WorkWithFile.clear();
  192. cout << "Введите новое имя пользователя: ";
  193. cin >> LogAndPassInfo.login;
  194. cout << endl;
  195. cout << "Введите новый пароль: ";
  196. cin >> LogAndPassInfo.password;
  197. cout << endl;
  198. WorkWithFile.write( (char*)&LogAndPassInfo, sizeof ( LogAndPassInfo ) );
  199. WorkWithFile.close();
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement