Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstring>
- using namespace std;
- struct Pasazerowie {
- string nazwisko;
- int nr_miejsca;
- Pasazerowie *next;
- };
- struct Lot {
- string symbol_lotu;
- string lotnisko_startowe;
- string data_lotu;
- int licznik = 0;
- Pasazerowie *head = nullptr;
- Lot *next;
- };
- void Dodaj_Lot(Lot* &Head, string symbol_lotu, string lotnisko_startowe, string data_lotu);
- void Dodaj_Pasazera(Lot* &Wybrany, string nazwisko, int nr_miejsca);
- void Szukaj_Lotu(Lot* &Head, string symbol_lotu, string lotnisko_startowe, string data_lotu, string nazwisko, int nr_miejsca);
- void Tworzenie_Listy_Pasazerow(Lot* &Head);
- int main(){/*(int argc, char *argv[]) {
- */
- const char * wejscie = "loty.txt";
- /*
- const char * wejscie;
- if (argc != 3) {
- cout << "Nieprawidlowa liczba parametrow" << endl;
- return 0;
- }
- if (!strcmp(argv[1], "-i")) {
- wejscie = argv[2];
- }
- else {
- cout << "Blad parametrow" << endl;
- return 0;
- }*/
- Lot *Head = nullptr;
- fstream odczyt;
- odczyt.open(wejscie);
- string symbol_lotu;
- string lotnisko_startowe;
- string data_lotu;
- string nazwisko;
- int nr_miejsca;
- if (odczyt.good()) {
- while (!odczyt.eof()) {
- odczyt >> symbol_lotu;
- odczyt >> lotnisko_startowe;
- odczyt >> data_lotu;
- odczyt >> nazwisko;
- odczyt >> nr_miejsca;
- Szukaj_Lotu(Head, symbol_lotu, lotnisko_startowe, data_lotu, nazwisko, nr_miejsca);
- }
- Tworzenie_Listy_Pasazerow(Head);
- }
- return 0;
- }
- void Dodaj_Lot(Lot* &Head, string symbol_lotu, string lotnisko_startowe, string data_lotu) {
- Lot *New_Lot = new Lot;
- Lot *Current;
- Current = Head;
- while (Current->next != nullptr) Current = Current->next;
- New_Lot->next = nullptr;
- New_Lot->symbol_lotu = symbol_lotu;
- New_Lot->lotnisko_startowe = lotnisko_startowe;
- New_Lot->data_lotu = data_lotu;
- Current->next = New_Lot;
- }
- void Dodaj_Pasazera(Lot* &Wybrany, string nazwisko, int nr_miejsca) {
- if (Wybrany->head == nullptr) {
- Pasazerowie *New_Pasazer = new Pasazerowie;
- Wybrany->head = New_Pasazer;
- Wybrany->head->nr_miejsca = nr_miejsca;
- Wybrany->head->nazwisko = nazwisko;
- Wybrany->head->next = nullptr;
- return;
- }
- if (nr_miejsca < Wybrany->head->nr_miejsca) //sytuacja kiedy nowy pasażer ma mniejszy numer niż pierwszy na liście
- {
- Pasazerowie *New_Pasazer = new Pasazerowie;
- New_Pasazer->nr_miejsca = nr_miejsca;
- New_Pasazer->nazwisko = nazwisko;
- New_Pasazer->next = Wybrany->head;
- Wybrany->head = New_Pasazer;
- return;
- }
- Pasazerowie *Current = Wybrany->head;
- while (Current->next && nr_miejsca > Current->next->nr_miejsca)
- {
- Current = Current->next;
- }
- if (!Current->next) // sytuacja kiedy wstawiamy osobę z największym numerem w tzn wstawiamy na koniec
- {
- Current->next = new Pasazerowie;
- Current->next->nr_miejsca = nr_miejsca;
- Current->next->nazwisko = nazwisko;
- Current->next->next = nullptr;
- return;
- }
- if (nr_miejsca < Current->next->nr_miejsca)//sytuacja kiedy musimy wstawic go gdzies w srodek
- {
- Pasazerowie *New_Pasazer = new Pasazerowie;
- New_Pasazer->nazwisko = nazwisko;
- New_Pasazer->nr_miejsca = nr_miejsca;
- Pasazerowie* pom = Current->next;
- Current->next = New_Pasazer;
- New_Pasazer->next = pom;
- return;
- }
- }
- void Szukaj_Lotu(Lot* &Head, string symbol_lotu, string lotnisko_startowe, string data_lotu, string nazwisko, int nr_miejsca) {
- Lot *Current;
- Current = Head;
- if (Head == nullptr) {
- Lot *New_Lot = new Lot;
- Head = New_Lot;
- Head->next = nullptr;
- Head->licznik++;
- Head->symbol_lotu = symbol_lotu;
- Head->lotnisko_startowe = lotnisko_startowe;
- Head->data_lotu = data_lotu;
- Dodaj_Pasazera(Head, nazwisko, nr_miejsca);
- return;
- }
- while (Current->next != nullptr) {
- if (Current->symbol_lotu == symbol_lotu) {
- Dodaj_Pasazera(Current, nazwisko, nr_miejsca);
- Current->licznik++;
- return;
- }
- Current = Current->next;
- }
- Dodaj_Lot(Head, symbol_lotu, lotnisko_startowe, data_lotu);
- Szukaj_Lotu(Head, symbol_lotu, lotnisko_startowe, data_lotu, nazwisko, nr_miejsca);
- }
- void Tworzenie_Listy_Pasazerow(Lot* &Head) {
- Lot *Current;
- Current = Head;
- while (Current->next != nullptr) {
- Pasazerowie *Current_Passazer;
- Current_Passazer = Current->head;
- fstream zapis(Current->symbol_lotu + ".txt", ios::out);
- zapis << "lotnisko: " << Current->lotnisko_startowe << endl << "data lotu: " << Current->data_lotu << endl << "lista pasazerow:" << endl;
- for (int i = 0; i < Current->licznik; i++) {
- zapis << Current_Passazer->nr_miejsca << " " << Current_Passazer->nazwisko << endl;
- Current_Passazer = Current_Passazer->next;
- }
- zapis << "liczba rezerwacji: " << Current->licznik;
- Current = Current->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement