Advertisement
Guest User

Untitled

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