Guest User

Untitled

a guest
Jul 16th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.42 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. struct pojazd
  8. {
  9.     char model[20];
  10.     int rok;
  11.     float pojemnosc;
  12.     int id;
  13.     pojazd *poprzedni;
  14.     pojazd *nastepny;
  15. };
  16.  
  17. void pokaz ();
  18. void dodaj ();
  19. void dodajPo();
  20. void dodajPrzed();
  21. void usun  ();
  22. void usunPo();
  23. void usunPrzed();
  24. void edytuj();
  25. void zapisz();
  26. void fun(int sekundy);
  27.  
  28. pojazd *glowa = NULL, *ogon, *tmp, *dodawany;
  29.  
  30. int main()
  31. {
  32.     char fileOpen[]="C:/test/dane.txt";
  33.     char fileSave[]="C:/test/save.txt";
  34.     FILE* odczyt;
  35.     FILE* zapis;
  36.     odczyt = fopen(fileOpen, "r");
  37.     zapis = fopen(fileSave, "w");
  38.  
  39.     rewind(odczyt);
  40.  
  41.    
  42.  
  43.     int i = 0;
  44.     while(!feof(odczyt))
  45.     {
  46.  
  47.     if (glowa == NULL)
  48.     {
  49.         ++i;
  50.         ogon = new pojazd;
  51.         glowa = ogon;
  52.         ogon->poprzedni = NULL;
  53.         ogon->nastepny = NULL;
  54.         ogon->id = i;
  55.     }
  56.     else
  57.     {
  58.         ++i;
  59.         ogon->nastepny = new pojazd;
  60.         tmp = ogon;
  61.         ogon = ogon->nastepny;
  62.         ogon->poprzedni = tmp;
  63.         ogon->nastepny = NULL;
  64.         ogon->id = i;
  65.     }
  66.     fscanf(odczyt, "%s%d%f", ogon->model, &ogon->rok, &ogon->pojemnosc);
  67.     }
  68.    
  69.     int blad = 0;
  70.     do
  71.     {
  72.         system("cls");
  73.         cout << "Co chcesz zrobic ??" << endl;
  74.         cout << "[1] - pokaz liste" << endl;
  75.         cout << "[2] - dodaj element" << endl;
  76.         cout << "[3] - usun element" << endl;
  77.         cout << "[4] - edytuj element" << endl;
  78.         cout << "[5] - zapisz" << endl;
  79.         cout << "[6] - dodaj po elemencie" << endl;
  80.         cout << "[7] - dodaj przed elementem" << endl;
  81.         cout << "[8] - usun po elemencie" << endl;
  82.         cout << "[9] - usun przed elementem" << endl;
  83.         cout << "[0] - wyjdz" << endl;
  84.         int wybor;
  85.         cin >> wybor;
  86.         if (wybor == 1)
  87.             pokaz();
  88.         if (wybor == 2)
  89.             dodaj();
  90.         if (wybor == 3)
  91.             usun();
  92.         if (wybor == 4)
  93.             edytuj();
  94.         if (wybor == 5)
  95.             zapisz();
  96.         if (wybor == 6)
  97.             dodajPo();
  98.         if (wybor == 7)
  99.             dodajPrzed();
  100.         if (wybor == 8)
  101.             usunPo();
  102.         if (wybor == 9)
  103.             usunPrzed();
  104.         if (wybor == 0)
  105.         {
  106.             cout << "D";
  107.             for(int i = 0; i <= 30; i ++)
  108.             {
  109.                     cout << "-";
  110.                     fun(1);
  111.             }
  112.             cout << "D";
  113.             for(int i = 0; i < 3; i ++)
  114.             {
  115.                 cout << " ~ ";
  116.                 fun(8);
  117.             }
  118.             cout << endl << "Taki chuj w dupe Dabrowskiej !!!" << endl;
  119.             return 0;
  120.         }
  121.     } while (!blad);
  122.  
  123.  
  124. }
  125.  
  126.  
  127. void pokaz()
  128. {
  129.     system("cls");
  130.     ogon = glowa;
  131.     int i = 0;
  132.     while (ogon->nastepny != NULL)
  133.     {
  134.     i++;
  135.     ogon->id = i;
  136.     cout << "------------------------------------------------" << endl;
  137.     cout << "ELEMENT ID: \t" << ogon->id << endl;
  138.     cout << "------------------------------------------------" << endl;
  139.     cout << "MODEL\t\t\t:\t" << ogon->model << endl;
  140.     cout << "ROK\t\t\t:\t" << ogon->rok << endl;
  141.     cout << "POJ.\t\t\t:\t" << ogon->pojemnosc << endl;
  142.     cout << "ADRES\t\t\t: \t0x" << ogon << endl;
  143.     if (ogon->nastepny == NULL)
  144.     cout << "NASTEPNY ELEMENT\t:\tBRAK" << endl;
  145.     else
  146.     {
  147.     cout << "NASTEPNY ELEMENT\t:\t0x" << ogon->nastepny << endl;
  148.     }
  149.     if (ogon->poprzedni == NULL)
  150.     {
  151.         cout << "POPRZEDNI ELEMENT\t:\tBRAK" << endl;
  152.     }
  153.     else
  154.     {
  155.         cout << "POPRZEDNI ELEMENT\t:\t0x" << ogon->poprzedni << endl;
  156.     }
  157.     cout << "------------------------------------------------" << endl;
  158.     cout << endl;
  159.     ogon = ogon->nastepny;
  160.     }
  161.     i++;
  162.     ogon->id = i;
  163.     cout << "------------------------------------------------" << endl;
  164.     cout << "ELEMENT ID: \t" << ogon->id << endl;
  165.     cout << "------------------------------------------------" << endl;
  166.     cout << "MODEL\t\t\t:\t" << ogon->model << endl;
  167.     cout << "ROK\t\t\t:\t" << ogon->rok << endl;
  168.     cout << "POJ.\t\t\t:\t" << ogon->pojemnosc << endl;
  169.     cout << "ADRES\t\t\t: \t0x" << ogon << endl;
  170.     if (ogon->nastepny == NULL)
  171.     cout << "NASTEPNY ELEMENT\t:\tBRAK" << endl;
  172.     else
  173.     {
  174.     cout << "NASTEPNY ELEMENT\t:\t0x" << ogon->nastepny << endl;
  175.     }
  176.     cout << "POPRZEDNI ELEMENT\t:\t0x" << ogon->poprzedni << endl;
  177.     cout << "------------------------------------------------" << endl;
  178.     cout << endl;
  179.     system("pause");
  180. }
  181. void dodaj()
  182. {
  183.     system("cls");
  184.     ogon = glowa;
  185.     while(ogon->nastepny != NULL)
  186.     {
  187.         ogon = ogon->nastepny;
  188.     }
  189.     ogon->nastepny = new pojazd;
  190.     tmp = ogon;
  191.     ogon = ogon->nastepny;
  192.     ogon->poprzedni = tmp;
  193.     ogon->nastepny = NULL;
  194.     ogon->id = (tmp->id + 1);
  195.     cout << "Podaj model ->";
  196.     cin >> ogon->model;
  197.     cout << endl << "Podaj rok ->";
  198.     cin >> ogon->rok;
  199.     cout << endl << "Podaj pojemnosc ->";
  200.     cin >> ogon->pojemnosc;
  201.     system("cls");
  202.     cout << "------------------------------------------------" << endl;
  203.     cout << "(i)DODANO NOWY ELEMENT" <<  endl;
  204.     cout << "------------------------------------------------" << endl;
  205.     cout << "MODEL\t\t\t:\t" << ogon->model << endl;
  206.     cout << "ROK\t\t\t:\t" << ogon->rok << endl;
  207.     cout << "POJ.\t\t\t:\t" << ogon->pojemnosc << endl;
  208.     cout << "------------------------------------------------" << endl;
  209.     cout << "(i)PARAMETRY OBIEKTU" <<  endl;
  210.     cout << "------------------------------------------------" << endl;
  211.     cout << "ADRES\t\t\t: \t0x" << ogon << endl;
  212.     if (ogon->nastepny == NULL)
  213.     cout << "NASTEPNY ELEMENT\t:\tNIE ISTNIEJE" << endl;
  214.     else
  215.     {
  216.     cout << "NASTEPNY ELEMENT\t:\t0x" << ogon->nastepny << endl;
  217.     }
  218.     cout << "POPRZEDNI ELEMENT\t:\t0x" << ogon->poprzedni << endl;
  219.     cout << "------------------------------------------------" << endl;
  220.     system("pause");
  221. }
  222. void dodajPo()
  223. {
  224.     system("cls");
  225.     ogon = glowa;
  226.     int element;
  227.     cout << "Podaj id po ktorym chcesz dodac element" << endl;
  228.     cin >> element;
  229.     int i = 0;
  230.     while(ogon->nastepny != NULL && i < element)
  231.     {
  232.         tmp = ogon;
  233.         ogon = ogon->nastepny;
  234.         i++;
  235.     }
  236.     cout << "DODAJESZ PO ELEMENCIE O NAZWIE :" <<  tmp->model << endl;
  237.     dodawany = new pojazd;
  238.     tmp->nastepny = dodawany;
  239.     ogon->poprzedni = dodawany;
  240.     dodawany->poprzedni = tmp;
  241.     dodawany->nastepny = ogon;
  242.     cout << "Podaj nazwe : " << endl;
  243.     cin >> dodawany->model;
  244.     cout << "Podaj rok : " << endl;
  245.     cin >> dodawany->rok;
  246.     cout << "Podaj silnik : " << endl;
  247.     cin >> dodawany->pojemnosc;
  248.     system("cls");
  249.     cout << "------------------------------------------------" << endl;
  250.     cout << "ELEMENT ZOSTAL DODANY POMYSLNIE "  <<endl;
  251.     cout << "------------------------------------------------" << endl;
  252.     system("pause");
  253. }
  254. void dodajPrzed()
  255. {
  256.    
  257.     system("cls");
  258.     ogon = glowa;
  259.     int element;
  260.     cout << "Podaj id przed ktorym chcesz dodac element" << endl;
  261.     cin >> element;
  262.     int i = 0;
  263.     while(ogon->nastepny != NULL && i < element - 2)
  264.     {
  265.         tmp = ogon;
  266.         ogon = ogon->nastepny;
  267.         i++;
  268.     }
  269.     if (element == 1)
  270.     {
  271.         dodawany = new pojazd;
  272.         cout << "Podaj nazwe : " << endl;
  273.         cin >> dodawany->model;
  274.         cout << "Podaj rok : " << endl;
  275.         cin >> dodawany->rok;
  276.         cout << "Podaj silnik : " << endl;
  277.         cin >> dodawany->pojemnosc;
  278.         dodawany->poprzedni = NULL;
  279.         dodawany->nastepny = glowa;
  280.         glowa->poprzedni = dodawany;
  281.         glowa = dodawany;
  282.         system("cls");
  283.         cout << "------------------------------------------------" << endl;
  284.         cout << "ELEMENT ZOSTAL DODANY POMYSLNIE "  <<endl;
  285.         cout << "------------------------------------------------" << endl;
  286.         system("pause");
  287.     }
  288.     else
  289.     {
  290.  
  291.     cout << "DODAJESZ W MIEJSCE ELEMENTU O NAZWIE :" <<  ogon->model << endl;
  292.  
  293.     dodawany = new pojazd;
  294.     dodawany->poprzedni = ogon;
  295.     tmp = ogon;
  296.     ogon = ogon->nastepny;
  297.     dodawany->nastepny = ogon;
  298.     tmp->nastepny = dodawany;
  299.     ogon->poprzedni = dodawany;
  300.     cout << "Podaj nazwe : " << endl;
  301.     cin >> dodawany->model;
  302.     cout << "Podaj rok : " << endl;
  303.     cin >> dodawany->rok;
  304.     cout << "Podaj silnik : " << endl;
  305.     cin >> dodawany->pojemnosc;
  306.     system("cls");
  307.     cout << "------------------------------------------------" << endl;
  308.     cout << "ELEMENT ZOSTAL DODANY POMYSLNIE "  <<endl;
  309.     cout << "------------------------------------------------" << endl;
  310.     system("pause");
  311.     }
  312. }
  313. void usun ()
  314. {
  315.     system("cls");
  316.     ogon=glowa;
  317.     int numer;
  318.     cout << "------------------------------------------------" << endl;
  319.     cout << "PODAJ NUMER SAMOCHODU DO USUNIECIA...            " << endl;
  320.     cout << "------------------------------------------------" << endl;
  321.     cout << "->";
  322.     cin >> numer;
  323.     if(numer == 1)
  324.     {
  325.         cout << "------------------------------------------------" << endl;
  326.         cout << "ELEMENT ID: \t" << ogon->id << endl;
  327.         cout << "------------------------------------------------" << endl;
  328.         cout << "MODEL\t\t\t:\t" << ogon->model << endl;
  329.         cout << "ROK\t\t\t:\t" << ogon->rok << endl;
  330.         cout << "POJ.\t\t\t:\t" << ogon->pojemnosc << endl;
  331.         cout << "ADRES\t\t\t: \t0x" << ogon << endl;
  332.         if (ogon->nastepny == NULL)
  333.         cout << "NASTEPNY ELEMENT\t:\tBRAK" << endl;
  334.         else
  335.         {
  336.         cout << "NASTEPNY ELEMENT\t:\t0x" << ogon->nastepny << endl;
  337.         }
  338.         if (ogon->poprzedni == NULL)
  339.         {
  340.         cout << "POPRZEDNI ELEMENT\t:\tBRAK" << endl;
  341.         }
  342.         else
  343.         {
  344.         cout << "POPRZEDNI ELEMENT\t:\t0x" << ogon->poprzedni << endl;
  345.         }
  346.         cout << "------------------------------------------------" << endl;
  347.  
  348.         ogon = glowa;
  349.         ogon = ogon->nastepny;
  350.         free(glowa);
  351.         glowa = ogon;
  352.         glowa->poprzedni = NULL;
  353.         system("cls");
  354.         cout << "------------------------------------------------" << endl;
  355.         cout << "ELEMENT ZOSTAL USUNIETY POMYSLNIE "  <<endl;
  356.         cout << "------------------------------------------------" << endl;
  357.         system("pause");
  358.     }
  359.     else
  360.     {
  361.     int blad = 0;
  362.     while(ogon->nastepny != NULL)
  363.     {
  364.         if(ogon->id == numer)
  365.         {
  366.             cout << "WYBRANO ID : " << ogon->id << " MODEL : " << ogon->model << endl;
  367.             tmp->nastepny = ogon->nastepny;
  368.             ogon->nastepny->poprzedni = tmp;
  369.             free(ogon);
  370.             system("cls");
  371.             cout << "------------------------------------------------" << endl;
  372.             cout << "ELEMENT ZOSTAL USUNIETY POMYSLNIE "  <<endl;
  373.             cout << "------------------------------------------------" << endl;
  374.             blad = 1;
  375.             system("pause");
  376.             break;
  377.         }
  378.         else
  379.         {
  380.             tmp = ogon;
  381.             ogon = ogon->nastepny;
  382.         }
  383.     }
  384.     if(ogon->nastepny == NULL && numer == ogon->id)
  385.     {
  386.         cout << "WYBRANO ID : " << ogon->id << " MODEL : " << ogon->model << endl;
  387.         free(ogon);
  388.         tmp->nastepny = NULL;
  389.         system("cls");
  390.         cout << "------------------------------------------------" << endl;
  391.         cout << "ELEMENT ZOSTAL USUNIETY POMYSLNIE "  <<endl;
  392.         cout << "------------------------------------------------" << endl;
  393.         blad = 1;
  394.         system("pause");
  395.  
  396.     }
  397.     if (ogon->id != numer && blad != 1)
  398.     {
  399.         cout << "PODANE ID NIE ISTNIEJE" << endl;
  400.         system("pause");
  401.     }
  402.     }
  403. }
  404. void usunPo()
  405. {
  406.     system("cls");
  407.     ogon = glowa;
  408.     int element;
  409.     cout << "Podaj id po ktorym chcesz usunac element" << endl;
  410.     cin >> element;
  411.     int i = 0;
  412.     while(ogon->nastepny != NULL && i != element)
  413.     {
  414.         tmp = ogon;
  415.         ogon = ogon->nastepny;
  416.         i++;
  417.     }
  418.     cout << "USUWASZ PO ELEMENCIE O NAZWIE :" <<  tmp->model << endl;
  419.     tmp->nastepny = ogon->nastepny;
  420.     ogon->nastepny->poprzedni =tmp;
  421.     free(ogon);
  422.     system("cls");
  423.     cout << "------------------------------------------------" << endl;
  424.     cout << "ELEMENT ZOSTAL USUNIETY POMYSLNIE "  <<endl;
  425.     cout << "------------------------------------------------" << endl;
  426.     system("pause");
  427. }
  428. void usunPrzed()
  429. {
  430.    
  431.    
  432.     system("cls");
  433.     ogon = glowa;
  434.     int element;
  435.     int blad = 0;
  436.     cout << "Podaj id przed ktorym chcesz usunac element" << endl;
  437.     cin >> element;
  438.     int i = 0;
  439.     while(ogon->nastepny != NULL && i < element - 2)
  440.     {
  441.         tmp = ogon;
  442.         ogon = ogon->nastepny;
  443.         i++;
  444.     }
  445.     if (element == 1)
  446.     {
  447.         system("cls");
  448.         cout << "------------------------------------------------" << endl;
  449.         cout << "NIE MOGE USUNAC CZEGOS CZEGO NIE MA..."  <<endl;
  450.         cout << "------------------------------------------------" << endl;
  451.         blad = 1;
  452.         system("pause");
  453.     }
  454.     if (element == 2)
  455.     {
  456.         system("cls");
  457.         tmp = ogon;
  458.         ogon = ogon->nastepny;
  459.         glowa = ogon;
  460.         free(tmp);
  461.         cout << "------------------------------------------------" << endl;
  462.         cout << "ELEMENT ZOSTAL USUNIETY POMYSLNIE "  <<endl;
  463.         cout << "------------------------------------------------" << endl;
  464.         blad = 1;
  465.         system("pause");
  466.     }
  467.     if(blad != 1)
  468.     {
  469.     tmp->nastepny = ogon->nastepny;
  470.     ogon->nastepny->poprzedni = tmp;
  471.     free(ogon);
  472.     system("cls");
  473.     cout << "------------------------------------------------" << endl;
  474.     cout << "ELEMENT ZOSTAL USUNIETY POMYSLNIE "  <<endl;
  475.     cout << "------------------------------------------------" << endl;
  476.     system("pause");
  477.     }
  478. }
  479. void edytuj()
  480. {
  481.     system("cls");
  482.     ogon=glowa;
  483.     int numer;
  484.     cout << "------------------------------------------------" << endl;
  485.     cout << "PODAJ ID SAMOCHODU DO EDYCJI...            " << endl;
  486.     cout << "------------------------------------------------" << endl;
  487.     cout << "->";
  488.     cin >> numer;
  489.     int blad = 0;
  490.     while(ogon->nastepny != NULL)
  491.     {
  492.         if(ogon->id == numer)
  493.         {
  494.             cout << "WYBRANO ID : " << ogon->id << " MODEL : " << ogon->model << endl;
  495.             cout << "Podaj model samochodu : " << endl;
  496.             cin >> ogon->model;
  497.             cout << "Podaj rok produkcji samochodu : " << endl;
  498.             cin >> ogon->rok;
  499.             cout << "Podaj poj. silnika samochodu : " << endl;
  500.             cin >> ogon->pojemnosc;
  501.             system("cls");
  502.             cout << "------------------------------------------------" << endl;
  503.             cout << "ELEMENT ZOSTAL EDYTOWANY POMYSLNIE "  <<endl;
  504.             cout << "------------------------------------------------" << endl;
  505.             blad = 1;
  506.             system("pause");
  507.             break;
  508.         }
  509.         else
  510.         {
  511.             tmp = ogon;
  512.             ogon = ogon->nastepny;
  513.         }
  514.     }
  515.     if(ogon->nastepny == NULL && numer == ogon->id)
  516.     {
  517.         cout << "WYBRANO ID : " << ogon->id << " MODEL : " << ogon->model << endl;
  518.         cout << "Podaj model samochodu : " << endl;
  519.         cin >> ogon->model;
  520.         cout << "Podaj rok produkcji samochodu : " << endl;
  521.         cin >> ogon->rok;
  522.         cout << "Podaj poj. silnika samochodu : " << endl;
  523.         cin >> ogon->pojemnosc;
  524.         system("cls");
  525.         cout << "------------------------------------------------" << endl;
  526.         cout << "ELEMENT ZOSTAL EDYTOWANY POMYSLNIE "  <<endl;
  527.         cout << "------------------------------------------------" << endl;
  528.         blad = 1;
  529.         system("pause");
  530.  
  531.     }
  532.     if (ogon->id != numer && blad != 1)
  533.     {
  534.         cout << "PODANE ID NIE ISTNIEJE" << endl;
  535.         system("pause");
  536.     }
  537.     }
  538. void zapisz()
  539. {
  540.     char fileOpen[]="C:/test/dane.txt";
  541.     char fileSave[]="C:/test/save.txt";
  542.     FILE* odczyt;
  543.     FILE* zapis;
  544.     odczyt = fopen(fileOpen, "r");
  545.     zapis = fopen(fileSave, "w");
  546.  
  547.     ogon = glowa;
  548.     int i = 0;
  549.     while (ogon->nastepny != NULL)
  550.     {
  551.         ++i;
  552.         ogon->id = i;
  553.         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);
  554.         ogon = ogon->nastepny;
  555.     }
  556.     ++i;
  557.     ogon->id = i;
  558.     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);
  559.     fclose(odczyt);
  560.     fclose(zapis);
  561. }
  562. void fun(int sekundy)
  563. {
  564.     clock_t endwait;
  565.     endwait = clock () + sekundy * (CLOCKS_PER_SEC/32)  ;
  566.     while (clock() < endwait) {}
  567. }
Add Comment
Please, Sign In to add comment