Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Automobile {
- protected:
- char *brand;
- int registration[5];
- int max;
- void copy(const Automobile &a)
- {
- this->brand=new char[strlen(a.brand)+1];
- strcpy(this->brand,a.brand);
- for(int i = 0; i < 5 ; i ++)
- {
- this->registration[i]=a.registration[i];
- }
- this->max=a.max;
- }
- public:
- Automobile()
- {
- max=0;
- brand=new char[0];
- for(int i = 1 ; i <=5 ; i ++)
- {
- registration[i-1]=i;
- }
- }
- Automobile(char *brand , int *registration , int max)
- {
- this->brand=new char[strlen(brand)+1];
- strcpy(this->brand,brand);
- for(int i = 0; i < 5 ; i ++)
- {
- this->registration[i]=registration[i];
- }
- this->max=max;
- }
- Automobile(const Automobile &a)
- {
- copy(a);
- }
- Automobile &operator=(const Automobile &a)
- {
- if(this!=&a)
- {
- delete [] brand;
- copy(a);
- }
- return *this;
- }
- bool operator==(const Automobile &a)
- {
- for(int i = 0 ; i < 5 ; i ++)
- {
- if(registration[i]!=a.registration[i])
- return false;
- }
- return true;
- }
- friend ostream &operator<<(ostream &out, const Automobile &a)
- {
- out<<"Marka\t"<<a.brand<<"\tRegistracija[ ";
- for(int i = 0 ; i < 5 ; i ++)
- {
- out<<a.registration[i]<<" ";
- }
- out<<"]";
- return out;
- }
- ~Automobile (){delete [] brand ; }
- int getMax(){return this->max;}
- };
- class RentACar{
- protected:
- char name [100];
- Automobile *automobile;
- int n ;
- void copy(const RentACar &r)
- {
- strcpy(this->name,r.name);
- this->automobile=new Automobile[r.n];
- for(int i = 0 ; i < n ; i++)
- {
- this->automobile[i]=r.automobile[i];
- }
- this->n=r.n;
- }
- public:
- RentACar(char*name="")
- {
- strcpy(this->name,name);
- n=0;
- automobile = new Automobile[0];
- }
- RentACar(const RentACar &r)
- {
- copy(r);
- }
- RentACar &operator=(const RentACar &r)
- {
- if(this!=&r)
- {
- delete [] automobile;
- copy(r);
- }
- return *this;
- }
- RentACar &operator+=(const Automobile &a)
- {
- Automobile *tmp=new Automobile[n+1];
- for(int i = 0 ; i < n ; i ++)
- {
- tmp[i]=automobile[i];
- }
- tmp[n]=a;
- n++;
- delete []automobile;
- automobile=tmp;
- return *this;
- }
- RentACar &operator-=(const Automobile &a) {
- int count = 0;
- for(int i = 0 ; i < n ; i ++) {
- if(automobile[i]==a) {
- count++;
- }
- }
- if(count==0) {
- return *this;
- }
- Automobile *tmp= new Automobile[n-count];
- int j=0 ;
- for(int i = 0 ; i < n ; i ++) {
- if(!(automobile[i]==a)) {
- tmp[j]=automobile[i];
- j++;
- }
- }
- delete [] automobile;
- automobile=tmp;
- n-=count;
- return *this;
- }
- void printWithSpeedOver(int max)
- {
- cout<<name<<endl;
- for(int i = 0 ; i < n ; i ++)
- {
- if(automobile[i].getMax()>max)
- cout<<automobile[i];
- }
- }
- };
- int main()
- {
- RentACar agencija("FINKI-Car");
- int n;
- cin>>n;
- for (int i=0;i<n;i++)
- {
- char marka[100];
- int regisracija[5];
- int maximumBrzina;
- cin>>marka;
- for (int i=0;i<5;i++)
- cin>>regisracija[i];
- cin>>maximumBrzina;
- Automobile nov=Automobile(marka,regisracija,maximumBrzina);
- //dodavanje na avtomobil
- agencija+=nov;
- }
- //se cita grehsniot avtmobil, za koj shto avtmobilot so ista registracija treba da se izbrishe
- char marka[100];
- int regisracija[5];
- int maximumBrzina;
- cin>>marka;
- for (int i=0;i<5;i++)
- cin>>regisracija[i];
- cin>>maximumBrzina;
- Automobile greshka=Automobile(marka,regisracija,maximumBrzina);
- //brishenje na avtomobil
- agencija-=greshka;
- agencija.printWithSpeedOver(150);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement