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 *brand;
- int *reg;
- int max;
- public:
- Automobile(){}
- Automobile(char*b, int*r,int m)
- {
- brand=new char[strlen(b)+1];
- strcpy(brand,b);
- reg=new int[5];
- for(int i=0;i<5;i++)
- {
- reg[i]=r[i];
- }
- max=m;
- }
- void setBrand (char*b)
- {
- delete [] brand;
- brand=new char[strlen(b)+1];
- strcpy(brand,b);
- }
- char *getBrand()
- {
- return brand;
- }
- void setReg (int *r)
- {
- delete [] reg;
- reg=new int [5];
- for(int i=0; i<5; i++) {
- reg[i]=r[i];
- }
- }
- int* getReg()
- {
- return reg;
- }
- Automobile(Automobile &a)
- {
- delete[]brand;
- delete[]reg;
- brand=new char[strlen(a.brand)+1];
- strcpy(brand,a.brand);
- reg=new int[5];
- for(int i=0;i<5;i++)
- {
- reg[i]=a.reg[i];
- }
- max=a.max;
- }
- void setMax(int m)
- {
- max=m;
- }
- int getMax(){return max;}
- friend ostream& operator<<(ostream& output, Automobile& a)
- {
- return output<<"Brand: "<<a.brand<<"Registration: "<<endl;
- for(int i=0;i<5;i++)
- {
- output<<a.reg[i]<<" ";
- }
- output<<endl;
- return output;
- }
- bool operator==(const Automobile &a)
- {
- for(int i=0;i<5;i++)
- {
- if(reg[i]!=a.reg[i])
- {
- return false;
- }
- }
- return 1;
- }
- ~Automobile()
- {
- delete [] brand;
- delete [] reg;
- }
- };
- class RentACar {
- private:
- char name[100];
- Automobile *automobiles;
- int No;
- public:
- RentACar(char*n)
- {
- strcpy(name,n);
- automobiles=new Automobile[0];
- No=0;
- }
- RentACar& operator+=(Automobile&a)
- {
- automobiles[No].setBrand(a.getBrand());
- for(int i=0;i<5;i++)
- {
- automobiles[No].setReg(a.getReg());
- }
- automobiles[No].setMax(a.getMax());
- No++;
- return *this;
- }
- /*
- NEDOVRSHENA
- RentACar& operator-=(Automobile&a)
- {
- automobiles[No].setBrand(a.getBrand());
- for(int i=0;i<5;i++)
- {
- automobiles[No].setReg(a.getReg());
- }
- automobiles[No].setMax(a.getMax());
- No--;
- }*/
- ~RentACar(){delete [] automobiles;}
- };
- 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.pecatiNadBrzina(150);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement