Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- using namespace std;
- class WebPage
- {
- private:
- char url[100];
- char *sodrzhina;
- public:
- WebPage(char *url="", char *sodrzhina="")
- {
- strcpy(this->url, url);
- this->sodrzhina = new char[strlen(sodrzhina)+1];
- strcpy(this->sodrzhina, 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;
- }
- WebPage &operator = (WebPage &wp)
- {
- strcpy(this->url, wp.url);
- delete[]this->sodrzhina;
- this->sodrzhina = new char(strlen(wp.sodrzhina)+1);
- strcpy(this->sodrzhina, wp.sodrzhina);
- return *this;
- }
- void pecati()
- {
- cout<<"URL: "<<this->url<<endl;
- cout<<"SODRZHINA: "<<this->sodrzhina<<endl;
- }
- };
- class WebServer
- {
- private:
- char ime[30];
- WebPage *wps;
- int n;
- public:
- WebServer(char *ime="", WebPage *wps=0, int n=0)
- {
- strcpy(this->ime, ime);
- this->wps = new WebPage[n];
- for(int i=0; i<this->n; i++)
- {
- this->wps[i]=wps[i];
- }
- this->n=n;
- }
- WebServer(const WebServer &ws)
- {
- strcpy(this->ime, ws.ime);
- this->wps=new WebPage[ws.n];
- for(int i=0; i<this->n; i++)
- {
- this->wps[i]=ws.wps[i];
- }
- this->n = ws.n;
- }
- void dodadi(WebPage wp)
- {
- WebPage *tmp;
- tmp = new WebPage[this->n];
- for(int i=0; i<this->n; i++)
- {
- tmp[i]=wps[i];
- }
- delete[]this->wps;
- this->wps = new WebPage[n+1];
- for(int i=0; i<this->n; i++)
- {
- this->wps[i]=tmp[i];
- }
- delete[]tmp;
- this->wps[this->n]=wp;
- this->n++;
- }
- void izbrishi(WebPage wp)
- {
- WebPage *tmp;
- int j;
- tmp = new WebPage[n-1];
- for(int i=0; i<this->n; i++)
- {
- if(wps[i].proverka(wp))
- continue;
- tmp[j] = this->wps[i];
- j++;
- }
- delete[]this->wps;
- this->wps = new WebPage[n-1];
- for(int i=0; i<this->n; i++)
- {
- this->wps[i]=tmp[j];
- }
- delete[]tmp;
- this->n--;
- }
- void sortLen()
- {
- for(int i=0; i<this->n; i++)
- {
- for(int j=i+1; j<this->n; j++)
- {
- if(strlen(wps[i].getUrl()) > strlen(wps[j].getUrl()))
- {
- WebPage t;
- t = wps[i];
- wps[i]=wps[j];
- wps[j]=t;
- }
- }
- }
- }
- void pecati()
- {
- for(int i=0; i<this->n; i++)
- this->wps[i].pecati();
- }
- void pecatiStraniciSoUrlNad(int threshold)
- {
- for(int i=0; i<this->n; i++)
- if(strlen(this->wps[i].getUrl())>threshold)
- this->wps[i].pecati();
- }
- };
- void sortAlpha(WebPage *wps, int n)
- {
- for(int i=0; i<n; i++)
- {
- for(int j=i+1; j<n; j++)
- {
- if(strcmp(wps[i].getUrl(), wps[j].getUrl()) > 0)
- {
- WebPage t;
- t=wps[i];
- wps[i]=wps[j];
- wps[j]=wps[i];
- }
- }
- }
- }
- int main()
- {
- int n;
- char url[100], sodrzina[100], ime[100];
- cout << "Vnesete broj na WebStranici vo serverot: ";
- cin >> n;
- WebPage stranici[n];
- for(int i=0;i<n;i++)
- {
- cout << endl << "Vnesete URL za " << i << "-ta stranica: ";
- cin >> url;
- cout << endl << "Vnesete SODRZINA za " << i << "-ta stranica: ";
- cin >> sodrzina;
- stranici[i] = WebPage(url,sodrzina);
- }
- cout << endl << "Vnesete ime za WebServerot: ";
- cin >> ime;
- WebServer ws(ime, stranici, n);
- ws.pecati();
- int opc;
- while(1)
- {
- cout << endl << "Izberi opcija(1 - dodadi web strana, 2 - izbrisi web strana, 3 - ispecati stranici, 4 - ispecati stranici so Url nad, 5 - prekin): ";
- cin >> opc;
- if(opc==1)
- {
- cout << endl << "Vnesi URL za stranicata sto sakas da ja dodades: ";
- cin >> url;
- cout << endl << "Vnesi SODRZINA za stranicata sto sakas da ja dodades: ";
- cin >> sodrzina;
- WebPage stranicaZaDodavanje(url,sodrzina);
- ws.dodadi(stranicaZaDodavanje);
- }else
- if(opc==2)
- {
- cout << endl << "Vnesi URL za stranicata sto sakas da ja izbrises: ";
- cin >> url;
- cout << endl << "Vnesi SODRZINA za stranicata sto sakas da ja izbrises: ";
- cin >> sodrzina;
- WebPage stranicaZaBrisenje(url,sodrzina);
- ws.izbrisi(stranicaZaBrisenje);
- }else
- if(opc==3)
- {
- ws.pecati();
- }else
- if(opc==4)
- {
- int threshold;
- cout << endl << "Vnesete threshold: ";
- cin >> threshold;
- ws.pecatiStraniciSoUrlNad(threshold);
- }else
- if(opc==5)
- {
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement