Advertisement
Guest User

Transport

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