Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.83 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3. using namespace std;
  4. class Avtomobil
  5. {
  6.     private:
  7.     char boja[20];
  8.     char brend[20];
  9.     char model[20];
  10.     public:
  11.     Avtomobil(char* boja="",char* brend="", char* model="")
  12.     {
  13.         strcpy(this->boja,boja);
  14.         strcpy(this->brend,brend);
  15.         strcpy(this->model,model);
  16.     }
  17.     ~Avtomobil(){}
  18.     Avtomobil& operator=(const Avtomobil &a)
  19.     {
  20.         if(this==&a)
  21.         {
  22.             return *this;
  23.         }
  24.         strcpy(this->boja,a.boja);
  25.         strcpy(this->brend,a.brend);
  26.         strcpy(this->model,a.model);
  27.         return *this;  
  28.     }
  29.     char* getBoja()
  30.     {
  31.         return boja;
  32.     }
  33.     char* getBrend()
  34.     {
  35.         return brend;
  36.     }
  37.     char* getModel()
  38.     {
  39.         return model;
  40.     }
  41. };
  42. class ParkingPlac
  43. {
  44.     private:
  45.     char adresa[20];
  46.     char *id;
  47.     int cenacas;
  48.     int zarabotka;
  49.     Avtomobil *avtomobili;
  50.     int brVozila;
  51.     public:
  52.     ParkingPlac(char* adresa="", const char* id="", int cenacas=0, int zarabotka=0,int brVozila=0, Avtomobil* avtomobili=0)
  53.     {
  54.         strcpy(this->adresa,adresa);
  55.         this->cenacas=cenacas;
  56.         this->zarabotka=zarabotka;
  57.         this->id= new char[strlen(id)];
  58.         strcpy(this->id,id);
  59.         this->brVozila=brVozila;
  60.         this->avtomobili=new Avtomobil[brVozila];
  61.     }
  62.     ParkingPlac(const ParkingPlac& p)
  63.     {
  64.         strcpy(this->adresa,p.adresa);
  65.         this->cenacas=p.cenacas;
  66.         this->zarabotka=p.zarabotka;
  67.         this->id= new char[strlen(p.id)];
  68.         strcpy(this->id,p.id);
  69.         this->brVozila=p.brVozila;
  70.         this->avtomobili=new Avtomobil[p.brVozila];
  71.         for(int i=0;i<brVozila;i++)
  72.         {
  73.             avtomobili[i]=p.avtomobili[i];
  74.         }
  75.     }
  76.     ~ParkingPlac()
  77.     {
  78.         delete [] id;
  79.         delete [] avtomobili;
  80.     }
  81.     ParkingPlac& operator=(const ParkingPlac &pp)
  82.     {
  83.         if(this==&pp)
  84.         {
  85.             return *this;
  86.         }
  87.         strcpy(this->adresa,pp.adresa);
  88.         this->cenacas=pp.cenacas;
  89.         this->zarabotka=pp.zarabotka;
  90.         delete [] this->id;
  91.         this->id = new char[strlen(pp.id)];
  92.         strcpy(this->id,pp.id);
  93.         delete [] this->avtomobili;
  94.         this->avtomobili= new Avtomobil[pp.brVozila];
  95.         for(int i=0;i<brVozila;i++)
  96.         {
  97.             avtomobili[i]=pp.avtomobili[i];
  98.         }
  99.         return *this;  
  100.     }
  101.     char* getId()
  102.     {
  103.         return id;
  104.     }
  105.     void pecati()
  106.     {
  107.         if(zarabotka!=0)
  108.         {
  109.             cout<<id<<" "<<adresa<<" - "<<zarabotka<<" denari"<<endl;
  110.         }
  111.         else
  112.         {
  113.             cout<<id<<" "<<adresa<<" "<<endl;
  114.         }
  115.         return;
  116.     }
  117.     void platiCasovi(int casovi)
  118.     {
  119.         zarabotka+=cenacas*casovi;
  120.     }
  121.     int daliIstaAdresa(ParkingPlac p)
  122.     {
  123.         if(strcmp(adresa,p.adresa)==0)
  124.             return 1;
  125.         return 0;
  126.     }
  127.     ParkingPlac& parkirajVozilo(Avtomobil& novoVozilo)
  128.     {
  129.         Avtomobil* temp = new Avtomobil[brVozila+1];
  130.         for(int i=0;i<brVozila;i++)
  131.         {
  132.             temp[i]=avtomobili[i];
  133.         }
  134.         temp[brVozila]=novoVozilo;
  135.         brVozila++;
  136.         delete [] avtomobili;
  137.         avtomobili=temp;
  138.         return *this;
  139.     }
  140.     void pecatiParkiraniVozila()
  141.     {
  142.         cout<<"Vo parkingot se parkirani slednite vozila: "<<endl;
  143.         for(int i=0;i<brVozila;i++)
  144.         {
  145.             cout<<i+1<<"."<<avtomobili[i].getBoja()<<" "<<avtomobili[i].getBrend()<<" "<<avtomobili[i].getModel()<<endl;
  146.         }
  147.     }
  148. };
  149. // вашиот код
  150.  
  151. int main(){
  152.  
  153.     ParkingPlac p[100];
  154.     int n,m;
  155.     char adresa[50],id[50];
  156.     int brojcasovi,cenacas;
  157.     cin>>n;
  158.     if(n > 0){
  159.  
  160.  
  161.         for (int i=0;i<n;i++){
  162.             cin.get();
  163.             cin.getline(adresa,50);
  164.             cin>>id>>cenacas;
  165.            
  166.             ParkingPlac edna(adresa,id,cenacas);
  167.            
  168.             p[i]=edna;
  169.         }
  170.         //plakjanje
  171.         cin>>m;
  172.         for (int i=0;i<m;i++){
  173.  
  174.             cin>>id>>brojcasovi;
  175.            
  176.             int findId=false;
  177.             for (int j=0;j<m;j++){
  178.                 if (strcmp(p[j].getId(),id)==0){
  179.                     p[j].platiCasovi(brojcasovi);
  180.                     findId=true;
  181.                 }
  182.             }
  183.             if (!findId)
  184.             cout<<"Ne e platen parking. Greshen ID."<<endl;
  185.         }
  186.  
  187.         cout<<"========="<<endl;
  188.         ParkingPlac pCentar("Cvetan Dimov","C10",80);
  189.         for (int i=0;i<n;i++)
  190.             if (p[i].daliIstaAdresa(pCentar))
  191.                 p[i].pecati();
  192.     } else {
  193.  
  194.         ParkingPlac najdobarPlac("Mars", "1337", 1);
  195.         int brVozila;
  196.         cin >> brVozila;
  197.         for(int i = 0; i < brVozila; ++i){
  198.  
  199.             char boja[20];
  200.             char brend[20];
  201.             char model[20];
  202.  
  203.             cin >> boja >> brend >> model;
  204.             Avtomobil novAvtomobil(boja, brend, model);
  205.             najdobarPlac.parkirajVozilo(novAvtomobil);
  206.         }
  207.         if(brVozila != 0)
  208.         najdobarPlac.pecatiParkiraniVozila();
  209.  
  210.     }
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement