Advertisement
frusso1337

Lab 4-01 Parking

Mar 19th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include<iostream>
  2. //вашиот код
  3. #include<cstring>
  4. using namespace std;
  5. class ParkingPlac
  6. {
  7. private:
  8.     char adress[20];
  9.     char *id;
  10.     int priceph;
  11.     int profit;
  12. public:
  13.     ParkingPlac(char *adress=" ",char *id=" ",int priceph=0)
  14.     {
  15.         this->priceph = priceph;
  16.         strncpy(this->adress,adress,20);
  17.         this->id = new char[strlen(id)];
  18.         strncpy(this->id,id,strlen(id));
  19.         this->profit=0;
  20.     }
  21.     ParkingPlac(const ParkingPlac &p)
  22.     {
  23.         strncpy(this->adress,p.adress,20);
  24.         this->priceph = p.priceph;
  25.         this->profit = p.profit;
  26.         this->id=new char[strlen(p.id)];
  27.         strncpy(this->id,p.id,strlen(p.id));
  28.     }
  29.     ~ParkingPlac()
  30.     {
  31.         delete [] id;
  32.     }
  33.     ParkingPlac& operator=(const ParkingPlac& p)
  34.     {
  35.         strncpy(adress,p.adress,20);
  36.         strncpy(id,p.id,strlen(p.id));
  37.         profit=p.profit;
  38.         priceph=p.priceph;
  39.         return *this;
  40.     }
  41.     void platiCasovi(int h)
  42.     {
  43.         profit+=h*priceph;
  44.     }
  45.     bool daliIstaAdresa(ParkingPlac p)
  46.     {
  47.         if(strcmp(adress,p.adress)==0) return true;
  48.         else return false;
  49.     }
  50.     char* getId()
  51.     {
  52.         return id;
  53.     }
  54.     void pecati()
  55.     {
  56.         cout<<id<<" "<<adress;
  57.         if(profit!=0) cout<<" - "<<profit<<" denari"<<endl;
  58.     }
  59. };
  60. int main()
  61. {
  62.     ParkingPlac p[100];
  63.     int n,m;
  64.     char adresa[50],id[50];
  65.     int brojcasovi,cenacas;
  66.     cin>>n;
  67.     for (int i=0; i<n; i++)
  68.     {
  69.         cin.get();
  70.         cin.getline(adresa,50);
  71.         cin>>id>>cenacas;
  72.         ParkingPlac edna(adresa,id,cenacas);
  73. //povik na operatorot =
  74.         p[i]=edna;
  75.     }
  76. //plakjanje
  77.     cin>>m;
  78.     for (int i=0; i<m; i++)
  79.     {
  80.         cin>>id>>brojcasovi;
  81.         int findId=false;
  82.         for (int j=0; j<n; j++)
  83.         {
  84.             if (strcmp(p[j].getId(),id)==0)
  85.             {
  86.                 p[j].platiCasovi(brojcasovi);
  87.                 findId=true;
  88.             }
  89.         }
  90.         if (!findId)
  91.             cout<<"Ne e platen parking. Greshen ID."<<endl;
  92.     }
  93.     cout<<"========="<<endl;
  94.     ParkingPlac pCentar("Cvetan Dimov","C10",80);
  95.     for (int i=0; i<n; i++)
  96.         if (p[i].daliIstaAdresa(pCentar))
  97.             p[i].pecati();
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement