Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <exception>
  3. #include <list>
  4.  
  5. using namespace std;
  6.  
  7. struct osoba
  8. {
  9.     string imie, nazwisko;
  10. };
  11.  
  12. class osoby
  13. {
  14.     list <osoba> nowa;
  15. public:
  16.     void dodaj()
  17.     {
  18.         try
  19.         {
  20.             string imie, nazwisko;
  21.             cout << "Podaj imie: " <<endl;
  22.             cin >> imie;
  23.             cout << "Podaj nazwisko: " <<endl;
  24.             cin >> nazwisko;
  25.             if(imie.size() > 20)
  26.                 throw (string) "Za dlugie";
  27.             if(nazwisko.size() > 20)
  28.                 throw (string) "Za dlugie";
  29.             struct osoba a;
  30.             a.imie = imie;
  31.             a.nazwisko = nazwisko;
  32.             nowa.push_back(a);
  33.         }
  34.         catch (string e)
  35.         {
  36.             cout << "Blad: " << e <<endl;
  37.         }
  38.     }
  39.     void wyswietl()
  40.     {
  41.         try
  42.         {
  43.             if(nowa.size()==0)
  44.                 throw (string) "Brak osob na liscie";
  45.             cout << "Lista osob: " <<endl;
  46.             list <osoba>::iterator i;
  47.             for(i=nowa.begin();i!=nowa.end();i++)
  48.                 cout << (*i).imie << " " << (*i).nazwisko <<endl;
  49.         }
  50.         catch (string e)
  51.         {
  52.             cout << "Blad: " << e <<endl;
  53.         }
  54.     }
  55. };
  56. int main()
  57. {
  58.     osoby obiekt;
  59.     obiekt.dodaj();
  60.     obiekt.dodaj();
  61.     obiekt.dodaj();
  62.     obiekt.wyswietl();
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement