sandra0309

web

Mar 29th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. //ne znam zasto mi vrakja greski za operatorot,se uspav i posle se ke ti dopratam
  2. #include <iostream>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. class WebPage
  8. {
  9. private:
  10. char url[100];
  11. char *sodrzina;
  12. public:
  13. WebPage(char *url="",char *sodrzina="")
  14. {
  15. strcpy(this->url,url);
  16. this->sodrzina=new char[strlen(sodrzina)+1];
  17. strcpy(this->sodrzina,sodrzina);
  18. }
  19. WebPage(const WebPage &wp)
  20. {
  21. strcpy(this->url,wp.url);
  22. this->sodrzina=new char[strlen(wp.sodrzina)+1];
  23. strcpy(this->sodrzina,wp.sodrzina);
  24. }
  25. WebPage &operator =( WebPage &wp)
  26. { if(this!=&wp) {
  27. strcpy(this->url,wp.url);
  28. delete [] this->sodrzina;
  29. this->sodrzina= new char[strlen(wp.sodrzina)+1];
  30. strcpy(this->sodrzina,wp.sodrzina);
  31. }
  32. return *this;
  33. }
  34. char *getUrl()
  35. {
  36. return this->url;
  37. }
  38. void setUrl(char *url)
  39. {
  40. strcpy(this->url,url);
  41. }
  42. char *getSodrzina ()
  43. {
  44. return this->sodrzina;
  45. }
  46. void *setSodrzina (char *sodrzina)
  47. {
  48. delete [] this->sodrzina;
  49. this->sodrzina=new char [strlen(sodrzina)+1];
  50. strcpy(this->sodrzina,sodrzina);
  51. }
  52. bool proverka(WebPage wp)
  53. {
  54.  
  55.  
  56. if(strcmp(this->url,wp.url)==0 && strcmp(this->sodrzina,wp.sodrzina)==0)
  57. return true;
  58. else
  59. return false;
  60. }
  61. void Pecati()
  62. {
  63. cout<<url<<endl;
  64. cout<<sodrzina<<endl;
  65. }
  66.  
  67.  
  68. };
  69.  
  70. class WebServer
  71. {
  72. private:
  73. char ime[30];
  74. WebPage wps;
  75. int n;
  76. public:
  77. WebServer(char *ime="", WebPage *wps=0,int n=0)
  78. {
  79. strcpy(this->ime,ime);
  80. this->wps= new WebPage[n];
  81. for(int i=0;i<n;i++)
  82. {
  83. this->wps[i]=WebPage(wps[i]);
  84.  
  85. }
  86. }
  87. WebServer(const WebServer &ws)
  88. {
  89. strcpy(this->ime,ws.ime);
  90. this->wps=new WebPage[ws.n];
  91. for(int i=0;i<n;i++)
  92. {
  93. this->wps[i]=WebPage(ws.wps[i]);
  94. }
  95. this->n=ws.n;
  96. }
  97. WebServer &operator = (WebServer &ws)
  98. { if(this!=&ws)
  99. {
  100.  
  101.  
  102. strcpy(this->ime,wp.ime);
  103. delete [] this->wps;
  104. this->wps=new WebPage[ws.n];
  105. for(int i=0;i<n;i++)
  106. {
  107. this->wps[i]=ws.n;
  108. }
  109. this->n=ws.n;
  110. }
  111. }
  112. int getN ()
  113. {
  114. return this->n;
  115. }
  116. void setN(int n)
  117. {
  118.  
  119. this->n=n;
  120. }
  121. char *getIme ()
  122. {
  123.  
  124. return this->ime;
  125. }
  126. void setIme(char *ime)
  127. {
  128. strcpy(this->ime,ime);
  129. }
  130. WebPage *getWps ()
  131. {
  132.  
  133. return this->wps;
  134. }
  135. void setWps(WebPage *wps,int n)
  136. {
  137. delete [] this->wps;
  138. for(int i=0;i<n;i++)
  139. {
  140. this->wps[i].setUrl(wsp[i].getUrl());
  141. this->wps[i].getSodrzina(wps[i].getSodrzina());
  142. }
  143. }
  144. void Dodadi(WebServer wp)
  145. {
  146. WebPage *temp;
  147. temp=new WebPage[this->n];
  148. for( int i=0;i<n;i++)
  149. {
  150. temp[i]=WebPage(this->wps[i]);
  151.  
  152. }
  153. delete [] this->wps;
  154. this->wps=WebPage[this->n+1];
  155. for(int i=0;i<n;i++)
  156. {
  157. this->wps[i]=WebPage(temp[i]);
  158. }
  159. delete [] temp;
  160. this->wps[n]=WebPage(wp);
  161. n++;
  162. }
  163. void Izbrisi(WebServer wp)
  164. {
  165. WebPage *temp;
  166. int j=0;
  167. temp=new WebPage[this->n-1];
  168. for( int i=0;i<n;i++)
  169. { if(this->wps[i].proverka(wp))
  170. continue;
  171. temp[j]=WebPage(this->wps[i]);
  172. j++;
  173.  
  174. }
  175. delete [] this->wps;
  176. this->wps=new WebPage[j];
  177. for(int i=0;i<n;i++)
  178. {
  179. this->wps[i]=WebPage(temp[j]);
  180. }
  181. delete [] temp;
  182. n--;
  183. }
  184. void sortAlpha()
  185. {
  186. for(int i=0;i<n;i++)
  187. { for(int j=i+1;j<this->i+1;j++)
  188. {
  189. if(strcmp(wps[i].getUrl().wps[j].getUrl()>0)
  190. wps t=this->wps[i];
  191. wps[i]=wps[j];
  192. wps[j]=t;
  193. }
  194.  
  195. }
  196. }
  197. void sortLen()
  198. {
  199. for(i=0;i<this->n;i++)
  200. {
  201. for(j=i+1;j<this->n;j++)
  202. {
  203. if(strlen(wps[i].getUrl())>strlen(wps[j].getUrl()))
  204. {
  205. WebPage t=wps[i];
  206. wps[i]=wps[j];
  207. wps[j]=t;
  208. }
  209.  
  210. }
  211. }
  212. }
  213. void Pecatistranicisourlnad(int n)
  214. {
  215. for(int i=0;i<n;i++)
  216. {
  217. if(strlen(this->wps[i].getUrl())>=n)
  218. {
  219. this->wps[i].pecati();
  220. }
  221. }
  222. }
  223.  
  224.  
  225. };
  226. void pecati(WebPage *wps,int n)
  227. {
  228. for(i=0;i<n;i++)
  229. {
  230. wps[i].Pecati();
  231. }
  232. }
  233.  
  234. int main()
  235. {
  236. int n;
  237. char url[100], sodrzina[100], ime[100];
  238. cout << "Vnesete broj na WebStranici vo serverot: ";
  239. cin >> n;
  240. WebPage stranici[n];
  241. for(int i=0;i<n;i++)
  242. {
  243. cout << endl << "Vnesete URL za " << i << "-ta stranica: ";
  244. cin >> url;
  245. cout << endl << "Vnesete SODRZINA za " << i << "-ta stranica: ";
  246. cin >> sodrzina;
  247. stranici[i] = WebPage(url,sodrzina);
  248. }
  249.  
  250. return 0;
  251. }
Advertisement
Add Comment
Please, Sign In to add comment