Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. struct Pasazerowie {
  9. string nazwisko;
  10. int nr_miejsca;
  11. Pasazerowie *next;
  12. };
  13.  
  14. struct Lot {
  15. string symbol_lotu;
  16. string lotnisko_startowe;
  17. string data_lotu;
  18. int licznik = 0;
  19. Pasazerowie *head = nullptr;
  20. Lot *next;
  21. };
  22.  
  23. void Dodaj_Lot(Lot* &Head, string symbol_lotu, string lotnisko_startowe, string data_lotu);
  24. void Dodaj_Pasazera(Lot* &Wybrany, string nazwisko, int nr_miejsca);
  25. void Szukaj_Lotu(Lot* &Head, string symbol_lotu, string lotnisko_startowe, string data_lotu, string nazwisko, int nr_miejsca);
  26. void Tworzenie_Listy_Pasazerow(Lot* &Head);
  27.  
  28. int main(){/*(int argc, char *argv[]) {
  29. */
  30. const char * wejscie = "loty.txt";
  31. /*
  32. const char * wejscie;
  33.  
  34. if (argc != 3) {
  35. cout << "Nieprawidlowa liczba parametrow" << endl;
  36. return 0;
  37. }
  38. if (!strcmp(argv[1], "-i")) {
  39. wejscie = argv[2];
  40. }
  41. else {
  42. cout << "Blad parametrow" << endl;
  43. return 0;
  44. }*/
  45.  
  46. Lot *Head = nullptr;
  47. fstream odczyt;
  48. odczyt.open(wejscie);
  49. string symbol_lotu;
  50. string lotnisko_startowe;
  51. string data_lotu;
  52. string nazwisko;
  53. int nr_miejsca;
  54.  
  55. if (odczyt.good()) {
  56. while (!odczyt.eof()) {
  57. odczyt >> symbol_lotu;
  58. odczyt >> lotnisko_startowe;
  59. odczyt >> data_lotu;
  60. odczyt >> nazwisko;
  61. odczyt >> nr_miejsca;
  62. Szukaj_Lotu(Head, symbol_lotu, lotnisko_startowe, data_lotu, nazwisko, nr_miejsca);
  63. }
  64. Tworzenie_Listy_Pasazerow(Head);
  65. }
  66.  
  67. return 0;
  68. }
  69.  
  70. void Dodaj_Lot(Lot* &Head, string symbol_lotu, string lotnisko_startowe, string data_lotu) {
  71. Lot *New_Lot = new Lot;
  72.  
  73. Lot *Current;
  74. Current = Head;
  75. while (Current->next != nullptr) Current = Current->next;
  76. New_Lot->next = nullptr;
  77. New_Lot->symbol_lotu = symbol_lotu;
  78. New_Lot->lotnisko_startowe = lotnisko_startowe;
  79. New_Lot->data_lotu = data_lotu;
  80. Current->next = New_Lot;
  81. }
  82. void Dodaj_Pasazera(Lot* &Wybrany, string nazwisko, int nr_miejsca) {
  83.  
  84.  
  85. if (Wybrany->head == nullptr) {
  86. Pasazerowie *New_Pasazer = new Pasazerowie;
  87. Wybrany->head = New_Pasazer;
  88. Wybrany->head->nr_miejsca = nr_miejsca;
  89. Wybrany->head->nazwisko = nazwisko;
  90. Wybrany->head->next = nullptr;
  91. return;
  92. }
  93.  
  94. if (nr_miejsca < Wybrany->head->nr_miejsca) //sytuacja kiedy nowy pasażer ma mniejszy numer niż pierwszy na liście
  95. {
  96. Pasazerowie *New_Pasazer = new Pasazerowie;
  97. New_Pasazer->nr_miejsca = nr_miejsca;
  98. New_Pasazer->nazwisko = nazwisko;
  99. New_Pasazer->next = Wybrany->head;
  100. Wybrany->head = New_Pasazer;
  101. return;
  102. }
  103.  
  104. Pasazerowie *Current = Wybrany->head;
  105.  
  106. while (Current->next && nr_miejsca > Current->next->nr_miejsca)
  107. {
  108. Current = Current->next;
  109. }
  110.  
  111. if (!Current->next) // sytuacja kiedy wstawiamy osobę z największym numerem w tzn wstawiamy na koniec
  112. {
  113. Current->next = new Pasazerowie;
  114. Current->next->nr_miejsca = nr_miejsca;
  115. Current->next->nazwisko = nazwisko;
  116. Current->next->next = nullptr;
  117. return;
  118. }
  119.  
  120. if (nr_miejsca < Current->next->nr_miejsca)//sytuacja kiedy musimy wstawic go gdzies w srodek
  121. {
  122. Pasazerowie *New_Pasazer = new Pasazerowie;
  123. New_Pasazer->nazwisko = nazwisko;
  124. New_Pasazer->nr_miejsca = nr_miejsca;
  125. Pasazerowie* pom = Current->next;
  126. Current->next = New_Pasazer;
  127. New_Pasazer->next = pom;
  128. return;
  129.  
  130. }
  131.  
  132. }
  133.  
  134. void Szukaj_Lotu(Lot* &Head, string symbol_lotu, string lotnisko_startowe, string data_lotu, string nazwisko, int nr_miejsca) {
  135. Lot *Current;
  136. Current = Head;
  137. if (Head == nullptr) {
  138. Lot *New_Lot = new Lot;
  139. Head = New_Lot;
  140. Head->next = nullptr;
  141. Head->licznik++;
  142. Head->symbol_lotu = symbol_lotu;
  143. Head->lotnisko_startowe = lotnisko_startowe;
  144. Head->data_lotu = data_lotu;
  145. Dodaj_Pasazera(Head, nazwisko, nr_miejsca);
  146. return;
  147. }
  148. while (Current->next != nullptr) {
  149. if (Current->symbol_lotu == symbol_lotu) {
  150. Dodaj_Pasazera(Current, nazwisko, nr_miejsca);
  151. Current->licznik++;
  152. return;
  153. }
  154. Current = Current->next;
  155. }
  156. Dodaj_Lot(Head, symbol_lotu, lotnisko_startowe, data_lotu);
  157. Szukaj_Lotu(Head, symbol_lotu, lotnisko_startowe, data_lotu, nazwisko, nr_miejsca);
  158. }
  159.  
  160. void Tworzenie_Listy_Pasazerow(Lot* &Head) {
  161. Lot *Current;
  162. Current = Head;
  163.  
  164. while (Current->next != nullptr) {
  165. Pasazerowie *Current_Passazer;
  166. Current_Passazer = Current->head;
  167. fstream zapis(Current->symbol_lotu + ".txt", ios::out);
  168. zapis << "lotnisko: " << Current->lotnisko_startowe << endl << "data lotu: " << Current->data_lotu << endl << "lista pasazerow:" << endl;
  169. for (int i = 0; i < Current->licznik; i++) {
  170. zapis << Current_Passazer->nr_miejsca << " " << Current_Passazer->nazwisko << endl;
  171. Current_Passazer = Current_Passazer->next;
  172. }
  173. zapis << "liczba rezerwacji: " << Current->licznik;
  174. Current = Current->next;
  175. }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement