Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Automobile
- {
- private:
- char* marka;
- int* registracija;
- int maxbrzina;
- public:
- // set i get metodi !
- int getMaxBrzina()
- {
- return maxbrzina;
- }
- Automobile() {} //default
- Automobile(char* m,int* r,int mb)//arguments
- {
- marka=new char[strlen(m)+1];
- strcpy(marka,m);
- registracija=new int[5];
- for(int i=0; i<5; i++)
- registracija[i]=r[i];
- maxbrzina=mb;
- }
- Automobile(const Automobile &a)//copy constructor
- {
- marka=new char[strlen(a.marka)+1];
- strcpy(marka,a.marka);
- registracija=new int[5];
- for(int i=0; i<5; i++)
- registracija[i]=a.registracija[i];
- maxbrzina=a.maxbrzina;
- }
- Automobile& operator= (const Automobile &a)//operator za dodeluvanje
- {
- if(this != &a)
- {
- delete[] marka;
- delete[] registracija;
- marka=new char[strlen(a.marka)+1];
- strcpy(marka,a.marka);
- registracija=new int[5];
- for(int i=0; i<5; i++)
- registracija[i]=a.registracija[i];
- maxbrzina=a.maxbrzina;
- }
- return *this;
- }
- ~Automobile()//destructor
- {
- delete[] marka;
- delete[] registracija;
- }
- bool operator== (const Automobile &A)//za sporedba
- {
- for(int i=0; i<5; i++)
- if(this->registracija[i]!=A.registracija[i])
- return false;
- return true;
- }
- friend ostream& operator<< (ostream &out, const Automobile &A)//format: Marka:ime Registracija:[x y z k l]
- {
- return out<<"Marka\t"<<A.marka<<"\tRegistracija[ "<<A.registracija[0]<<" "<<A.registracija[1]<<" "<<A.registracija[2]<<" "<<A.registracija[3]<<" "<<A.registracija[4]<<" ]"<<endl;
- }
- };
- class RentACar
- {
- private:
- char ime[100];
- Automobile* cars;
- int brCars;
- public:
- RentACar(char *ime)//constructor with one argument
- {
- strcpy(this->ime,ime);
- }
- RentACar() {}; //default constructor
- RentACar(char *ime,Automobile *cars,int brCars)//constructor with arguments
- {
- strcpy(this->ime,ime);
- this->brCars=brCars;
- this->cars=new Automobile[brCars];
- for(int i=0; i<brCars; i++)
- this->cars[i]=cars[i];
- }
- RentACar(const RentACar &a)//copy constructor
- {
- strcpy(ime,a.ime);
- brCars=a.brCars;
- cars=new Automobile[a.brCars];
- for(int i=0; i<brCars; i++)
- cars[i]=a.cars[i];
- }
- RentACar& operator= (const RentACar &a)//operator za dodeluvanje
- {
- if(this != &a)
- {
- strcpy(ime,a.ime);
- brCars=a.brCars;
- cars=new Automobile[a.brCars];
- for(int i=0; i<brCars; i++)
- cars[i]=a.cars[i];
- }
- return *this;
- }
- ~RentACar()//destructor
- {
- delete[] cars;
- }
- RentACar& operator+= (const Automobile &a)
- {
- if(brCars==0)
- {
- cars=new Automobile[1];
- cars[0]=a;
- brCars++;
- }
- else
- {
- Automobile *tmp = cars;
- cars=new Automobile[brCars+1];
- for(int i=0;i<brCars;i++)
- cars[i]=tmp[i];
- delete[] tmp;
- cars[brCars]=a;
- brCars++;
- }
- return *this;
- }
- RentACar& operator-= (const Automobile &a)
- {
- Automobile *tmp=new Automobile[brCars];
- int novBr=0;
- for(int i=0;i<brCars;i++)
- if(!(cars[i]==a))
- {
- tmp[novBr]=cars[i];
- novBr++;
- }
- delete[] cars;
- cars=tmp;
- brCars=novBr;
- return *this;
- }
- void pecatiNadBrzina (int max)
- {
- for(int i=0;i<brCars;i++)
- if(cars[i].getMaxBrzina()>max)
- cout<<cars[i]<<endl;
- }
- };
- int main()
- {
- RentACar agencija("FINKI-Car"); // instanciranje objekt
- 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;
- cout<<"FINKI-Car"<<endl;
- agencija.pecatiNadBrzina(150);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement