Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.11 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4.  
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6. using namespace std;
  7.  
  8. class Platnosc {
  9. public:
  10.     char* nazwa_platnosci;
  11.     double kwota_platnosci;
  12.     int dzien, miesiac, rok;
  13.     Platnosc() { nazwa_platnosci = nullptr; }
  14.     Platnosc(Platnosc &p) {
  15.         nazwa_platnosci = new char[strlen(p.nazwa_platnosci) + 1];
  16.         strcpy(this->nazwa_platnosci,p.nazwa_platnosci);
  17.         this->kwota_platnosci = p.kwota_platnosci;
  18.         this->dzien = p.dzien;
  19.         this->miesiac = p.miesiac;
  20.         this->rok = p.rok;
  21.     }
  22.     Platnosc(char *_nazwa, double kwota, int dzien, int miesiac, int rok) {
  23.         this->nazwa_platnosci = new char[strlen(_nazwa) + 1];
  24.         strcpy(this->nazwa_platnosci,_nazwa);
  25.         this->kwota_platnosci = kwota;
  26.         this->dzien = dzien;
  27.         this->miesiac = miesiac;
  28.         this->rok = rok;
  29.     }
  30.     Platnosc &operator=(const Platnosc &p) {
  31.         this->nazwa_platnosci = p.nazwa_platnosci;
  32.         this->kwota_platnosci = p.kwota_platnosci;
  33.         this->dzien = p.dzien;
  34.         this->miesiac = p.miesiac;
  35.         this->rok = p.rok;
  36.        
  37.     }
  38.     void echo() {
  39.         cout << this->nazwa_platnosci << endl;
  40.     }
  41. };
  42.  
  43. class Stos_platnosci {
  44. public:
  45.     //friend class Platnosc;
  46.     int pojemnosc;
  47.     int ostatni_element = 0;
  48.     Platnosc **stos;
  49.     //Platnosc *mstos;
  50. public:
  51.     Stos_platnosci() { this->pojemnosc = 0; }
  52.     //Konstruktor kopiujący
  53.     Stos_platnosci(Stos_platnosci &stos) {
  54.         if (stos.pojemnosc != this->pojemnosc) {
  55.             for (int i = 0; i<this->pojemnosc; i++)
  56.                 delete[] this->stos[i];
  57.             delete[] this->stos;
  58.             this->stos = new Platnosc*[stos.pojemnosc];
  59.             this->pojemnosc = stos.pojemnosc;
  60.             for (int i = 0; i<this->pojemnosc; i++)
  61.                 this->stos[i] = stos.stos[i];
  62.         }
  63.         else {
  64.             for (int i = 0; i<this->pojemnosc; i++)
  65.                 this->stos[i] = stos.stos[i];
  66.         }
  67.     }
  68.     Stos_platnosci(int pojemnosc) {
  69.         this->pojemnosc = pojemnosc;
  70.         this->stos = new Platnosc*[pojemnosc];
  71.     }
  72.     ~Stos_platnosci() {
  73.         for (int i = 0; i<this->ostatni_element; i++)
  74.             delete[] this->stos[i];
  75.         delete[] stos;
  76.     }
  77.     Platnosc * operator--() {
  78.         Platnosc *temp = this->stos[0];
  79.         for (int i = 0; i < this->pojemnosc - 1 || this->stos[i] == nullptr; ++i)
  80.             this->stos[i] = this->stos[i + 1];
  81.         this->ostatni_element -= 1;
  82.         return temp;
  83.     }
  84.     Stos_platnosci & operator +=(Platnosc *platnosc) {
  85.         this->stos[this->ostatni_element] = platnosc;
  86.         this->ostatni_element++;
  87.         return *this;
  88.     }
  89.     Platnosc * operator[](int i) { return this->stos[i]; };
  90.     friend ostream& operator<<(ostream& strumien, const Stos_platnosci &dupa) {
  91.         for (int i = 0; i < dupa.ostatni_element; i++)
  92.             strumien << dupa.stos[i]->nazwa_platnosci << " " << dupa.stos[i]->kwota_platnosci << " " << dupa.stos[i]->dzien << " " << dupa.stos[i]->miesiac << " " << dupa.stos[i]->rok << endl;
  93.         return strumien;
  94.     }
  95. };
  96.  
  97. class Kolejka_wydatkow : public Stos_platnosci {
  98. public:
  99.     Platnosc* tmp;
  100. public:
  101.     Kolejka_wydatkow(int pojemnosc)
  102.     {
  103.         this->pojemnosc = pojemnosc;
  104.         this->ostatni_element = 0;
  105.         *stos = new Platnosc[this->pojemnosc];
  106.        
  107.     }
  108.     ~Kolejka_wydatkow() {
  109.         delete[] stos;
  110.     }
  111.     friend ostream& operator<<(ostream& strumien, const Stos_platnosci &dupa);
  112.  
  113.     Kolejka_wydatkow& operator=(Stos_platnosci& w)
  114.     {
  115.         this->pojemnosc = w.pojemnosc;
  116.         this->ostatni_element = w.ostatni_element;
  117.         *stos = new Platnosc[this->pojemnosc];
  118.        
  119.         for (int i = 0; i < ostatni_element; i++)
  120.         {
  121.             stos[i] = w.stos[i];
  122.         }
  123.         for (int i = 0; i < ostatni_element; i++)
  124.         {
  125.             for (int j = 0; j < ostatni_element; j++)
  126.             {
  127.                 if (stos[j] > stos[i])
  128.                 {
  129.                     tmp = stos[i];
  130.                     stos[i] = stos[j];
  131.                     stos[j] = tmp;
  132.                 }
  133.  
  134.             }
  135.         }
  136.         return *this;
  137.     }
  138.  
  139. };
  140.  
  141. int main(int argc, char** argv) {
  142.     Platnosc *dupa = new Platnosc("Dupa blada", 300, 21, 02, 1900);
  143.     Platnosc *dupa2 = new Platnosc("Kurwy wino", 800, 21, 01, 1990);
  144.     Platnosc *dupa3 = new Platnosc("A tu pianino", 9900, 30, 02, 1990);
  145.     Platnosc *dupa4 = new Platnosc(*dupa);
  146.     Stos_platnosci stos(4);
  147.    
  148.    
  149.     stos += dupa;
  150.     stos += dupa2;
  151.     stos += dupa3;
  152.     stos += dupa4;
  153.     stos[0]->echo();
  154.     Kolejka_wydatkow kw(1);
  155.     cout << stos;
  156.  
  157.     system("pause");
  158.     return 0;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement