Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string.h>
- using namespace std;
- class Avtomobil
- {
- private:
- char boja[20];
- char brend[20];
- char model[20];
- public:
- Avtomobil(char* boja="",char* brend="", char* model="")
- {
- strcpy(this->boja,boja);
- strcpy(this->brend,brend);
- strcpy(this->model,model);
- }
- ~Avtomobil(){}
- Avtomobil& operator=(const Avtomobil &a)
- {
- if(this==&a)
- {
- return *this;
- }
- strcpy(this->boja,a.boja);
- strcpy(this->brend,a.brend);
- strcpy(this->model,a.model);
- return *this;
- }
- char* getBoja()
- {
- return boja;
- }
- char* getBrend()
- {
- return brend;
- }
- char* getModel()
- {
- return model;
- }
- };
- class ParkingPlac
- {
- private:
- char adresa[20];
- char *id;
- int cenacas;
- int zarabotka;
- Avtomobil *avtomobili;
- int brVozila;
- public:
- ParkingPlac(char* adresa="", const char* id="", int cenacas=0, int zarabotka=0,int brVozila=0, Avtomobil* avtomobili=0)
- {
- strcpy(this->adresa,adresa);
- this->cenacas=cenacas;
- this->zarabotka=zarabotka;
- this->id= new char[strlen(id)];
- strcpy(this->id,id);
- this->brVozila=brVozila;
- this->avtomobili=new Avtomobil[brVozila];
- }
- ParkingPlac(const ParkingPlac& p)
- {
- strcpy(this->adresa,p.adresa);
- this->cenacas=p.cenacas;
- this->zarabotka=p.zarabotka;
- this->id= new char[strlen(p.id)];
- strcpy(this->id,p.id);
- this->brVozila=p.brVozila;
- this->avtomobili=new Avtomobil[p.brVozila];
- for(int i=0;i<brVozila;i++)
- {
- avtomobili[i]=p.avtomobili[i];
- }
- }
- ~ParkingPlac()
- {
- delete [] id;
- delete [] avtomobili;
- }
- ParkingPlac& operator=(const ParkingPlac &pp)
- {
- if(this==&pp)
- {
- return *this;
- }
- strcpy(this->adresa,pp.adresa);
- this->cenacas=pp.cenacas;
- this->zarabotka=pp.zarabotka;
- delete [] this->id;
- this->id = new char[strlen(pp.id)];
- strcpy(this->id,pp.id);
- delete [] this->avtomobili;
- this->avtomobili= new Avtomobil[pp.brVozila];
- for(int i=0;i<brVozila;i++)
- {
- avtomobili[i]=pp.avtomobili[i];
- }
- return *this;
- }
- char* getId()
- {
- return id;
- }
- void pecati()
- {
- if(zarabotka!=0)
- {
- cout<<id<<" "<<adresa<<" - "<<zarabotka<<" denari"<<endl;
- }
- else
- {
- cout<<id<<" "<<adresa<<" "<<endl;
- }
- return;
- }
- void platiCasovi(int casovi)
- {
- zarabotka+=cenacas*casovi;
- }
- int daliIstaAdresa(ParkingPlac p)
- {
- if(strcmp(adresa,p.adresa)==0)
- return 1;
- return 0;
- }
- ParkingPlac& parkirajVozilo(Avtomobil& novoVozilo)
- {
- Avtomobil* temp = new Avtomobil[brVozila+1];
- for(int i=0;i<brVozila;i++)
- {
- temp[i]=avtomobili[i];
- }
- temp[brVozila]=novoVozilo;
- brVozila++;
- delete [] avtomobili;
- avtomobili=temp;
- return *this;
- }
- void pecatiParkiraniVozila()
- {
- cout<<"Vo parkingot se parkirani slednite vozila: "<<endl;
- for(int i=0;i<brVozila;i++)
- {
- cout<<i+1<<"."<<avtomobili[i].getBoja()<<" "<<avtomobili[i].getBrend()<<" "<<avtomobili[i].getModel()<<endl;
- }
- }
- };
- // вашиот код
- int main(){
- ParkingPlac p[100];
- int n,m;
- char adresa[50],id[50];
- int brojcasovi,cenacas;
- cin>>n;
- if(n > 0){
- for (int i=0;i<n;i++){
- cin.get();
- cin.getline(adresa,50);
- cin>>id>>cenacas;
- ParkingPlac edna(adresa,id,cenacas);
- p[i]=edna;
- }
- //plakjanje
- cin>>m;
- for (int i=0;i<m;i++){
- cin>>id>>brojcasovi;
- int findId=false;
- for (int j=0;j<m;j++){
- if (strcmp(p[j].getId(),id)==0){
- p[j].platiCasovi(brojcasovi);
- findId=true;
- }
- }
- if (!findId)
- cout<<"Ne e platen parking. Greshen ID."<<endl;
- }
- cout<<"========="<<endl;
- ParkingPlac pCentar("Cvetan Dimov","C10",80);
- for (int i=0;i<n;i++)
- if (p[i].daliIstaAdresa(pCentar))
- p[i].pecati();
- } else {
- ParkingPlac najdobarPlac("Mars", "1337", 1);
- int brVozila;
- cin >> brVozila;
- for(int i = 0; i < brVozila; ++i){
- char boja[20];
- char brend[20];
- char model[20];
- cin >> boja >> brend >> model;
- Avtomobil novAvtomobil(boja, brend, model);
- najdobarPlac.parkirajVozilo(novAvtomobil);
- }
- if(brVozila != 0)
- najdobarPlac.pecatiParkiraniVozila();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement