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 maxspeed;
- void copy1(const Automobile &a) {
- marka=new char[strlen(a.marka)+1];
- registracija=new int[5];
- strcpy(marka, a.marka);
- for(int i=0;i<5;i++)
- registracija[i]=a.registracija[i];
- maxspeed=a.maxspeed;
- }
- public:
- Automobile(){}
- Automobile(char *marka, int *registracija, int maxspeed)
- {
- this->marka = new char[strlen(marka)+1];
- strcpy(this->marka, marka);
- this->registracija = new int[5];
- for(int i = 0; i < 5; i++){
- this->registracija[i] = registracija[i];
- }
- this->maxspeed = maxspeed;
- }
- Automobile(const Automobile &a) {
- copy1(a);
- }
- Automobile &operator=(const Automobile &a) {
- if(this==&a) return *this;
- delete [] marka;
- delete [] registracija;
- copy1(a);
- return *this;
- }
- friend bool operator==(const Automobile &a, const Automobile &b) {
- int flag=0;
- for(int i=0;i<5;i++){
- if(a.registracija[i]==b.registracija[i]) flag=1;
- else flag=0;
- }
- if(flag==1)return true;
- else return false;
- }
- friend ostream &operator<<(ostream &out, Automobile &a) {
- int i;
- cout<<"Marka\t"<<a.marka<<"\tRegistracija[ ";
- for(i=0;i<4;i++){
- cout<<a.registracija[i]<<" ";
- }
- cout<<a.registracija[i]<<" ]"<<endl;
- return out;
- }
- int getMspeed() {
- return maxspeed;
- }
- char *getmarka() {
- return marka;
- }
- int *getregistracija() {
- return registracija;
- }
- void printreg() {
- int i;
- for(i=0;i<4;i++)
- cout<<registracija[i]<<" ";
- cout<<registracija[i];
- }
- ~Automobile(){
- delete [] marka;
- delete [] registracija;
- }
- };
- class RentACar{
- private:
- char ime[100];
- Automobile *a;
- int broj;
- void copy2(const RentACar &r){
- strcpy(this->ime,r.ime);
- this->broj=r.broj;
- this->a=new Automobile[r.broj];
- for(int i=0;i<r.broj;i++)
- a[i]=r.a[i];
- }
- public:
- RentACar(){}
- RentACar(char *ime){
- strcpy(this->ime, ime);
- broj=0;
- a=new Automobile[1];
- }
- RentACar(const RentACar &r){
- copy2(r);
- }
- RentACar &operator=(const RentACar &r) {
- if(this==&r) return *this;
- delete []a;
- copy2(r);
- return *this;
- }
- RentACar &operator+=(const Automobile &a) {
- Automobile *x=this->a;
- this->a=new Automobile[broj+1];
- for(int i=0;i<broj;i++)
- this->a[i]=x[i];
- delete []x;
- this->a[broj++]=a;
- return *this;
- }
- RentACar &operator-=(const Automobile &a) {
- Automobile *x=new Automobile[broj];
- int pom=0;
- for(int i=0;i<broj;i++)
- {
- if(!(this->a[i]==a)) {x[pom]=this->a[i]; pom++;}
- }
- delete []this->a;
- this->a=x;
- broj=pom;
- return *this;
- }
- void pecatiNadBrzina(int n){
- cout<<ime<<endl;
- for(int i=0;i<broj;i++)
- {
- if(a[i].getMspeed()>n)
- cout<<a[i]<<endl;
- }
- }
- ~RentACar(){ delete []a;}
- };
- 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