Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class Automobile
  6. {
  7. private:
  8. char* marka;
  9. int* registracija;
  10. int maxbrzina;
  11.  
  12. public:
  13.  
  14. // set i get metodi !
  15. int getMaxBrzina()
  16. {
  17. return maxbrzina;
  18. }
  19.  
  20. Automobile() {} //default
  21.  
  22. Automobile(char* m,int* r,int mb)//arguments
  23. {
  24. marka=new char[strlen(m)+1];
  25. strcpy(marka,m);
  26. registracija=new int[5];
  27. for(int i=0; i<5; i++)
  28. registracija[i]=r[i];
  29. maxbrzina=mb;
  30. }
  31.  
  32. Automobile(const Automobile &a)//copy constructor
  33. {
  34. marka=new char[strlen(a.marka)+1];
  35. strcpy(marka,a.marka);
  36. registracija=new int[5];
  37. for(int i=0; i<5; i++)
  38. registracija[i]=a.registracija[i];
  39. maxbrzina=a.maxbrzina;
  40. }
  41.  
  42. Automobile& operator= (const Automobile &a)//operator za dodeluvanje
  43. {
  44. if(this != &a)
  45. {
  46. delete[] marka;
  47. delete[] registracija;
  48. marka=new char[strlen(a.marka)+1];
  49. strcpy(marka,a.marka);
  50. registracija=new int[5];
  51. for(int i=0; i<5; i++)
  52. registracija[i]=a.registracija[i];
  53. maxbrzina=a.maxbrzina;
  54. }
  55. return *this;
  56. }
  57.  
  58. ~Automobile()//destructor
  59. {
  60. delete[] marka;
  61. delete[] registracija;
  62. }
  63.  
  64. bool operator== (const Automobile &A)//za sporedba
  65. {
  66. for(int i=0; i<5; i++)
  67. if(this->registracija[i]!=A.registracija[i])
  68. return false;
  69. return true;
  70. }
  71.  
  72. friend ostream& operator<< (ostream &out, const Automobile &A)//format: Marka:ime Registracija:[x y z k l]
  73. {
  74. return out<<"Marka\t"<<A.marka<<"\tRegistracija[ "<<A.registracija[0]<<" "<<A.registracija[1]<<" "<<A.registracija[2]<<" "<<A.registracija[3]<<" "<<A.registracija[4]<<" ]"<<endl;
  75. }
  76. };
  77.  
  78. class RentACar
  79. {
  80. private:
  81. char ime[100];
  82. Automobile* cars;
  83. int brCars;
  84.  
  85. public:
  86. RentACar(char *ime)//constructor with one argument
  87. {
  88. strcpy(this->ime,ime);
  89. }
  90.  
  91. RentACar() {}; //default constructor
  92.  
  93. RentACar(char *ime,Automobile *cars,int brCars)//constructor with arguments
  94. {
  95. strcpy(this->ime,ime);
  96. this->brCars=brCars;
  97. this->cars=new Automobile[brCars];
  98. for(int i=0; i<brCars; i++)
  99. this->cars[i]=cars[i];
  100. }
  101.  
  102. RentACar(const RentACar &a)//copy constructor
  103. {
  104. strcpy(ime,a.ime);
  105. brCars=a.brCars;
  106. cars=new Automobile[a.brCars];
  107. for(int i=0; i<brCars; i++)
  108. cars[i]=a.cars[i];
  109. }
  110.  
  111.  
  112. RentACar& operator= (const RentACar &a)//operator za dodeluvanje
  113. {
  114. if(this != &a)
  115. {
  116. strcpy(ime,a.ime);
  117. brCars=a.brCars;
  118. cars=new Automobile[a.brCars];
  119. for(int i=0; i<brCars; i++)
  120. cars[i]=a.cars[i];
  121. }
  122. return *this;
  123. }
  124.  
  125. ~RentACar()//destructor
  126. {
  127. delete[] cars;
  128. }
  129.  
  130. RentACar& operator+= (const Automobile &a)
  131. {
  132. if(brCars==0)
  133. {
  134. cars=new Automobile[1];
  135. cars[0]=a;
  136. brCars++;
  137. }
  138. else
  139. {
  140. Automobile *tmp = cars;
  141. cars=new Automobile[brCars+1];
  142. for(int i=0;i<brCars;i++)
  143. cars[i]=tmp[i];
  144. delete[] tmp;
  145. cars[brCars]=a;
  146. brCars++;
  147. }
  148. return *this;
  149. }
  150.  
  151. RentACar& operator-= (const Automobile &a)
  152. {
  153. Automobile *tmp=new Automobile[brCars];
  154. int novBr=0;
  155. for(int i=0;i<brCars;i++)
  156. if(!(cars[i]==a))
  157. {
  158. tmp[novBr]=cars[i];
  159. novBr++;
  160. }
  161. delete[] cars;
  162. cars=tmp;
  163. brCars=novBr;
  164. return *this;
  165. }
  166.  
  167. void pecatiNadBrzina (int max)
  168. {
  169. for(int i=0;i<brCars;i++)
  170. if(cars[i].getMaxBrzina()>max)
  171. cout<<cars[i]<<endl;
  172.  
  173. }
  174. };
  175.  
  176. int main()
  177. {
  178. RentACar agencija("FINKI-Car"); // instanciranje objekt
  179. int n;
  180. cin>>n;
  181.  
  182. for (int i=0; i<n; i++)
  183. {
  184. char marka[100];
  185. int regisracija[5];
  186. int maximumBrzina;
  187.  
  188. cin>>marka;
  189.  
  190. for (int i=0; i<5; i++)
  191. cin>>regisracija[i];
  192.  
  193. cin>>maximumBrzina;
  194.  
  195. Automobile nov=Automobile(marka,regisracija,maximumBrzina);
  196.  
  197. //dodavanje na avtomobil
  198. agencija+=nov;
  199.  
  200. }
  201. //se cita grehsniot avtmobil, za koj shto avtmobilot so ista registracija treba da se izbrishe
  202. char marka[100];
  203. int regisracija[5];
  204. int maximumBrzina;
  205. cin>>marka;
  206. for (int i=0; i<5; i++)
  207. cin>>regisracija[i];
  208. cin>>maximumBrzina;
  209.  
  210. Automobile greshka=Automobile(marka,regisracija,maximumBrzina);
  211.  
  212. //brishenje na avtomobil
  213. agencija-=greshka;
  214.  
  215. cout<<"FINKI-Car"<<endl;
  216.  
  217. agencija.pecatiNadBrzina(150);
  218.  
  219. return 0;
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement