Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class WebPage
- {
- private:
- char url[100];
- char *sodrzhina;
- public:
- WebPage(char *url="", char *sodrzhina="") //default i konstruktor so argumenti zaedno
- {
- strcpy(this->url, url);
- this->sodzhina = new char[strlen(sodzhina+1)]; //alocijaranje nova memorija
- strcpy(this->sodzhina, sodrzhina);
- }
- WebPage(const WebPage &wp)
- {
- strcpy(this->url, wp.url);
- this->sodrzhina = new char[strlen(wp.sodrzhina+1)];
- strcpy(this->sodrzhina, wp.sodrzhina);
- }
- char *getUrl()
- {
- return this->url;
- }
- char *getSodrzhina()
- {
- return this->sodrzhina;
- }
- void setUrl(char *url)
- {
- strcpy(this->url, url);
- }
- void setSodrzhina(char *sodrzhina)
- {
- delete[]this->sodrzhina; //Веќе креиран објект со некоја вредност претходно во конструкторот, па ја бришеме истата
- this->sodrzhina = new char [strlen(sodrzhina+1)];
- strcpy(this->sodrzhina, sodrzhina);
- }
- bool proverka(WebPage wp)
- {
- if(strcmp(this->url, wp.url)==0 && strcmp(this->sodrzhina, wp.sodrzhina)==0)
- return true;
- return false;
- }
- }; // Крај class WebPage
- class WebServer
- {
- private:
- char ime[30];
- WebPage *wps; //листа од веб страници (динамички алоцирана низа од обjекти од класата WebPage)
- public:
- WebServer(char *ime="", WebPage *wps=0,int n=0)
- {
- strcpy(this->ime, ime);
- this->wps = new WebPage[n];
- for(int i=0; i<n; i++)
- {
- this->wps[i]=WebPage(wps[i]); //го повикуваме copy конструкторот од WebPage
- }
- }
- WebServer(const WebServer &ws)
- {
- strcpy(this->ime, ws.ime);
- this->wps = new WebPage[ws.n];
- for(int i=0; i<ws.n; i++)
- {
- this->wps[i]=WebPage(ws.wps[i]);
- }
- }
- // get i set
- WebPage *getWps()
- {
- return this->wps;
- }
- void setWps(WebPage *wps, int n) //n-секогаш кога имаме низа која не е char
- {
- delete[] this->wps; //меморијата претходно алоцирана со new WebPage[n], треба да се ослободи со delete[]
- this->wps = new WebPage[n];
- this->n = n;
- for(int i=0; i<n; i++)
- {
- this->wps[i].setUrl(wps[i].getUrl());
- this->wps[i].setSodrzhina(wps[i].getSodrzhina());
- }
- }
- char *getIme()
- {
- return this->ime;
- }
- void setIme(char *ime)
- {
- strcpy(this->ime, ime);
- }
- int getN()
- {
- return this->n;
- }
- void n(int n)
- {
- this->n=n;
- }
- void dodadi(WebPage wp)
- {
- WebPage *tmp;
- tmp = new WebPage[this->n];
- for(int i=0; i<n; i++)
- {
- tmp[i]=WebPage(this->wps[i]);
- }
- delete[] this->wps;
- this->wps = new WebPage[this->n+1];
- for(int i=0; i<this->n; i++)
- {
- this->wps=WebPage(tmp[i]);
- }
- delete [] tmp;
- this->wps[this->n] = WebPage(wp);
- this->n++;
- }
- void izbrishi(WebPage wp)
- {
- WebPage *tmp;
- tmp = new WebPage[this->n-1]; //gledame kolku elementi treba da iskopirame, zatoa n-1
- int j;
- for(int i=0; i<this->n; i++)
- {
- if(this->wps[i].proverka(wp))
- continue;
- tmp[j]=WebPage(this->wps[i]);
- j++;
- }
- delete [] this->wps;
- this->wps = new Webpage[this->n-1];
- for(int i=0; i<this->n-1; i++)
- {
- this->wps[i]=WebPage(tmp[j])
- }
- delete [] tmp;
- this->n--;
- }
- ~WebServer()
- {
- delete [] wps;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement