Advertisement
Guest User

program do walenia konia

a guest
May 21st, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <cstdio>
  4. #include <conio.h>
  5. #include <vector>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9.  
  10. class Zwierze
  11. {
  12. public:
  13.     string gatunek;
  14.     string ruch;
  15.     string glos;
  16.     Zwierze(string gat, string r, string gl)
  17.     {
  18.         gatunek = gat;
  19.         ruch = r;
  20.         glos = gl;
  21.     }
  22. };
  23.  
  24. int main()
  25. {
  26.     string gatunek;
  27.     string ruch;
  28.     string glos;
  29.     char wybor;
  30.     unsigned int i;
  31.     vector<Zwierze>animal;
  32.  
  33.     while(1)
  34.     {
  35.         cout << "===================" << endl;
  36.         cout << "1. Dodaj zwierze" << endl;
  37.         cout << "2. Wyswietl zawartosc" << endl;
  38.         cout << "3. Edycja ostatnio dodanego zwierzecia" << endl;
  39.         cout << "4. Usun zwierze" << endl;
  40.         cout << "5. Zapisz do pliku baze wprowadzonych zwierzat" << endl;
  41.         cout << "6. Koniec" << endl;
  42.         cout << "===================" << endl;
  43.         wybor = getch();
  44.         system("cls");
  45.  
  46.         if(wybor == '1')
  47.         {
  48.             cout << "Gatunek: ";
  49.             cin >> gatunek;
  50.             cout << "Sposob poruszania sie: ";
  51.             cin >> ruch;
  52.             cout << "Wydawany odglos: ";
  53.             cin >> glos;
  54.             cout << endl;
  55.             animal.push_back(Zwierze(gatunek,ruch,glos));
  56.         }
  57.         else if(wybor == '2')
  58.         {
  59.             for(i=0; i<animal.size(); i++)
  60.             {
  61.                 cout << i << ".";
  62.                 cout << "Gatunek: " << animal[i].gatunek << endl;
  63.                 cout << "Ruch: " << animal[i].ruch << endl;
  64.                 cout << "Glos: " << animal[i].glos << endl;
  65.                 cout << endl;
  66.             }
  67.         }
  68.         else if(wybor == '3')
  69.         {
  70.             unsigned int pick;
  71.  
  72.             for(i=0; i<animal.size(); i++)
  73.             {
  74.                 cout << i << ".";
  75.                 cout << "Gatunek: " << animal[i].gatunek << endl;
  76.                 cout << "Ruch: " << animal[i].ruch << endl;
  77.                 cout << "Glos: " << animal[i].glos << endl;
  78.                 cout << endl;
  79.             }
  80.  
  81.             cout << "Ktore zwierze chcesz edytowac?" << endl;
  82.             cin >> pick;
  83.             if(pick>animal.size())
  84.             {
  85.                 cout << "Brak zwierzecia z podanym indeksem." << endl;
  86.             }
  87.             else
  88.             {
  89.                 animal.erase(animal.begin()+pick);
  90.                 cout << "Gatunek: ";
  91.                 cin >> animal[pick].gatunek;
  92.                 cout << "Sposob poruszania sie: ";
  93.                 cin >> animal[pick].ruch;
  94.                 cout << "Wydawany odglos: ";
  95.                 cin >> animal[pick].glos;
  96.                 cout << endl;
  97.                 // animal.insert(animal.begin()+pick, pick);
  98.             }
  99.         }
  100.         else if(wybor == '4')
  101.         {
  102.             int pick;
  103.             if(animal.size()==0)
  104.             {
  105.                 cout << "Brak zwierzat w bazie" << endl;
  106.             }
  107.             else
  108.             {
  109.                 for(i=0; i<animal.size(); i++)
  110.                 {
  111.                     cout << i << ".";
  112.                     cout << "Gatunek: " << animal[i].gatunek << endl;
  113.                     cout << "Ruch: " << animal[i].ruch << endl;
  114.                     cout << "Glos: " << animal[i].glos << endl;
  115.                     cout << endl;
  116.                 }
  117.  
  118.                 cout << "Ktore zwierze chcesz usunac?" << endl;
  119.                 cin >> pick;
  120.                 animal.erase(animal.begin()+pick);
  121.                 system("cls");
  122.                 cout << "Wybrane zwierze zostalo usuniete!" << endl;
  123.             }
  124.         }
  125.         else if(wybor == '6')
  126.             return 0;
  127.         else if(wybor == '5')
  128.         {
  129.             string tekst;
  130.             fstream plik;
  131.             plik.open("plik.txt", ios::out);
  132.             if(plik.good() == true)
  133.             {
  134.                 for(i=0; i<animal.size(); i++)
  135.             {
  136.                 plik << i << "." <<animal[i].gatunek << endl;
  137.                 plik << animal[i].ruch << endl;
  138.                 plik << animal[i].glos << endl;
  139.                 cout << "pomyslnie dokonano zapisu" << endl;
  140.             }
  141.             }
  142.             plik.close();
  143.         }
  144.     }
  145.         return 0;
  146.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement