Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <cstdio>
- #include <conio.h>
- #include <vector>
- #include <fstream>
- using namespace std;
- class Zwierze
- {
- public:
- string gatunek;
- string ruch;
- string glos;
- Zwierze(string gat, string r, string gl)
- {
- gatunek = gat;
- ruch = r;
- glos = gl;
- }
- };
- int main()
- {
- string gatunek;
- string ruch;
- string glos;
- char wybor;
- unsigned int i;
- vector<Zwierze>animal;
- while(1)
- {
- cout << "===================" << endl;
- cout << "1. Dodaj zwierze" << endl;
- cout << "2. Wyswietl zawartosc" << endl;
- cout << "3. Edycja ostatnio dodanego zwierzecia" << endl;
- cout << "4. Usun zwierze" << endl;
- cout << "5. Zapisz do pliku baze wprowadzonych zwierzat" << endl;
- cout << "6. Koniec" << endl;
- cout << "===================" << endl;
- wybor = getch();
- system("cls");
- if(wybor == '1')
- {
- cout << "Gatunek: ";
- cin >> gatunek;
- cout << "Sposob poruszania sie: ";
- cin >> ruch;
- cout << "Wydawany odglos: ";
- cin >> glos;
- cout << endl;
- animal.push_back(Zwierze(gatunek,ruch,glos));
- }
- else if(wybor == '2')
- {
- for(i=0; i<animal.size(); i++)
- {
- cout << i << ".";
- cout << "Gatunek: " << animal[i].gatunek << endl;
- cout << "Ruch: " << animal[i].ruch << endl;
- cout << "Glos: " << animal[i].glos << endl;
- cout << endl;
- }
- }
- else if(wybor == '3')
- {
- unsigned int pick;
- for(i=0; i<animal.size(); i++)
- {
- cout << i << ".";
- cout << "Gatunek: " << animal[i].gatunek << endl;
- cout << "Ruch: " << animal[i].ruch << endl;
- cout << "Glos: " << animal[i].glos << endl;
- cout << endl;
- }
- cout << "Ktore zwierze chcesz edytowac?" << endl;
- cin >> pick;
- if(pick>animal.size())
- {
- cout << "Brak zwierzecia z podanym indeksem." << endl;
- }
- else
- {
- animal.erase(animal.begin()+pick);
- cout << "Gatunek: ";
- cin >> animal[pick].gatunek;
- cout << "Sposob poruszania sie: ";
- cin >> animal[pick].ruch;
- cout << "Wydawany odglos: ";
- cin >> animal[pick].glos;
- cout << endl;
- // animal.insert(animal.begin()+pick, pick);
- }
- }
- else if(wybor == '4')
- {
- int pick;
- if(animal.size()==0)
- {
- cout << "Brak zwierzat w bazie" << endl;
- }
- else
- {
- for(i=0; i<animal.size(); i++)
- {
- cout << i << ".";
- cout << "Gatunek: " << animal[i].gatunek << endl;
- cout << "Ruch: " << animal[i].ruch << endl;
- cout << "Glos: " << animal[i].glos << endl;
- cout << endl;
- }
- cout << "Ktore zwierze chcesz usunac?" << endl;
- cin >> pick;
- animal.erase(animal.begin()+pick);
- system("cls");
- cout << "Wybrane zwierze zostalo usuniete!" << endl;
- }
- }
- else if(wybor == '6')
- return 0;
- else if(wybor == '5')
- {
- string tekst;
- fstream plik;
- plik.open("plik.txt", ios::out);
- if(plik.good() == true)
- {
- for(i=0; i<animal.size(); i++)
- {
- plik << i << "." <<animal[i].gatunek << endl;
- plik << animal[i].ruch << endl;
- plik << animal[i].glos << endl;
- cout << "pomyslnie dokonano zapisu" << endl;
- }
- }
- plik.close();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement