Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- struct pojazd
- {
- char model[20];
- int rok;
- float pojemnosc;
- int id;
- pojazd *poprzedni;
- pojazd *nastepny;
- };
- void pokaz ();
- void dodaj ();
- void dodajPo();
- void dodajPrzed();
- void usun ();
- void usunPo();
- void usunPrzed();
- void edytuj();
- void zapisz();
- void fun(int sekundy);
- pojazd *glowa = NULL, *ogon, *tmp, *dodawany;
- int main()
- {
- char fileOpen[]="C:/test/dane.txt";
- char fileSave[]="C:/test/save.txt";
- FILE* odczyt;
- FILE* zapis;
- odczyt = fopen(fileOpen, "r");
- zapis = fopen(fileSave, "w");
- rewind(odczyt);
- int i = 0;
- while(!feof(odczyt))
- {
- if (glowa == NULL)
- {
- ++i;
- ogon = new pojazd;
- glowa = ogon;
- ogon->poprzedni = NULL;
- ogon->nastepny = NULL;
- ogon->id = i;
- }
- else
- {
- ++i;
- ogon->nastepny = new pojazd;
- tmp = ogon;
- ogon = ogon->nastepny;
- ogon->poprzedni = tmp;
- ogon->nastepny = NULL;
- ogon->id = i;
- }
- fscanf(odczyt, "%s%d%f", ogon->model, &ogon->rok, &ogon->pojemnosc);
- }
- int blad = 0;
- do
- {
- system("cls");
- cout << "Co chcesz zrobic ??" << endl;
- cout << "[1] - pokaz liste" << endl;
- cout << "[2] - dodaj element" << endl;
- cout << "[3] - usun element" << endl;
- cout << "[4] - edytuj element" << endl;
- cout << "[5] - zapisz" << endl;
- cout << "[6] - dodaj po elemencie" << endl;
- cout << "[7] - dodaj przed elementem" << endl;
- cout << "[8] - usun po elemencie" << endl;
- cout << "[9] - usun przed elementem" << endl;
- cout << "[0] - wyjdz" << endl;
- int wybor;
- cin >> wybor;
- if (wybor == 1)
- pokaz();
- if (wybor == 2)
- dodaj();
- if (wybor == 3)
- usun();
- if (wybor == 4)
- edytuj();
- if (wybor == 5)
- zapisz();
- if (wybor == 6)
- dodajPo();
- if (wybor == 7)
- dodajPrzed();
- if (wybor == 8)
- usunPo();
- if (wybor == 9)
- usunPrzed();
- if (wybor == 0)
- {
- cout << "D";
- for(int i = 0; i <= 30; i ++)
- {
- cout << "-";
- fun(1);
- }
- cout << "D";
- for(int i = 0; i < 3; i ++)
- {
- cout << " ~ ";
- fun(8);
- }
- cout << endl << "Taki chuj w dupe Dabrowskiej !!!" << endl;
- return 0;
- }
- } while (!blad);
- }
- void pokaz()
- {
- system("cls");
- ogon = glowa;
- int i = 0;
- while (ogon->nastepny != NULL)
- {
- i++;
- ogon->id = i;
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ID: \t" << ogon->id << endl;
- cout << "------------------------------------------------" << endl;
- cout << "MODEL\t\t\t:\t" << ogon->model << endl;
- cout << "ROK\t\t\t:\t" << ogon->rok << endl;
- cout << "POJ.\t\t\t:\t" << ogon->pojemnosc << endl;
- cout << "ADRES\t\t\t: \t0x" << ogon << endl;
- if (ogon->nastepny == NULL)
- cout << "NASTEPNY ELEMENT\t:\tBRAK" << endl;
- else
- {
- cout << "NASTEPNY ELEMENT\t:\t0x" << ogon->nastepny << endl;
- }
- if (ogon->poprzedni == NULL)
- {
- cout << "POPRZEDNI ELEMENT\t:\tBRAK" << endl;
- }
- else
- {
- cout << "POPRZEDNI ELEMENT\t:\t0x" << ogon->poprzedni << endl;
- }
- cout << "------------------------------------------------" << endl;
- cout << endl;
- ogon = ogon->nastepny;
- }
- i++;
- ogon->id = i;
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ID: \t" << ogon->id << endl;
- cout << "------------------------------------------------" << endl;
- cout << "MODEL\t\t\t:\t" << ogon->model << endl;
- cout << "ROK\t\t\t:\t" << ogon->rok << endl;
- cout << "POJ.\t\t\t:\t" << ogon->pojemnosc << endl;
- cout << "ADRES\t\t\t: \t0x" << ogon << endl;
- if (ogon->nastepny == NULL)
- cout << "NASTEPNY ELEMENT\t:\tBRAK" << endl;
- else
- {
- cout << "NASTEPNY ELEMENT\t:\t0x" << ogon->nastepny << endl;
- }
- cout << "POPRZEDNI ELEMENT\t:\t0x" << ogon->poprzedni << endl;
- cout << "------------------------------------------------" << endl;
- cout << endl;
- system("pause");
- }
- void dodaj()
- {
- system("cls");
- ogon = glowa;
- while(ogon->nastepny != NULL)
- {
- ogon = ogon->nastepny;
- }
- ogon->nastepny = new pojazd;
- tmp = ogon;
- ogon = ogon->nastepny;
- ogon->poprzedni = tmp;
- ogon->nastepny = NULL;
- ogon->id = (tmp->id + 1);
- cout << "Podaj model ->";
- cin >> ogon->model;
- cout << endl << "Podaj rok ->";
- cin >> ogon->rok;
- cout << endl << "Podaj pojemnosc ->";
- cin >> ogon->pojemnosc;
- system("cls");
- cout << "------------------------------------------------" << endl;
- cout << "(i)DODANO NOWY ELEMENT" << endl;
- cout << "------------------------------------------------" << endl;
- cout << "MODEL\t\t\t:\t" << ogon->model << endl;
- cout << "ROK\t\t\t:\t" << ogon->rok << endl;
- cout << "POJ.\t\t\t:\t" << ogon->pojemnosc << endl;
- cout << "------------------------------------------------" << endl;
- cout << "(i)PARAMETRY OBIEKTU" << endl;
- cout << "------------------------------------------------" << endl;
- cout << "ADRES\t\t\t: \t0x" << ogon << endl;
- if (ogon->nastepny == NULL)
- cout << "NASTEPNY ELEMENT\t:\tNIE ISTNIEJE" << endl;
- else
- {
- cout << "NASTEPNY ELEMENT\t:\t0x" << ogon->nastepny << endl;
- }
- cout << "POPRZEDNI ELEMENT\t:\t0x" << ogon->poprzedni << endl;
- cout << "------------------------------------------------" << endl;
- system("pause");
- }
- void dodajPo()
- {
- system("cls");
- ogon = glowa;
- int element;
- cout << "Podaj id po ktorym chcesz dodac element" << endl;
- cin >> element;
- int i = 0;
- while(ogon->nastepny != NULL && i < element)
- {
- tmp = ogon;
- ogon = ogon->nastepny;
- i++;
- }
- cout << "DODAJESZ PO ELEMENCIE O NAZWIE :" << tmp->model << endl;
- dodawany = new pojazd;
- tmp->nastepny = dodawany;
- ogon->poprzedni = dodawany;
- dodawany->poprzedni = tmp;
- dodawany->nastepny = ogon;
- cout << "Podaj nazwe : " << endl;
- cin >> dodawany->model;
- cout << "Podaj rok : " << endl;
- cin >> dodawany->rok;
- cout << "Podaj silnik : " << endl;
- cin >> dodawany->pojemnosc;
- system("cls");
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ZOSTAL DODANY POMYSLNIE " <<endl;
- cout << "------------------------------------------------" << endl;
- system("pause");
- }
- void dodajPrzed()
- {
- system("cls");
- ogon = glowa;
- int element;
- cout << "Podaj id przed ktorym chcesz dodac element" << endl;
- cin >> element;
- int i = 0;
- while(ogon->nastepny != NULL && i < element - 2)
- {
- tmp = ogon;
- ogon = ogon->nastepny;
- i++;
- }
- if (element == 1)
- {
- dodawany = new pojazd;
- cout << "Podaj nazwe : " << endl;
- cin >> dodawany->model;
- cout << "Podaj rok : " << endl;
- cin >> dodawany->rok;
- cout << "Podaj silnik : " << endl;
- cin >> dodawany->pojemnosc;
- dodawany->poprzedni = NULL;
- dodawany->nastepny = glowa;
- glowa->poprzedni = dodawany;
- glowa = dodawany;
- system("cls");
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ZOSTAL DODANY POMYSLNIE " <<endl;
- cout << "------------------------------------------------" << endl;
- system("pause");
- }
- else
- {
- cout << "DODAJESZ W MIEJSCE ELEMENTU O NAZWIE :" << ogon->model << endl;
- dodawany = new pojazd;
- dodawany->poprzedni = ogon;
- tmp = ogon;
- ogon = ogon->nastepny;
- dodawany->nastepny = ogon;
- tmp->nastepny = dodawany;
- ogon->poprzedni = dodawany;
- cout << "Podaj nazwe : " << endl;
- cin >> dodawany->model;
- cout << "Podaj rok : " << endl;
- cin >> dodawany->rok;
- cout << "Podaj silnik : " << endl;
- cin >> dodawany->pojemnosc;
- system("cls");
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ZOSTAL DODANY POMYSLNIE " <<endl;
- cout << "------------------------------------------------" << endl;
- system("pause");
- }
- }
- void usun ()
- {
- system("cls");
- ogon=glowa;
- int numer;
- cout << "------------------------------------------------" << endl;
- cout << "PODAJ NUMER SAMOCHODU DO USUNIECIA... " << endl;
- cout << "------------------------------------------------" << endl;
- cout << "->";
- cin >> numer;
- if(numer == 1)
- {
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ID: \t" << ogon->id << endl;
- cout << "------------------------------------------------" << endl;
- cout << "MODEL\t\t\t:\t" << ogon->model << endl;
- cout << "ROK\t\t\t:\t" << ogon->rok << endl;
- cout << "POJ.\t\t\t:\t" << ogon->pojemnosc << endl;
- cout << "ADRES\t\t\t: \t0x" << ogon << endl;
- if (ogon->nastepny == NULL)
- cout << "NASTEPNY ELEMENT\t:\tBRAK" << endl;
- else
- {
- cout << "NASTEPNY ELEMENT\t:\t0x" << ogon->nastepny << endl;
- }
- if (ogon->poprzedni == NULL)
- {
- cout << "POPRZEDNI ELEMENT\t:\tBRAK" << endl;
- }
- else
- {
- cout << "POPRZEDNI ELEMENT\t:\t0x" << ogon->poprzedni << endl;
- }
- cout << "------------------------------------------------" << endl;
- ogon = glowa;
- ogon = ogon->nastepny;
- free(glowa);
- glowa = ogon;
- glowa->poprzedni = NULL;
- system("cls");
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ZOSTAL USUNIETY POMYSLNIE " <<endl;
- cout << "------------------------------------------------" << endl;
- system("pause");
- }
- else
- {
- int blad = 0;
- while(ogon->nastepny != NULL)
- {
- if(ogon->id == numer)
- {
- cout << "WYBRANO ID : " << ogon->id << " MODEL : " << ogon->model << endl;
- tmp->nastepny = ogon->nastepny;
- ogon->nastepny->poprzedni = tmp;
- free(ogon);
- system("cls");
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ZOSTAL USUNIETY POMYSLNIE " <<endl;
- cout << "------------------------------------------------" << endl;
- blad = 1;
- system("pause");
- break;
- }
- else
- {
- tmp = ogon;
- ogon = ogon->nastepny;
- }
- }
- if(ogon->nastepny == NULL && numer == ogon->id)
- {
- cout << "WYBRANO ID : " << ogon->id << " MODEL : " << ogon->model << endl;
- free(ogon);
- tmp->nastepny = NULL;
- system("cls");
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ZOSTAL USUNIETY POMYSLNIE " <<endl;
- cout << "------------------------------------------------" << endl;
- blad = 1;
- system("pause");
- }
- if (ogon->id != numer && blad != 1)
- {
- cout << "PODANE ID NIE ISTNIEJE" << endl;
- system("pause");
- }
- }
- }
- void usunPo()
- {
- system("cls");
- ogon = glowa;
- int element;
- cout << "Podaj id po ktorym chcesz usunac element" << endl;
- cin >> element;
- int i = 0;
- while(ogon->nastepny != NULL && i != element)
- {
- tmp = ogon;
- ogon = ogon->nastepny;
- i++;
- }
- cout << "USUWASZ PO ELEMENCIE O NAZWIE :" << tmp->model << endl;
- tmp->nastepny = ogon->nastepny;
- ogon->nastepny->poprzedni =tmp;
- free(ogon);
- system("cls");
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ZOSTAL USUNIETY POMYSLNIE " <<endl;
- cout << "------------------------------------------------" << endl;
- system("pause");
- }
- void usunPrzed()
- {
- system("cls");
- ogon = glowa;
- int element;
- int blad = 0;
- cout << "Podaj id przed ktorym chcesz usunac element" << endl;
- cin >> element;
- int i = 0;
- while(ogon->nastepny != NULL && i < element - 2)
- {
- tmp = ogon;
- ogon = ogon->nastepny;
- i++;
- }
- if (element == 1)
- {
- system("cls");
- cout << "------------------------------------------------" << endl;
- cout << "NIE MOGE USUNAC CZEGOS CZEGO NIE MA..." <<endl;
- cout << "------------------------------------------------" << endl;
- blad = 1;
- system("pause");
- }
- if (element == 2)
- {
- system("cls");
- tmp = ogon;
- ogon = ogon->nastepny;
- glowa = ogon;
- free(tmp);
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ZOSTAL USUNIETY POMYSLNIE " <<endl;
- cout << "------------------------------------------------" << endl;
- blad = 1;
- system("pause");
- }
- if(blad != 1)
- {
- tmp->nastepny = ogon->nastepny;
- ogon->nastepny->poprzedni = tmp;
- free(ogon);
- system("cls");
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ZOSTAL USUNIETY POMYSLNIE " <<endl;
- cout << "------------------------------------------------" << endl;
- system("pause");
- }
- }
- void edytuj()
- {
- system("cls");
- ogon=glowa;
- int numer;
- cout << "------------------------------------------------" << endl;
- cout << "PODAJ ID SAMOCHODU DO EDYCJI... " << endl;
- cout << "------------------------------------------------" << endl;
- cout << "->";
- cin >> numer;
- int blad = 0;
- while(ogon->nastepny != NULL)
- {
- if(ogon->id == numer)
- {
- cout << "WYBRANO ID : " << ogon->id << " MODEL : " << ogon->model << endl;
- cout << "Podaj model samochodu : " << endl;
- cin >> ogon->model;
- cout << "Podaj rok produkcji samochodu : " << endl;
- cin >> ogon->rok;
- cout << "Podaj poj. silnika samochodu : " << endl;
- cin >> ogon->pojemnosc;
- system("cls");
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ZOSTAL EDYTOWANY POMYSLNIE " <<endl;
- cout << "------------------------------------------------" << endl;
- blad = 1;
- system("pause");
- break;
- }
- else
- {
- tmp = ogon;
- ogon = ogon->nastepny;
- }
- }
- if(ogon->nastepny == NULL && numer == ogon->id)
- {
- cout << "WYBRANO ID : " << ogon->id << " MODEL : " << ogon->model << endl;
- cout << "Podaj model samochodu : " << endl;
- cin >> ogon->model;
- cout << "Podaj rok produkcji samochodu : " << endl;
- cin >> ogon->rok;
- cout << "Podaj poj. silnika samochodu : " << endl;
- cin >> ogon->pojemnosc;
- system("cls");
- cout << "------------------------------------------------" << endl;
- cout << "ELEMENT ZOSTAL EDYTOWANY POMYSLNIE " <<endl;
- cout << "------------------------------------------------" << endl;
- blad = 1;
- system("pause");
- }
- if (ogon->id != numer && blad != 1)
- {
- cout << "PODANE ID NIE ISTNIEJE" << endl;
- system("pause");
- }
- }
- void zapisz()
- {
- char fileOpen[]="C:/test/dane.txt";
- char fileSave[]="C:/test/save.txt";
- FILE* odczyt;
- FILE* zapis;
- odczyt = fopen(fileOpen, "r");
- zapis = fopen(fileSave, "w");
- ogon = glowa;
- int i = 0;
- while (ogon->nastepny != NULL)
- {
- ++i;
- ogon->id = i;
- fprintf(zapis, "ID:\t%d\tROK:\t%d\t\SILNIK:\t%.1f\tNAZWA:\t%s\t\n", ogon->id, ogon->rok, ogon->pojemnosc, ogon->model);
- ogon = ogon->nastepny;
- }
- ++i;
- ogon->id = i;
- fprintf(zapis, "ID:\t%d\tROK:\t%d\t\SILNIK:\t%.1f\tNAZWA:\t%s\t\n", ogon->id, ogon->rok, ogon->pojemnosc, ogon->model);
- fclose(odczyt);
- fclose(zapis);
- }
- void fun(int sekundy)
- {
- clock_t endwait;
- endwait = clock () + sekundy * (CLOCKS_PER_SEC/32) ;
- while (clock() < endwait) {}
- }
Add Comment
Please, Sign In to add comment