ivanakarpuzova

Untitled

Sep 2nd, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. class Karticka
  5. {
  6. protected:
  7. int brojVozena;
  8.  
  9. public:
  10. Karticka(int BrojVozena)
  11. {
  12. brojVozena=BrojVozena;
  13. }
  14. Karticka(){}
  15. virtual int vkupnaCena() = 0;
  16. virtual ~Karticka(){}
  17. bool operator < (Karticka &k)
  18. {
  19. return this->vkupnaCena()<k.vkupnaCena();
  20. }
  21.  
  22.  
  23. friend ostream& operator<< (ostream &out, Karticka &k)
  24. {
  25. out<<"Vkupna cena: "<<k.vkupnaCena()<<endl;
  26. out<<"Broj na vozenja: "<<k.brojVozena<<endl;
  27. return out;
  28. }
  29.  
  30.  
  31. };
  32.  
  33. class KartickaAvtobus : public Karticka
  34. {
  35. private:
  36. int cena;
  37. int cenaEdno;
  38. //int brojV;
  39. public:
  40. KartickaAvtobus (int Cena, int CenaEdno, int BrojV)
  41. {
  42. cena=Cena;
  43. cenaEdno=CenaEdno;
  44. brojVozena=BrojV;
  45. }
  46. KartickaAvtobus(){}
  47.  
  48. int vkupnaCena()
  49. {
  50. return cena + (cenaEdno * brojVozena);
  51. }
  52. };
  53.  
  54. class KarickaVoz : public Karticka
  55. {
  56. private:
  57. //int brojVoz;
  58. bool gradska;
  59. public:
  60. KarickaVoz(int BrojVoz, bool Gradska)
  61. {
  62. brojVozena=BrojVoz;
  63. gradska=Gradska;
  64. }
  65. KarickaVoz(){}
  66.  
  67. int vkupnaCena()
  68. {
  69. if(gradska == true)
  70. return brojVozena*50;
  71. else
  72. return brojVozena*95;
  73. }
  74.  
  75. };
  76.  
  77. class AvtomatZaKarticki
  78. {
  79. public:
  80. static int total(Karticka **karticki,int n)
  81. { int suma=0;
  82. for(int i=0;i<n;i++)
  83. {
  84. suma+=karticki[i]->vkupnaCena();
  85. }
  86.  
  87. return suma;
  88.  
  89. }
  90. };
  91.  
  92.  
  93. int main() {
  94. int n;
  95. cin >> n;
  96. if(n == 0) {
  97. cout << "Constructors" << endl;
  98. KartickaAvtobus ds(150,35,2);
  99. KarickaVoz cs(15,false);
  100. cout << "OK" << endl;
  101. } else if(n == 1) {
  102. cout << "operator <<" << endl;
  103. KartickaAvtobus ds(150,35,2);
  104. KarickaVoz cs(10,true);
  105. cout << ds << endl;
  106. cout << cs << endl;
  107. } else if(n == 2) {
  108. cout << "<" << endl;
  109. KartickaAvtobus ds(150,35,2);
  110. KarickaVoz cs(20,true);
  111. KarickaVoz css(30, false);
  112. cout << (ds < cs) << endl;
  113. cout << (cs < ds) << endl;
  114. cout << (cs < css) << endl;
  115. cout << (cs < css) << endl;
  116. } else if(n == 3) {
  117. cout << "Karticka total" << endl;
  118. KartickaAvtobus ds1(150,35,2);
  119. KartickaAvtobus ds2(100,80,5);
  120. KartickaAvtobus ds3(150,40,1);
  121. KarickaVoz cs1(15,false);
  122. KarickaVoz cs2(10,true);
  123. KarickaVoz cs3(20,true);
  124. Karticka** s = new Karticka*[6];
  125. s[0] = &ds1;
  126. s[1] = &ds2;
  127. s[2] = &ds3;
  128. s[3] = &cs1;
  129. s[4] = &cs2;
  130. s[5] = &cs3;
  131. cout<<AvtomatZaKarticki::total(s, 6);
  132. delete [] s;
  133. }
  134.  
  135. return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment