Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. // inicjaly, imie, nazwisko, mail, dzielenie maila na user i serwer
  8. class Czlowiek {
  9.  
  10. private:
  11.     string imie;
  12.     string nazwisko;
  13.     string mail;
  14.     double wiek;
  15. public:
  16.     Czlowiek(string imie, string nazwisko, string mail, double wiek): imie(imie), nazwisko(nazwisko), mail(mail), wiek(wiek){}
  17.  
  18.     void wypisz_inicjaly() {
  19.         cout << "Inicjały to " << imie[0] << " " << nazwisko[0] << endl;
  20.     }
  21.  
  22.     void wypisz_usera() {
  23.         size_t pozycja_malpy = mail.find('@');
  24.         string user = mail.substr(0,pozycja_malpy);
  25.         cout << "User to " << user << endl;
  26.     }
  27.  
  28.     void wypisz_serwer() {
  29.         size_t pozycja_malpy = mail.find('@');
  30.         string serwer = mail.substr(pozycja_malpy+1, mail.size());
  31.         cout << "Serwer to " << serwer << endl;
  32.     }
  33.  
  34.     void show() {
  35.         wypisz_inicjaly();
  36.         wypisz_usera();
  37.         wypisz_serwer();
  38.     }
  39.  
  40.     bool operator >(const Czlowiek cz) {
  41.         if(this->wiek > cz.wiek) {
  42.             return true;
  43.         }
  44.         return false;
  45.     }
  46.  
  47.     bool operator <(const Czlowiek cz) {
  48.         if(this->wiek < cz.wiek) {
  49.             return true;
  50.         }
  51.         return false;
  52.     }
  53.  
  54.     double getWiek() const {
  55.         return wiek;
  56.     }
  57. };
  58.  
  59. bool wiekszy(Czlowiek cz1, Czlowiek cz2) {
  60.     return cz1>cz2;
  61. }
  62.  
  63. int main(int argc, char** argv) {
  64.  
  65.     Czlowiek cz1 = Czlowiek("Wojciech", "Regula", "test@wp.pl", 30);
  66.     Czlowiek cz2 = Czlowiek("Wojciech", "Regula", "test@wp.pl", 40);
  67.     Czlowiek cz3 = Czlowiek("Wojciech", "Regula", "test@wp.pl", 20);
  68.     Czlowiek cz4 = Czlowiek("Wojciech", "Regula", "test@wp.pl", 10);
  69.  
  70.     cout << "Przed sortowaniem" << endl;
  71.  
  72.     vector<Czlowiek> wektorOsob = {cz1, cz2, cz3, cz4};
  73.     for(Czlowiek cz : wektorOsob) {
  74.         cout << cz.getWiek() << endl;
  75.     }
  76.  
  77.     cout << "Po sortowaniu" << endl;
  78.  
  79.     sort(wektorOsob.begin(), wektorOsob.end(), wiekszy);
  80.     for(Czlowiek cz : wektorOsob) {
  81.         cout << cz.getWiek() << endl;
  82.     }
  83.  
  84.     return 0;
  85. }
  86.  
  87. // ----------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement