Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Avtomobil{
- private:
- char boja[20];
- char brend[20];
- char model[20];
- public:
- Avtomobil(){}
- Avtomobil(char boja[],char brend[20],char model[20]){
- strcpy(this->boja,boja);
- strcpy(this->brend,brend);
- strcpy(this->model,model);
- }
- Avtomobil &operator=(Avtomobil &novObjekt){
- if(this!=&novObjekt){
- strcpy(this->boja,novObjekt.boja);
- strcpy(this->brend,novObjekt.brend);
- strcpy(this->model,novObjekt.model);
- }
- return *this;
- }
- void print(){
- cout<<"Avtomobil: "<<model<<" "<<brend<<" "<<boja<<endl;
- }
- ~Avtomobil(){}
- };
- class ParkingPlac{
- private:
- char adresa[20];
- char *id;
- int cena;
- int zarabotka;
- Avtomobil *niza;
- // brojot na avtomobili
- int n;
- public:
- ParkingPlac(){
- id=new char[0];
- niza=new Avtomobil[0];
- n=0;
- }
- ParkingPlac(char adresa[],char *id,int cena){
- strcpy(this->adresa,adresa);
- this->id=new char[strlen(id)+1];
- strcpy(this->id,id);
- this->cena=cena;
- niza=new Avtomobil[0];
- n=0;
- this->zarabotka=0;
- }
- void parkirajVozilo(Avtomobil &novoVozilo){
- Avtomobil *tempNiza=new Avtomobil[n];
- for(int i=0;i<n;i++){
- // operator = povik
- tempNiza[i]=niza[i];
- }
- niza=new Avtomobil[n+1];
- for(int i=0;i<n;i++){
- niza[i]=tempNiza[i];
- }
- niza[n]=novoVozilo;
- n++;
- delete []tempNiza;
- }
- void pecatiParkiraniVozila(){
- cout<<"ParkingPlac: "<<adresa<<endl;
- for(int i=0;i<n;i++){
- niza[i].print();
- }
- }
- void pecati(){
- if(zarabotka!=0){
- cout<<id<<" "<<adresa<<" "<<zarabotka<<" denari"<<endl;
- }else{
- cout<<id<<" "<<adresa<<endl;
- }
- }
- void platiCasovi(int casovi){
- zarabotka+=casovi*cena;
- }
- bool daliIstaAdresa(ParkingPlac p){
- if(strcmp(this->adresa,p.adresa)==0){
- return true;
- }
- return false;
- }
- char* getId(){
- return id;
- }
- ~ParkingPlac(){
- delete []id;
- }
- };
- 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++){
- //cout << p[j].getId() << endl;
- 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);
- // isto so += operator
- najdobarPlac.parkirajVozilo(novAvtomobil);
- }
- if(brVozila != 0)
- najdobarPlac.pecatiParkiraniVozila();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement