Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Karticka
- {
- protected:
- int brojVozena;
- public:
- Karticka(int BrojVozena)
- {
- brojVozena=BrojVozena;
- }
- Karticka(){}
- virtual int vkupnaCena() = 0;
- virtual ~Karticka(){}
- bool operator < (Karticka &k)
- {
- return this->vkupnaCena()<k.vkupnaCena();
- }
- friend ostream& operator<< (ostream &out, Karticka &k)
- {
- out<<"Vkupna cena: "<<k.vkupnaCena()<<endl;
- out<<"Broj na vozenja: "<<k.brojVozena<<endl;
- return out;
- }
- };
- class KartickaAvtobus : public Karticka
- {
- private:
- int cena;
- int cenaEdno;
- //int brojV;
- public:
- KartickaAvtobus (int Cena, int CenaEdno, int BrojV)
- {
- cena=Cena;
- cenaEdno=CenaEdno;
- brojVozena=BrojV;
- }
- KartickaAvtobus(){}
- int vkupnaCena()
- {
- return cena + (cenaEdno * brojVozena);
- }
- };
- class KarickaVoz : public Karticka
- {
- private:
- //int brojVoz;
- bool gradska;
- public:
- KarickaVoz(int BrojVoz, bool Gradska)
- {
- brojVozena=BrojVoz;
- gradska=Gradska;
- }
- KarickaVoz(){}
- int vkupnaCena()
- {
- if(gradska == true)
- return brojVozena*50;
- else
- return brojVozena*95;
- }
- };
- class AvtomatZaKarticki
- {
- public:
- static int total(Karticka **karticki,int n)
- { int suma=0;
- for(int i=0;i<n;i++)
- {
- suma+=karticki[i]->vkupnaCena();
- }
- return suma;
- }
- };
- int main() {
- int n;
- cin >> n;
- if(n == 0) {
- cout << "Constructors" << endl;
- KartickaAvtobus ds(150,35,2);
- KarickaVoz cs(15,false);
- cout << "OK" << endl;
- } else if(n == 1) {
- cout << "operator <<" << endl;
- KartickaAvtobus ds(150,35,2);
- KarickaVoz cs(10,true);
- cout << ds << endl;
- cout << cs << endl;
- } else if(n == 2) {
- cout << "<" << endl;
- KartickaAvtobus ds(150,35,2);
- KarickaVoz cs(20,true);
- KarickaVoz css(30, false);
- cout << (ds < cs) << endl;
- cout << (cs < ds) << endl;
- cout << (cs < css) << endl;
- cout << (cs < css) << endl;
- } else if(n == 3) {
- cout << "Karticka total" << endl;
- KartickaAvtobus ds1(150,35,2);
- KartickaAvtobus ds2(100,80,5);
- KartickaAvtobus ds3(150,40,1);
- KarickaVoz cs1(15,false);
- KarickaVoz cs2(10,true);
- KarickaVoz cs3(20,true);
- Karticka** s = new Karticka*[6];
- s[0] = &ds1;
- s[1] = &ds2;
- s[2] = &ds3;
- s[3] = &cs1;
- s[4] = &cs2;
- s[5] = &cs3;
- cout<<AvtomatZaKarticki::total(s, 6);
- delete [] s;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment