Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- using namespace std;
- class Platnosc {
- public:
- char* nazwa_platnosci;
- double kwota_platnosci;
- int dzien, miesiac, rok;
- Platnosc() { nazwa_platnosci = nullptr; }
- Platnosc(Platnosc &p) {
- nazwa_platnosci = new char[strlen(p.nazwa_platnosci) + 1];
- strcpy(this->nazwa_platnosci,p.nazwa_platnosci);
- this->kwota_platnosci = p.kwota_platnosci;
- this->dzien = p.dzien;
- this->miesiac = p.miesiac;
- this->rok = p.rok;
- }
- Platnosc(char *_nazwa, double kwota, int dzien, int miesiac, int rok) {
- this->nazwa_platnosci = new char[strlen(_nazwa) + 1];
- strcpy(this->nazwa_platnosci,_nazwa);
- this->kwota_platnosci = kwota;
- this->dzien = dzien;
- this->miesiac = miesiac;
- this->rok = rok;
- }
- Platnosc &operator=(const Platnosc &p) {
- this->nazwa_platnosci = p.nazwa_platnosci;
- this->kwota_platnosci = p.kwota_platnosci;
- this->dzien = p.dzien;
- this->miesiac = p.miesiac;
- this->rok = p.rok;
- }
- void echo() {
- cout << this->nazwa_platnosci << endl;
- }
- };
- class Stos_platnosci {
- public:
- //friend class Platnosc;
- int pojemnosc;
- int ostatni_element = 0;
- Platnosc **stos;
- //Platnosc *mstos;
- public:
- Stos_platnosci() { this->pojemnosc = 0; }
- //Konstruktor kopiujący
- Stos_platnosci(Stos_platnosci &stos) {
- if (stos.pojemnosc != this->pojemnosc) {
- for (int i = 0; i<this->pojemnosc; i++)
- delete[] this->stos[i];
- delete[] this->stos;
- this->stos = new Platnosc*[stos.pojemnosc];
- this->pojemnosc = stos.pojemnosc;
- for (int i = 0; i<this->pojemnosc; i++)
- this->stos[i] = stos.stos[i];
- }
- else {
- for (int i = 0; i<this->pojemnosc; i++)
- this->stos[i] = stos.stos[i];
- }
- }
- Stos_platnosci(int pojemnosc) {
- this->pojemnosc = pojemnosc;
- this->stos = new Platnosc*[pojemnosc];
- }
- ~Stos_platnosci() {
- for (int i = 0; i<this->ostatni_element; i++)
- delete[] this->stos[i];
- delete[] stos;
- }
- Platnosc * operator--() {
- Platnosc *temp = this->stos[0];
- for (int i = 0; i < this->pojemnosc - 1 || this->stos[i] == nullptr; ++i)
- this->stos[i] = this->stos[i + 1];
- this->ostatni_element -= 1;
- return temp;
- }
- Stos_platnosci & operator +=(Platnosc *platnosc) {
- this->stos[this->ostatni_element] = platnosc;
- this->ostatni_element++;
- return *this;
- }
- Platnosc * operator[](int i) { return this->stos[i]; };
- friend ostream& operator<<(ostream& strumien, const Stos_platnosci &dupa) {
- for (int i = 0; i < dupa.ostatni_element; i++)
- strumien << dupa.stos[i]->nazwa_platnosci << " " << dupa.stos[i]->kwota_platnosci << " " << dupa.stos[i]->dzien << " " << dupa.stos[i]->miesiac << " " << dupa.stos[i]->rok << endl;
- return strumien;
- }
- };
- class Kolejka_wydatkow : public Stos_platnosci {
- public:
- Platnosc* tmp;
- public:
- Kolejka_wydatkow(int pojemnosc)
- {
- this->pojemnosc = pojemnosc;
- this->ostatni_element = 0;
- *stos = new Platnosc[this->pojemnosc];
- }
- ~Kolejka_wydatkow() {
- delete[] stos;
- }
- friend ostream& operator<<(ostream& strumien, const Stos_platnosci &dupa);
- Kolejka_wydatkow& operator=(Stos_platnosci& w)
- {
- this->pojemnosc = w.pojemnosc;
- this->ostatni_element = w.ostatni_element;
- *stos = new Platnosc[this->pojemnosc];
- for (int i = 0; i < ostatni_element; i++)
- {
- stos[i] = w.stos[i];
- }
- for (int i = 0; i < ostatni_element; i++)
- {
- for (int j = 0; j < ostatni_element; j++)
- {
- if (stos[j] > stos[i])
- {
- tmp = stos[i];
- stos[i] = stos[j];
- stos[j] = tmp;
- }
- }
- }
- return *this;
- }
- };
- int main(int argc, char** argv) {
- Platnosc *dupa = new Platnosc("Dupa blada", 300, 21, 02, 1900);
- Platnosc *dupa2 = new Platnosc("Kurwy wino", 800, 21, 01, 1990);
- Platnosc *dupa3 = new Platnosc("A tu pianino", 9900, 30, 02, 1990);
- Platnosc *dupa4 = new Platnosc(*dupa);
- Stos_platnosci stos(4);
- stos += dupa;
- stos += dupa2;
- stos += dupa3;
- stos += dupa4;
- stos[0]->echo();
- Kolejka_wydatkow kw(1);
- cout << stos;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement