Advertisement
Guest User

DlaKuby.ver.2

a guest
Jan 19th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <string>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. string linia;
  10. fstream plik;
  11.  
  12. struct rezer {
  13.     string lot;
  14.     string city;
  15.     string date;
  16.     string name;
  17.     int seat;
  18.     rezer* next; // wskaznik na nastêpny element
  19.     rezer(); // konstruktor
  20. };
  21.  
  22.  
  23. // konstruktor:
  24. rezer::rezer() {
  25.     next = 0;
  26. }
  27.  
  28. struct list {
  29.     rezer* first; // wskaznik na pocz¹tek listy
  30.     void show();
  31.     void add(string lot, string city, string date, string name, int seat);
  32.     void del(int nr);
  33.     list();
  34. };
  35.  
  36.  
  37. // konstruktor:
  38. list::list() {
  39.     first = 0;
  40. }
  41.  
  42. void list::add(string lot, string city, string date, string name, int seat)
  43. {
  44.     rezer* nowa = new rezer;    // tworzy nowy element listy
  45.  
  46.     nowa->lot = lot;
  47.     nowa->city = city;
  48.     nowa->date = date;
  49.     nowa->name = name;
  50.     nowa->seat = seat;
  51.  
  52.     if (first == 0) // sprawdzamy czy to pierwszy element listy
  53.     {
  54.         // je¿eli tak to nowy element jest teraz pocz¹tkiem listy
  55.         first = nowa;
  56.     }
  57.     else
  58.     {
  59.         // w przeciwnym wypadku wêdrujemy na koniec listy
  60.         rezer* temp = first;
  61.  
  62.         while (temp->next)
  63.         {
  64.             // znajdujemy wskaŸnik na ostatni element
  65.             temp = temp->next;
  66.         }
  67.  
  68.         temp->next = nowa;  // ostatni element wskazuje na nasz nowy
  69.         nowa->next = 0;  // ostatni nie wskazuje na nic
  70.     }
  71. }
  72.  
  73.  
  74. void list::show()
  75. {
  76.     // wskaznik na pierszy element listy
  77.     rezer* temp = first;
  78.  
  79.     // przewijamy wskazniki na nastepne elementy
  80.     while (temp)
  81.     {
  82.         cout << "\n" << "Nr lotu: " << temp->lot << endl;
  83.         cout << "Miasto: " << temp->city << endl;
  84.         cout << "Data: " << temp->date << endl;
  85.         cout << "Imie pasazera: " << temp->name << endl;
  86.         cout << "Nr miejsca: " << temp->seat << "\n" << endl;
  87.         temp = temp->next;
  88.     }
  89. }
  90.  
  91. int main() {
  92.  
  93.     string wybor = "1";
  94.     string corobimy;
  95.     list* moja_lista = new list;
  96.  
  97.     string nr_lotu;
  98.     string miasto;
  99.     string data;
  100.     string imie;
  101.     int miejsce;
  102.  
  103.     do
  104.     {
  105.         cout << "Jesli chcesz dodac kolejny rekord, wybierz 1." << endl;
  106.         cout << "Jesli chcesz wyswietlic cala liste, wybierz 2." << endl;
  107.         cout << "Jesli chcesz wyjsc, wybierz 0." << "\n" << endl;
  108.         cin >> corobimy;
  109.  
  110.         if (corobimy == "1")
  111.         {
  112.             cout << "Podaj nr lotu:" << endl;
  113.             cin >> nr_lotu;
  114.             cout << "Podaj nazwe miasta:" << endl;
  115.             cin >> miasto;
  116.             cout << "Podaj date:" << endl;
  117.             cin >> data;
  118.             cout << "Podaj imie:" << endl;
  119.             cin >> imie;
  120.             cout << "Podaj nr miejsca:" << endl;
  121.             cin >> miejsce;
  122.             cout << "\n" << "Zapisano dane." << "\n" << endl;
  123.             moja_lista->list::add(nr_lotu, miasto, data, imie, miejsce);
  124.  
  125.             /*
  126.             fstream uchwyt; //obiekt typu fstream (uchwyt do pliku)
  127.             uchwyt.open("rezerwacje.txt"); //otwieramy plik: plik.txt (plik - nazwa pliku, txt - rozszerzenie)
  128.             string linia;
  129.             do
  130.             {
  131.                 getline(uchwyt, linia); //pobierz linijkę
  132.                 cout << linia << endl; //wypisz na ekranie
  133.                 char slowo;
  134.                 char delim[] = " ";
  135.                 slowo = strtok(linia, delim);
  136.                 while (slowo)
  137.                 {
  138.                     cout << slowo << endl;
  139.                     slowo = strtok(NULL, delim);
  140.                 }
  141.             }
  142.             while(linia != ""); //przerwij jeżeli linia będzie pusta (dane w pliku się skończą) UWAGA: Pamiętaj, żeby w pliku zostawić ostatnią linijkę pustą
  143.  
  144.             uchwyt.close(); //zamykamy plik
  145.             */
  146.             /*
  147.             FILE * file;
  148.             file = fopen("rezerwacje.txt", "r");
  149.             const int ile_elem = 1000;
  150.             char bufor[ile_elem];
  151.             char *slowo;
  152.             char delim[] = " ";
  153.             char *odczyt = fread(bufor, sizeof(char), ile_elem, file);
  154.             slowo = strtok(odczyt, delim);
  155.             while (slowo)
  156.             {
  157.                 cout << slowo << endl;
  158.                 slowo = strtok(NULL, delim);
  159.             }
  160.             */
  161.             wybor = "1";
  162.  
  163.         }
  164.  
  165.         else if (corobimy == "2")
  166.         {
  167.             moja_lista->list::show();
  168.             wybor = "1";
  169.         }
  170.  
  171.         else if (corobimy == "0")
  172.         {
  173.             cout << "Koniec." << endl;
  174.             wybor = "0";
  175.         }
  176.  
  177.     } while (wybor != "0");
  178.  
  179.  
  180.  
  181.     /*
  182.         rezer jeden[9]; // tablica ze struktury
  183.         int j = 0;
  184.         int i = 1;
  185.  
  186.         for (int k = 0; k < 9; k++) {
  187.             if (i == 1) {
  188.                 cout << "Podaj imie ucznia numer " << endl;
  189.                 cin >> jeden[j].lot;
  190.                 cin >> jeden[j].city;
  191.                 cin >> jeden[j].date;
  192.                 cin >> jeden[j].name;
  193.                 cin >> jeden[j].seat;
  194.                 cin >> i;
  195.                 j++;
  196.             }
  197.             else
  198.                 k = 9;
  199.         }
  200.  
  201.         j--;
  202.         for (int k = 0; k < 9; k++)
  203.         {
  204.             cout << jeden[j].name << endl;
  205.             k++;
  206.         }
  207.     */
  208.  
  209.     return 0;
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement