Advertisement
Guest User

Website

a guest
Mar 26th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. class WebPage
  5. {
  6.     char url[100];
  7.     char *sodrzina;
  8. public:
  9.     WebPage(char *url,char *sodrzina)
  10.     {
  11.         strcpy(this->url,url);
  12.         this->sodrzina=new char[strlen(sodrzina)+1];
  13.         strcpy(this->sodrzina,sodrzina);
  14.     }
  15.     WebPage()
  16.     {
  17.         strcpy(this->url,"");
  18.         this->sodrzina=new char[0];
  19.         strcpy(this->sodrzina,"");
  20.    
  21.     }
  22.     WebPage(const WebPage &wp)
  23.     {
  24.         strcpy(this->url,wp.url);
  25.         this->sodrzina=new char[strlen(wp.sodrzina)+1];
  26.         strcpy(this->sodrzina,wp.sodrzina);
  27.     }
  28.     char* getUrl()
  29.     {
  30.         return this->url;
  31.     }
  32.     char* getSodrzina()
  33.     {
  34.         return this->sodrzina;
  35.     }
  36.     void setUrl(char *url)
  37.     {
  38.         strcpy(this->url,url);
  39.  
  40.     }
  41.     void setSodrzina(char *sodrzina)
  42.     {
  43.         delete []this->sodrzina;
  44.         this->sodrzina=new char[strlen(sodrzina)+1];
  45.         strcpy(this->sodrzina,sodrzina);
  46.  
  47.  
  48.     }
  49.     bool Proverka(WebPage wpp)
  50.     {
  51.         if((strcmp(this->url,wpp.url)==0)&&(strcmp(this->sodrzina,wpp.sodrzina)==0))
  52.             return true;
  53.         else
  54.             return false;
  55.     }
  56.     void pecati()
  57.     {
  58.         cout<<this->url;
  59.         cout<<this->sodrzina;
  60.     }
  61. };
  62. class WebServer
  63. {
  64.     char ime[30];
  65.     WebPage *wp;
  66.     int count;
  67. public:
  68.     WebServer()
  69.     {
  70.         strcpy(this->ime,"");
  71.         this->count=0;
  72.         this->wp=new WebPage[0];
  73.     }
  74.     WebServer(char *ime,WebPage *wp,int count)
  75.     {
  76.         strcpy(this->ime,ime);
  77.         this->count=count;
  78.         this->wp=new WebPage[count];
  79.         for(int i=0;i<count;i++)
  80.         {
  81.             this->wp[i]=wp[i];
  82.         }
  83.         cout<<"Serverot e konstruiran"<<endl;
  84.     }
  85.     WebServer(const WebServer &ws)
  86.     {
  87.         strcpy(this->ime,ws.ime);
  88.         this->count=ws.count;
  89.         this->wp=new WebPage[count];
  90.         for(int i=0;i<count;i++)
  91.         {
  92.             this->wp[i]=ws.wp[i];
  93.         }
  94.     }
  95.     void Dodadi(WebPage wpp)
  96.     {
  97.         WebPage *temp;
  98.         temp=new WebPage[this->count];
  99.         for(int i=0;i<count;i++)
  100.         {
  101.             temp[i]=WebPage(this->wp[i]);
  102.         }
  103.         delete []this->wp;
  104.         this->wp=new WebPage[this->count+1];
  105.         for(int i=0;i<count;i++)
  106.         {
  107.             this->wp[i]=temp[i];
  108.  
  109.         }
  110.         delete []temp;
  111.         this->wp[count]=WebPage(wpp);
  112.         count++;
  113.     }
  114.     void Izbrisi(WebPage wpp)
  115.     {
  116.         WebPage *temp;
  117.         int j=0;
  118.         temp=new WebPage[count-1];
  119.         for(int i=0;i<count;i++)
  120.         {
  121.             if(this->wp[i].Proverka(wpp))
  122.              continue;
  123.             else
  124.             {
  125.                 temp[j]=this->wp[i];
  126.             }
  127.         }
  128.         delete []wp;
  129.         this->count--;
  130.         this->wp=new WebPage[count];
  131.         for(int i=0;i<count;i++)
  132.         {
  133.             this->wp[i]=temp[i];
  134.         }
  135.         delete []temp;
  136.     }
  137.     void Pecati()
  138.     {
  139.         for(int i=0;i<count;i++)
  140.         {
  141.             wp[i].pecati();
  142.         }
  143.     }
  144.     void pecatiStranicisoUrl(int threshold)
  145.     {
  146.         for(int i=0;i<this->count;i++)
  147.         {
  148.             if(strlen(this->wp[i].getUrl())>threshold)
  149.             {
  150.                 this->wp[i].pecati();
  151.             }
  152.         }
  153.     }
  154. };
  155. int main()
  156. {
  157.  
  158.     char *sodrzina,url[100];
  159.     char ime[30];
  160.     cout<<"Vnesete ime za web serverot"<<endl;
  161.     cin>>ime;
  162.     WebPage *wp;
  163.     cout<<"Vnesete broj na stranici"<<endl;
  164.     int count;
  165.     cin>>count;
  166.     for (int i=0;i<count;i++)
  167.     {
  168.         cout<<"Vnesete sodrzina i url za wp"<<endl;
  169.         cin>>sodrzina;
  170.         cin>>url;
  171.         wp[i]=WebPage(url,sodrzina);
  172.     }
  173.     WebServer ws(ime,wp,count);
  174.     char *novasodrzina;
  175.     char novUrl[100];
  176.    
  177.     cout<<"Vnesete sodrzina i url za novata strana "<<endl;
  178.     cin>>novasodrzina;
  179.     cin>>novUrl;
  180.     WebPage wpp(novUrl,novasodrzina);
  181.     ws.Dodadi(wpp);
  182.     cout<<"Stranicata e dodadena"<<endl;
  183.     ws.Pecati();
  184.     ws.Izbrisi(wpp);
  185.     cout<<"Stranicata e izbrisana"<<endl;
  186.     ws.Pecati();
  187.     int urll;
  188.     ws.Pecati();
  189.     cout<<"Vnesete url"<<endl;
  190.     cin>>urll;
  191.     ws.pecatiStranicisoUrl(urll);
  192.    
  193.    
  194.     return 0;
  195.  
  196.  
  197.  
  198.  
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement