Advertisement
Guest User

Untitled

a guest
May 19th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.96 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. string PriceOfResort;
  16. string StayPrice;
  17. };
  18.  
  19. struct Access
  20. {
  21. string login;
  22. string password;
  23. };
  24.  
  25. Resort InformationAboutResort[100];
  26. Access LogAndPassInfo;
  27.  
  28. int StartMenu();
  29. void ReadResort();
  30. void AddResortBook();
  31. void ReadResortBook();
  32. void SelectSort();
  33. void ClearResortBook();
  34. int LoginAndPassword();
  35. void ChangeUserAccess();
  36. int CountsOfResort();
  37. void ShekerSortPlace();
  38. void ShekerSortCity();
  39. void ShekerSortPrice();
  40. void ShekerSortStay();
  41. void ChangeInformation();
  42.  
  43. int CountOfResort = 0;
  44.  
  45. int main(array<System::String ^> ^args)
  46. {
  47. setlocale( 0, "Rus" );
  48. if ( LoginAndPassword() == 1 )
  49. {
  50. do
  51. {
  52. ReadResort();
  53. } while ( StartMenu() != 2 );
  54. }
  55. else
  56. {
  57. cout << "Неверное имя польователя или пароль!";
  58. }
  59. return 0;
  60. }
  61.  
  62. int StartMenu()
  63. {
  64. int UserSelect;
  65. cout << "Добро пожаловать в справочник курортов! Что бы вы хотели сделать?" << endl;
  66. cout << "1) Добавление курорта в книгу." << endl;
  67. cout << "2) Вывод справочника на экран." << endl;
  68. cout << "3) Вывод сортированного справочника " << endl;
  69. cout << "4) Очистить курортную книгу." << endl;
  70. cout << "5) Изменить данные входа." << endl;
  71. cout << "6) Изменить данные." << endl;
  72. cout << "7) Выход из программы." << endl;
  73. cout << "Введите ваш выбор: ";
  74. cin >> UserSelect;
  75. switch ( UserSelect )
  76. {
  77. case 1:
  78. {
  79. AddResortBook();
  80. return 1;
  81. break;
  82. }
  83. case 2:
  84. {
  85. ReadResortBook();
  86. return 1;
  87. break;
  88. }
  89. case 3:
  90. {
  91. SelectSort();
  92. return 1;
  93. break;
  94. }
  95. case 4:
  96. {
  97. ClearResortBook();
  98. return 1;
  99. break;
  100. }
  101. case 5:
  102. {
  103. ChangeUserAccess();
  104. return 1;
  105. break;
  106. }
  107. case 6:
  108. {
  109. ChangeInformation();
  110. return 1;
  111. }
  112. case 7:
  113. {
  114. cout << "Досвидания, спасибо за использование программы!" << endl;
  115. return 2;
  116. break;
  117. }
  118. default:
  119. {
  120. cout << "Попробуйте еще раз!" << endl;
  121. StartMenu();
  122. return 1;
  123. break;
  124. }
  125. }
  126. }
  127.  
  128. void AddResortBook()
  129. {
  130. CountOfResort = CountsOfResort() + 1;
  131. ofstream WorkWithFile;
  132. WorkWithFile.open( "ResortBook.txt", ios::app );
  133. cout << " Функция добавляет курорт в список" << endl;
  134. cout << "Введите наименование курорта:";
  135. cin >> InformationAboutResort[CountOfResort].PlaceOfResort;
  136. cout << endl;
  137. cout << "Введите город курорта: ";
  138. cin >> InformationAboutResort[CountOfResort].CityOfResort;
  139. cout << endl;
  140. cout << "Введите стоимость поездки ";
  141. cin >> InformationAboutResort[CountOfResort].PriceOfResort;
  142. cout << endl;
  143. cout << "Введите стоимость проживания ";
  144. cin >> InformationAboutResort[CountOfResort].StayPrice;
  145. cout << endl;
  146. WorkWithFile << InformationAboutResort[CountOfResort].PlaceOfResort << " " << InformationAboutResort[CountOfResort].CityOfResort << " " << InformationAboutResort[CountOfResort].PriceOfResort << " " << InformationAboutResort[CountOfResort].StayPrice << " " << endl;
  147. cout << "Данные занесены в книгу!" << endl;
  148. WorkWithFile.close();
  149. };
  150.  
  151. void ReadResortBook()
  152. {
  153. CountOfResort = CountsOfResort();
  154. cout << "Курортов в списке: " << CountOfResort << endl;
  155. for (int i = 0; i < CountOfResort ; i++)
  156. {
  157. cout << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
  158. }
  159. };
  160.  
  161. void SelectSort()
  162. {
  163. int MetodOfSort;
  164. cout << "По какому параметру произвести сортировку? " << endl;
  165. cout << "1) Наименование курорта." << endl;
  166. cout << "2) Город курорта." << endl;
  167. cout << "3) Стоимость поездки." << endl;
  168. cout << "4) Стоимость проживания." << endl;
  169. cout << "Ваш выбор: ";
  170. cin >> MetodOfSort;
  171. cout << endl;
  172. switch ( MetodOfSort )
  173. {
  174. case 1:
  175. {
  176. ShekerSortPlace();
  177. break;
  178. }
  179. case 2:
  180. {
  181. ShekerSortCity();
  182. break;
  183. }
  184. case 3:
  185. {
  186. ShekerSortPrice();
  187. break;
  188. }
  189. case 4:
  190. {
  191. ShekerSortStay();
  192. break;
  193. }
  194. default:
  195. {
  196. cout << "Попробуйте еще раз!" << endl;
  197. SelectSort();
  198. break;
  199. }
  200. }
  201. };
  202.  
  203. void ClearResortBook()
  204. {
  205. fstream WorkWithFile;
  206. WorkWithFile.open( "ResortBook.txt", ios::out );
  207. WorkWithFile.clear();
  208. WorkWithFile.close();
  209. };
  210.  
  211. int LoginAndPassword()
  212. {
  213. fstream WorkWithFile;
  214. WorkWithFile.open( "UserAccess.txt", ios::in );
  215. WorkWithFile.read( (char*)&LogAndPassInfo, sizeof( LogAndPassInfo ) );
  216. string UserName, Password;
  217. cout << " Добро пожаловать в программу, введите имя пользователя и пароль для входа в систему! " << endl;
  218. cout << "Имя пользователя: ";
  219. cin >> UserName;
  220. cout << endl;
  221. cout << "Пароль: ";
  222. cin >> Password;
  223. if ( UserName == LogAndPassInfo.login && Password == LogAndPassInfo.password )
  224. {
  225. return 1;
  226. }
  227. else
  228. {
  229. return 2;
  230. }
  231. }
  232.  
  233. void ChangeUserAccess()
  234. {
  235. fstream WorkWithFile;
  236. WorkWithFile.open( "UserAccess.txt", ios::out );
  237. WorkWithFile.clear();
  238. cout << "Введите новое имя пользователя: ";
  239. cin >> LogAndPassInfo.login;
  240. cout << endl;
  241. cout << "Введите новый пароль: ";
  242. cin >> LogAndPassInfo.password;
  243. cout << endl;
  244. WorkWithFile.write( (char*)&LogAndPassInfo, sizeof ( LogAndPassInfo ) );
  245. WorkWithFile.close();
  246. }
  247.  
  248. int CountsOfResort()
  249. {
  250. CountOfResort = 0;
  251. fstream WorkWithFile;
  252. WorkWithFile.open( "ResortBook.txt", ios::in );
  253. string text;
  254. while ( !WorkWithFile.eof() )
  255. {
  256. getline ( WorkWithFile, text);
  257. CountOfResort++;
  258. }
  259. WorkWithFile.close();
  260. return CountOfResort - 1;
  261. };
  262.  
  263. void ReadResort()
  264. {
  265. CountOfResort = CountsOfResort();
  266. if ( CountOfResort != 0 )
  267. {
  268. fstream WorkWithFile;
  269. WorkWithFile.open( "ResortBook.txt" );
  270. string text, HelpToWrhite="";
  271. int LineCounter;
  272. while ( !WorkWithFile.eof() )
  273. {
  274. for (int i = 0; i < CountOfResort; i++)
  275. {
  276. getline ( WorkWithFile, text );
  277. LineCounter = 1;
  278. for (int j = 0; j < text.length(); j++)
  279. {
  280. if ( text[j] != ' ' )
  281. {
  282. if ( LineCounter == 1 )
  283. {
  284. HelpToWrhite += text[j];
  285. }
  286.  
  287. if ( LineCounter == 2 )
  288. {
  289. HelpToWrhite += text[j];
  290. }
  291.  
  292. if ( LineCounter == 3 )
  293. {
  294. HelpToWrhite += text[j];
  295. }
  296.  
  297. if ( LineCounter == 4 )
  298. {
  299. HelpToWrhite += text[j];
  300. }
  301. }
  302. else
  303. {
  304. if ( LineCounter == 1 )
  305. InformationAboutResort[i].PlaceOfResort = HelpToWrhite;
  306.  
  307. if ( LineCounter == 2 )
  308. InformationAboutResort[i].CityOfResort = HelpToWrhite;
  309.  
  310. if ( LineCounter == 3 )
  311. InformationAboutResort[i].PriceOfResort = HelpToWrhite;
  312.  
  313. if ( LineCounter == 4)
  314. InformationAboutResort[i].StayPrice = HelpToWrhite;
  315.  
  316. HelpToWrhite = "";
  317. LineCounter ++;
  318. }
  319. }
  320. }
  321. }
  322. WorkWithFile.close();
  323. }
  324. else
  325. {
  326. cout << "В данный момент файл пуст!" << endl;
  327. }
  328. };
  329.  
  330. void ShekerSortPlace()
  331. {
  332. Resort HelpToSort;
  333. CountOfResort = CountsOfResort();
  334. int left, right;
  335. left = 0;
  336. right = CountOfResort - 1;
  337. int flag = 1;
  338. while( ( left < right ) && flag > 0 )
  339. {
  340. flag = 0;
  341. for( int i = left; i < right; i++ )
  342. {
  343. if( InformationAboutResort[i].PlaceOfResort > InformationAboutResort[i+1].PlaceOfResort )
  344. {
  345. HelpToSort = InformationAboutResort[i];
  346. InformationAboutResort[i] = InformationAboutResort[i+1];
  347. InformationAboutResort[i+1] = HelpToSort;
  348. flag = 1;
  349. }
  350. }
  351. right--;
  352. for( int i = right; i > left; i-- )
  353. {
  354. if( InformationAboutResort[i-1].PlaceOfResort > InformationAboutResort[i].PlaceOfResort )
  355. {
  356. HelpToSort = InformationAboutResort[i];
  357. InformationAboutResort[i] = InformationAboutResort[i-1];
  358. InformationAboutResort[i-1] = HelpToSort;
  359. flag = 1;
  360. }
  361. }
  362. left++;
  363. }
  364. for (int i = 0; i < CountOfResort ; i++)
  365. {
  366. cout << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
  367. }
  368. }
  369.  
  370. void ShekerSortCity()
  371. {
  372. Resort HelpToSort;
  373. CountOfResort = CountsOfResort();
  374. int left, right;
  375. left = 0;
  376. right = CountOfResort - 1;
  377. int flag = 1;
  378. while( ( left < right ) && flag > 0 )
  379. {
  380. flag = 0;
  381. for( int i = left; i < right; i++ )
  382. {
  383. if( InformationAboutResort[i].CityOfResort > InformationAboutResort[i+1].CityOfResort )
  384. {
  385. HelpToSort = InformationAboutResort[i];
  386. InformationAboutResort[i] = InformationAboutResort[i+1];
  387. InformationAboutResort[i+1] = HelpToSort;
  388. flag = 1;
  389. }
  390. }
  391. right--;
  392. for( int i = right; i > left; i-- )
  393. {
  394. if( InformationAboutResort[i-1].CityOfResort > InformationAboutResort[i].CityOfResort )
  395. {
  396. HelpToSort = InformationAboutResort[i];
  397. InformationAboutResort[i] = InformationAboutResort[i-1];
  398. InformationAboutResort[i-1] = HelpToSort;
  399. flag = 1;
  400. }
  401. }
  402. left++;
  403. }
  404. for (int i = 0; i < CountOfResort ; i++)
  405. {
  406. cout << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
  407. }
  408. }
  409.  
  410. void ShekerSortPrice()
  411. {
  412. Resort HelpToSort;
  413. CountOfResort = CountsOfResort();
  414. int left, right;
  415. left = 0;
  416. right = CountOfResort - 1;
  417. int flag = 1;
  418. while( ( left < right ) && flag > 0 )
  419. {
  420. flag = 0;
  421. for( int i = left; i < right; i++ )
  422. {
  423. if( InformationAboutResort[i].PriceOfResort > InformationAboutResort[i+1].PriceOfResort )
  424. {
  425. HelpToSort = InformationAboutResort[i];
  426. InformationAboutResort[i] = InformationAboutResort[i+1];
  427. InformationAboutResort[i+1] = HelpToSort;
  428. flag = 1;
  429. }
  430. }
  431. right--;
  432. for( int i = right; i > left; i-- )
  433. {
  434. if( InformationAboutResort[i-1].PriceOfResort > InformationAboutResort[i].PriceOfResort )
  435. {
  436. HelpToSort = InformationAboutResort[i];
  437. InformationAboutResort[i] = InformationAboutResort[i-1];
  438. InformationAboutResort[i-1] = HelpToSort;
  439. flag = 1;
  440. }
  441. }
  442. left++;
  443. }
  444. for (int i = 0; i < CountOfResort ; i++)
  445. {
  446. cout << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
  447. }
  448. }
  449.  
  450. void ShekerSortStay()
  451. {
  452. Resort HelpToSort;
  453. CountOfResort = CountsOfResort();
  454. int left, right;
  455. left = 0;
  456. right = CountOfResort - 1;
  457. int flag = 1;
  458. while( ( left < right ) && flag > 0 )
  459. {
  460. flag = 0;
  461. for( int i = left; i < right; i++ )
  462. {
  463. if( InformationAboutResort[i].StayPrice > InformationAboutResort[i+1].StayPrice )
  464. {
  465. HelpToSort = InformationAboutResort[i];
  466. InformationAboutResort[i] = InformationAboutResort[i+1];
  467. InformationAboutResort[i+1] = HelpToSort;
  468. flag = 1;
  469. }
  470. }
  471. right--;
  472. for( int i = right; i > left; i-- )
  473. {
  474. if( InformationAboutResort[i-1].StayPrice > InformationAboutResort[i].StayPrice )
  475. {
  476. HelpToSort = InformationAboutResort[i];
  477. InformationAboutResort[i] = InformationAboutResort[i-1];
  478. InformationAboutResort[i-1] = HelpToSort;
  479. flag = 1;
  480. }
  481. }
  482. left++;
  483. }
  484. for (int i = 0; i < CountOfResort ; i++)
  485. {
  486. cout << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
  487. }
  488. }
  489.  
  490. void ChangeInformation()
  491. {
  492. fstream WorkWithFile;
  493. WorkWithFile.open( "ResortBook.txt", ios::out );
  494. int NumberOfLine = 0;
  495. int NumberOfRed, UserChoice;
  496. for (int i = 0; i < CountOfResort ; i++)
  497. {
  498. cout << NumberOfLine << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
  499. NumberOfLine++;
  500. }
  501. cout << "Какую строку вы хотели бы редактировать: ";
  502. cin >> NumberOfRed;
  503. cout << "Введите наименование курота: " ;
  504. cin >> InformationAboutResort[NumberOfRed].PlaceOfResort;
  505. cout << "Введите горорд: ";
  506. cin >> InformationAboutResort[NumberOfRed].CityOfResort;
  507. cout << "Введите стоимость поездки: ";
  508. cin >> InformationAboutResort[NumberOfRed].PriceOfResort;
  509. cout << "Введите стоитимость проживания: ";
  510. cin >> InformationAboutResort[NumberOfRed].StayPrice;
  511. for (int i = 0; i < CountOfResort ; i++)
  512. {
  513. cout << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << endl;
  514. NumberOfLine++;
  515. }
  516. cout << "Перезаписать файл? 1/0 " << endl;
  517. cin >> UserChoice;
  518. if (UserChoice = 1 )
  519. {
  520. for (int i = 0; i < CountOfResort; i++)
  521. {
  522. WorkWithFile << InformationAboutResort[i].PlaceOfResort << " " << InformationAboutResort[i].CityOfResort << " " << InformationAboutResort[i].PriceOfResort << " " << InformationAboutResort[i].StayPrice << " " << endl;
  523. }
  524. cout << "Сохранено" << endl;
  525. }
  526. else
  527. {
  528. cout << "Не записано" << endl;
  529. }
  530. WorkWithFile.close();
  531. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement