Advertisement
StefiIOE

Web Page

Apr 1st, 2019
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.42 KB | None | 0 0
  1.  #include<iostream>
  2.  #include<cstring>
  3.  using namespace std;
  4.  class WebPage{
  5.      private:
  6.      char url[100];
  7.      char *sodrzina;
  8.      public:
  9.      WebPage(){
  10.          char url='\0';
  11.          char sodrzina='0';
  12.      }
  13.      WebPage(char *url,char *sodrzina){
  14.          strcpy(this->url,url);
  15.          this ->sodrzina = new char[strlen(sodrzina)+1];
  16.          strcpy(this->sodrzina,sodrzina);
  17.      }
  18.      WebPage(const WebPage &p){
  19.       strcpy(this->url,p.url);
  20.          this ->sodrzina = new char[strlen(p.sodrzina)+1];
  21.          strcpy(this->sodrzina,p.sodrzina);
  22.        
  23.      }
  24.      char *getUrl(){
  25.          return url;
  26.      }
  27.      ~WebPage () {
  28.      delete [] sodrzina ;
  29.      }
  30.       WebPage&operator = (const WebPage &p){
  31.           if(this!=&p){
  32.          strcpy(this->url,p.url);
  33.          delete [] sodrzina ;
  34.          this ->sodrzina = new char[strlen(p.sodrzina)+1];
  35.          strcpy(this->sodrzina,p.sodrzina);
  36.              
  37.           }
  38.          
  39.           return *this;
  40.       }
  41.  
  42.       bool operator==(WebPage &p)
  43. {
  44.     return strcmp(url,p.url)==0;
  45. }
  46.  
  47.  };
  48. class WebServer{
  49.     private:
  50.     char ime[30];
  51.     WebPage *webpage;
  52.     int brojElemnti; //sama si go dodavam i moram sekogash da ja imam ovaa promenliva koga imam dinamichki alocirana niza od objekti
  53.     public:
  54.     WebServer(const char *ime=" ", WebPage *webpage=0,int brojElemnti=0){
  55.         strcpy(this->ime,ime);
  56.         this->webpage=new WebPage[brojElemnti];
  57.         for(int i=0;i<brojElemnti;i++){
  58.             this->webpage[i]=webpage[i];
  59.         }
  60.         this->brojElemnti=brojElemnti;
  61.     }
  62.     WebServer(const WebServer &s){
  63.         strcpy(this->ime,s.ime);
  64.         this->webpage=new WebPage[brojElemnti];
  65.         for(int i=0;i<brojElemnti;i++){
  66.             this->webpage[i]=s.webpage[i];
  67.         }
  68.         this->brojElemnti=s.brojElemnti;
  69.        
  70.     }
  71.   WebServer&operator = (const WebServer &s){
  72.       if(this!=&s)
  73.       {
  74.         strcpy(this->ime,s.ime);
  75.         delete []this -> webpage;
  76.         this->webpage=new WebPage[brojElemnti];
  77.         for(int i=0;i<brojElemnti;i++){
  78.             this->webpage[i]=s.webpage[i];
  79.         }
  80.         this->brojElemnti=s.brojElemnti;
  81.          
  82.       }
  83.       return *this;
  84.   }  
  85.   ~WebServer () {
  86.       delete [] webpage;
  87.   }
  88.   WebServer &operator+=(WebPage p)
  89. {
  90.     WebPage *tmp= new WebPage[brojElemnti+1];//samo rezerviram memorija
  91.     for(int i=0;i<brojElemnti;i++)
  92.     {
  93.         tmp[i]=webpage[i];// site elementi od niza[i ] kje se iskopiraat vo nizata tmp
  94.     }
  95.     tmp[brojElemnti++]=p;//na poslednoto mesto od tmp kje dodadam nova strana(objekt od klasata WebPage)
  96.     delete [] webpage;
  97.     webpage=tmp;
  98.     return *this;
  99. }
  100.  
  101. WebServer &operator-=(WebPage p)
  102. {
  103.     int novbrojac=0;
  104.     WebPage *tmp= new WebPage[brojElemnti];
  105.     for(int i=0;i<brojElemnti;i++)
  106.     {
  107.         if(!(webpage[i]==p))
  108.         tmp[novbrojac++]=webpage[i];
  109.     }
  110.     delete [] webpage;
  111.     webpage=tmp;
  112.     brojElemnti=novbrojac;
  113.     return *this;
  114. }
  115. void pecati(){
  116.         for(int i=0 ; i<brojElemnti;i++){
  117.             cout<<webpage[i].getUrl()<<endl;
  118.         }
  119. }
  120. };
  121.  
  122.  
  123. int main () {
  124. WebPage wp1 ("http://www.google.com", "The search engine");
  125. WebPage wp2 ("http://www.finki.ukim.mk", "FINKI");
  126. WebPage wp3 ("http://www.time.mk", "Site vesti");
  127. WebServer ws(" Server ");
  128. ws += wp1 ;
  129. ws += wp2 ;
  130. ws += wp3 ;
  131. ws.pecati ();
  132. ws-= wp3;
  133. ws.pecati ();
  134. return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement