Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <exception>
- #include <list>
- using namespace std;
- struct osoba
- {
- string imie, nazwisko;
- };
- class osoby
- {
- list <osoba> nowa;
- public:
- void dodaj()
- {
- try
- {
- string imie, nazwisko;
- cout << "Podaj imie: " <<endl;
- cin >> imie;
- cout << "Podaj nazwisko: " <<endl;
- cin >> nazwisko;
- if(imie.size() > 20)
- throw (string) "Za dlugie";
- if(nazwisko.size() > 20)
- throw (string) "Za dlugie";
- struct osoba a;
- a.imie = imie;
- a.nazwisko = nazwisko;
- nowa.push_back(a);
- }
- catch (string e)
- {
- cout << "Blad: " << e <<endl;
- }
- }
- void wyswietl()
- {
- try
- {
- if(nowa.size()==0)
- throw (string) "Brak osob na liscie";
- cout << "Lista osob: " <<endl;
- list <osoba>::iterator i;
- for(i=nowa.begin();i!=nowa.end();i++)
- cout << (*i).imie << " " << (*i).nazwisko <<endl;
- }
- catch (string e)
- {
- cout << "Blad: " << e <<endl;
- }
- }
- };
- int main()
- {
- osoby obiekt;
- obiekt.dodaj();
- obiekt.dodaj();
- obiekt.dodaj();
- obiekt.wyswietl();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement