Advertisement
alexaC

Untitled

Mar 29th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class Automobile {
  6. private:
  7. char *brand;
  8. int *reg;
  9. int max;
  10. public:
  11. Automobile(){}
  12. Automobile(char*b, int*r,int m)
  13. {
  14. brand=new char[strlen(b)+1];
  15. strcpy(brand,b);
  16. reg=new int[5];
  17. for(int i=0;i<5;i++)
  18. {
  19. reg[i]=r[i];
  20. }
  21. max=m;
  22. }
  23. void setBrand (char*b)
  24. {
  25. delete [] brand;
  26. brand=new char[strlen(b)+1];
  27. strcpy(brand,b);
  28. }
  29. char *getBrand()
  30. {
  31. return brand;
  32. }
  33. void setReg (int *r)
  34. {
  35. delete [] reg;
  36. reg=new int [5];
  37. for(int i=0; i<5; i++) {
  38. reg[i]=r[i];
  39. }
  40. }
  41. int* getReg()
  42. {
  43. return reg;
  44. }
  45. Automobile(Automobile &a)
  46. {
  47. delete[]brand;
  48. delete[]reg;
  49. brand=new char[strlen(a.brand)+1];
  50. strcpy(brand,a.brand);
  51. reg=new int[5];
  52. for(int i=0;i<5;i++)
  53. {
  54. reg[i]=a.reg[i];
  55. }
  56. max=a.max;
  57. }
  58. void setMax(int m)
  59. {
  60. max=m;
  61. }
  62. int getMax(){return max;}
  63. friend ostream& operator<<(ostream& output, Automobile& a)
  64. {
  65. return output<<"Brand: "<<a.brand<<"Registration: "<<endl;
  66. for(int i=0;i<5;i++)
  67. {
  68. output<<a.reg[i]<<" ";
  69. }
  70. output<<endl;
  71. return output;
  72. }
  73. bool operator==(const Automobile &a)
  74. {
  75. for(int i=0;i<5;i++)
  76. {
  77. if(reg[i]!=a.reg[i])
  78. {
  79. return false;
  80. }
  81. }
  82. return 1;
  83. }
  84. ~Automobile()
  85. {
  86. delete [] brand;
  87. delete [] reg;
  88. }
  89. };
  90. class RentACar {
  91. private:
  92. char name[100];
  93. Automobile *automobiles;
  94. int No;
  95. public:
  96. RentACar(char*n)
  97. {
  98. strcpy(name,n);
  99. automobiles=new Automobile[0];
  100. No=0;
  101.  
  102. }
  103. RentACar& operator+=(Automobile&a)
  104. {
  105. automobiles[No].setBrand(a.getBrand());
  106. for(int i=0;i<5;i++)
  107. {
  108. automobiles[No].setReg(a.getReg());
  109. }
  110. automobiles[No].setMax(a.getMax());
  111. No++;
  112. return *this;
  113. }
  114. /*
  115. NEDOVRSHENA
  116. RentACar& operator-=(Automobile&a)
  117. {
  118. automobiles[No].setBrand(a.getBrand());
  119. for(int i=0;i<5;i++)
  120. {
  121. automobiles[No].setReg(a.getReg());
  122. }
  123. automobiles[No].setMax(a.getMax());
  124. No--;
  125.  
  126. }*/
  127. ~RentACar(){delete [] automobiles;}
  128. };
  129.  
  130. int main() {
  131. RentACar agencija("FINKI-Car");
  132. int n;
  133. cin>>n;
  134.  
  135. for (int i=0; i<n; i++) {
  136. char marka[100];
  137. int regisracija[5];
  138. int maximumBrzina;
  139.  
  140. cin>>marka;
  141.  
  142. for (int i=0; i<5; i++)
  143. cin>>regisracija[i];
  144.  
  145. cin>>maximumBrzina;
  146.  
  147. Automobile nov=Automobile(marka,regisracija,maximumBrzina);
  148.  
  149. //dodavanje na avtomobil
  150. agencija+=nov;
  151.  
  152. }
  153. //se cita grehsniot avtmobil, za koj shto avtmobilot so ista registracija treba da se izbrishe
  154. char marka[100];
  155. int regisracija[5];
  156. int maximumBrzina;
  157. cin>>marka;
  158. for (int i=0; i<5; i++)
  159. cin>>regisracija[i];
  160. cin>>maximumBrzina;
  161.  
  162. Automobile greshka=Automobile(marka,regisracija,maximumBrzina);
  163.  
  164. //brishenje na avtomobil
  165. //agencija-=greshka;
  166.  
  167. //agencija.pecatiNadBrzina(150);
  168.  
  169. return 0;
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement