Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- // inicjaly, imie, nazwisko, mail, dzielenie maila na user i serwer
- class Czlowiek {
- private:
- string imie;
- string nazwisko;
- string mail;
- double wiek;
- public:
- Czlowiek(string imie, string nazwisko, string mail, double wiek): imie(imie), nazwisko(nazwisko), mail(mail), wiek(wiek){}
- void wypisz_inicjaly() {
- cout << "Inicjały to " << imie[0] << " " << nazwisko[0] << endl;
- }
- void wypisz_usera() {
- size_t pozycja_malpy = mail.find('@');
- string user = mail.substr(0,pozycja_malpy);
- cout << "User to " << user << endl;
- }
- void wypisz_serwer() {
- size_t pozycja_malpy = mail.find('@');
- string serwer = mail.substr(pozycja_malpy+1, mail.size());
- cout << "Serwer to " << serwer << endl;
- }
- void show() {
- wypisz_inicjaly();
- wypisz_usera();
- wypisz_serwer();
- }
- bool operator >(const Czlowiek cz) {
- if(this->wiek > cz.wiek) {
- return true;
- }
- return false;
- }
- bool operator <(const Czlowiek cz) {
- if(this->wiek < cz.wiek) {
- return true;
- }
- return false;
- }
- double getWiek() const {
- return wiek;
- }
- };
- bool wiekszy(Czlowiek cz1, Czlowiek cz2) {
- return cz1>cz2;
- }
- int main(int argc, char** argv) {
- Czlowiek cz1 = Czlowiek("Wojciech", "Regula", "test@wp.pl", 30);
- Czlowiek cz2 = Czlowiek("Wojciech", "Regula", "test@wp.pl", 40);
- Czlowiek cz3 = Czlowiek("Wojciech", "Regula", "test@wp.pl", 20);
- Czlowiek cz4 = Czlowiek("Wojciech", "Regula", "test@wp.pl", 10);
- cout << "Przed sortowaniem" << endl;
- vector<Czlowiek> wektorOsob = {cz1, cz2, cz3, cz4};
- for(Czlowiek cz : wektorOsob) {
- cout << cz.getWiek() << endl;
- }
- cout << "Po sortowaniu" << endl;
- sort(wektorOsob.begin(), wektorOsob.end(), wiekszy);
- for(Czlowiek cz : wektorOsob) {
- cout << cz.getWiek() << endl;
- }
- return 0;
- }
- // ----------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement