Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <string>
- #include <cstring>
- using namespace std;
- string linia;
- fstream plik;
- struct rezer {
- string lot;
- string city;
- string date;
- string name;
- int seat;
- rezer* next; // wskaznik na nastêpny element
- rezer(); // konstruktor
- };
- // konstruktor:
- rezer::rezer() {
- next = 0;
- }
- struct list {
- rezer* first; // wskaznik na pocz¹tek listy
- void show();
- void add(string lot, string city, string date, string name, int seat);
- void del(int nr);
- list();
- };
- // konstruktor:
- list::list() {
- first = 0;
- }
- void list::add(string lot, string city, string date, string name, int seat)
- {
- rezer* nowa = new rezer; // tworzy nowy element listy
- nowa->lot = lot;
- nowa->city = city;
- nowa->date = date;
- nowa->name = name;
- nowa->seat = seat;
- if (first == 0) // sprawdzamy czy to pierwszy element listy
- {
- // je¿eli tak to nowy element jest teraz pocz¹tkiem listy
- first = nowa;
- }
- else
- {
- // w przeciwnym wypadku wêdrujemy na koniec listy
- rezer* temp = first;
- while (temp->next)
- {
- // znajdujemy wskaŸnik na ostatni element
- temp = temp->next;
- }
- temp->next = nowa; // ostatni element wskazuje na nasz nowy
- nowa->next = 0; // ostatni nie wskazuje na nic
- }
- }
- void list::show()
- {
- // wskaznik na pierszy element listy
- rezer* temp = first;
- // przewijamy wskazniki na nastepne elementy
- while (temp)
- {
- cout << "\n" << "Nr lotu: " << temp->lot << endl;
- cout << "Miasto: " << temp->city << endl;
- cout << "Data: " << temp->date << endl;
- cout << "Imie pasazera: " << temp->name << endl;
- cout << "Nr miejsca: " << temp->seat << "\n" << endl;
- temp = temp->next;
- }
- }
- int main() {
- string wybor = "1";
- string corobimy;
- list* moja_lista = new list;
- string nr_lotu;
- string miasto;
- string data;
- string imie;
- int miejsce;
- do
- {
- cout << "Jesli chcesz dodac kolejny rekord, wybierz 1." << endl;
- cout << "Jesli chcesz wyswietlic cala liste, wybierz 2." << endl;
- cout << "Jesli chcesz wyjsc, wybierz 0." << "\n" << endl;
- cin >> corobimy;
- if (corobimy == "1")
- {
- cout << "Podaj nr lotu:" << endl;
- cin >> nr_lotu;
- cout << "Podaj nazwe miasta:" << endl;
- cin >> miasto;
- cout << "Podaj date:" << endl;
- cin >> data;
- cout << "Podaj imie:" << endl;
- cin >> imie;
- cout << "Podaj nr miejsca:" << endl;
- cin >> miejsce;
- cout << "\n" << "Zapisano dane." << "\n" << endl;
- moja_lista->list::add(nr_lotu, miasto, data, imie, miejsce);
- /*
- fstream uchwyt; //obiekt typu fstream (uchwyt do pliku)
- uchwyt.open("rezerwacje.txt"); //otwieramy plik: plik.txt (plik - nazwa pliku, txt - rozszerzenie)
- string linia;
- do
- {
- getline(uchwyt, linia); //pobierz linijkę
- cout << linia << endl; //wypisz na ekranie
- char slowo;
- char delim[] = " ";
- slowo = strtok(linia, delim);
- while (slowo)
- {
- cout << slowo << endl;
- slowo = strtok(NULL, delim);
- }
- }
- 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ą
- uchwyt.close(); //zamykamy plik
- */
- /*
- FILE * file;
- file = fopen("rezerwacje.txt", "r");
- const int ile_elem = 1000;
- char bufor[ile_elem];
- char *slowo;
- char delim[] = " ";
- char *odczyt = fread(bufor, sizeof(char), ile_elem, file);
- slowo = strtok(odczyt, delim);
- while (slowo)
- {
- cout << slowo << endl;
- slowo = strtok(NULL, delim);
- }
- */
- wybor = "1";
- }
- else if (corobimy == "2")
- {
- moja_lista->list::show();
- wybor = "1";
- }
- else if (corobimy == "0")
- {
- cout << "Koniec." << endl;
- wybor = "0";
- }
- } while (wybor != "0");
- /*
- rezer jeden[9]; // tablica ze struktury
- int j = 0;
- int i = 1;
- for (int k = 0; k < 9; k++) {
- if (i == 1) {
- cout << "Podaj imie ucznia numer " << endl;
- cin >> jeden[j].lot;
- cin >> jeden[j].city;
- cin >> jeden[j].date;
- cin >> jeden[j].name;
- cin >> jeden[j].seat;
- cin >> i;
- j++;
- }
- else
- k = 9;
- }
- j--;
- for (int k = 0; k < 9; k++)
- {
- cout << jeden[j].name << endl;
- k++;
- }
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement