Advertisement
Guest User

asdadsddd

a guest
May 20th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class Transport {
  6. protected:
  7. char *destinacija;
  8. int cena;
  9. int km;
  10. public:
  11.  
  12. Transport(){}
  13. Transport(char *destinacija, int cena, int km){
  14. strcpy(this->destinacija,destinacija);
  15. this->cena=cena;
  16. this->km=km;
  17. }
  18.  
  19. Transport(const Transport &t){
  20. strcpy(this->destinacija,t.destinacija);
  21. this->cena=t.cena;
  22. this->km=t.km;
  23. }
  24.  
  25. int getCena(){
  26. return cena;
  27. }
  28.  
  29. char *getDestinacija(){
  30. return destinacija;
  31. }
  32.  
  33. bool operator <(Transport &tr){
  34. if(this->km<tr.km){
  35. return true;
  36. }
  37. return false;
  38.  
  39. }
  40.  
  41. virtual int cenaTransport() = 0;
  42.  
  43. virtual void pecati()=0;
  44.  
  45. };
  46.  
  47. class AvtomobilTransport : public Transport{
  48.  
  49. protected:
  50. bool platensofer;
  51. public:
  52. AvtomobilTransport(){}
  53. AvtomobilTransport(char *destinacija, int cena, int km, bool platensofer):Transport(destinacija,cena,km){
  54. cout << "tri\n";
  55. this->platensofer=platensofer;
  56.  
  57. }
  58.  
  59. int cenaTransport(){
  60. int suma=0;
  61. if(platensofer==true){
  62. suma = getCena() + getCena()*0.2;
  63.  
  64. }
  65. return suma;
  66.  
  67. }
  68.  
  69. void pecati(){
  70. cout<<destinacija<<" "<< km<<" "<<cenaTransport()<<endl;
  71.  
  72. }
  73.  
  74.  
  75. };
  76.  
  77. class KombeTransport : public Transport{
  78.  
  79. protected:
  80. int brluge;
  81. public:
  82. KombeTransport(){}
  83. KombeTransport(char *destinacija, int cena, int km, int brluge):Transport(destinacija,cena,km){
  84. cout << "tri\n";
  85. this->brluge=brluge;
  86.  
  87. }
  88. int cenaTransport(){
  89. int suma=0;
  90. suma = getCena() - brluge*200;
  91. return suma;
  92. }
  93.  
  94. void pecati(){
  95. cout<<getDestinacija()<<" "<< km<<" "<<cenaTransport()<<endl;
  96.  
  97. }
  98.  
  99.  
  100. };
  101.  
  102. void pecatiPoloshiPonudi(Transport **t, int n,Transport& a){
  103.  
  104. for(int i=0;i<n;i++){
  105.  
  106. if(t[i]->cenaTransport()> a.cenaTransport()){
  107. t[i] -> pecati();
  108.  
  109. }
  110. }
  111.  
  112. }
  113.  
  114.  
  115.  
  116. int main(){
  117.  
  118. char destinacija[20];
  119. int tip,cena,rastojanie,lugje;
  120. bool shofer;
  121. int n;
  122. cin>>n;
  123. Transport **ponudi;
  124. ponudi=new Transport *[n];
  125.  
  126. for (int i=0;i<n;i++){
  127.  
  128. cin>>tip>>destinacija>>cena>>rastojanie;
  129. if (tip==1) {
  130. cin>>shofer;
  131. ponudi[i]=new AvtomobilTransport(destinacija,cena,rastojanie,shofer);
  132.  
  133. }
  134. else {
  135. cin>>lugje;
  136. ponudi[i]=new KombeTransport(destinacija,cena,rastojanie,lugje);
  137. }
  138.  
  139.  
  140. }
  141.  
  142. AvtomobilTransport nov("Ohrid",2000,600,false);
  143. pecatiPoloshiPonudi(ponudi,n,nov);
  144.  
  145. for (int i=0;i<n;i++) delete ponudi[i];
  146. delete [] ponudi;
  147. return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement