Advertisement
Guest User

Untitled

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