Advertisement
Guest User

Untitled

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