Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class WebPage {
- private:
- string url;
- string sodrzhina;
- public:
- WebPage() {}
- WebPage(string _url, string _sodrzina) {
- url = _url;
- sodrzhina = _sodrzina;
- }
- bool daliSeIsti(WebPage p) {
- if(url == p.url) {
- return true;
- }
- else {
- return false;
- }
- }
- void print() {
- cout << url << endl;
- }
- };
- class WebServer {
- private:
- string ime;
- WebPage * niza;
- int n;
- public:
- WebServer() {
- n = 0;
- }
- WebServer(string _ime) {
- ime = _ime;
- n = 0;
- }
- void addPage(WebPage p) {
- bool dali_postoi = false;
- for(int i = 0; i < n; i++) {
- if(niza[i].daliSeIsti(p)) {
- dali_postoi = true;
- }
- }
- if(dali_postoi == false) { // isto kako !dali_postoi
- WebPage tmp_niza[n + 1];
- for(int i = 0; i < n; i++) {
- tmp_niza[i] = niza[i];
- }
- tmp_niza[n] = p;
- n++;
- niza = new WebPage[n];
- for(int i = 0; i < n; i++) {
- niza[i] = tmp_niza[i];
- }
- }
- }
- void deletePage(WebPage p) {
- WebPage tmp_niza[n];
- int j = 0;
- for(int i = 0; i < n; i++) {
- if(niza[i].daliSeIsti(p) == false) {
- tmp_niza[j] = niza[i];
- j++;
- }
- }
- n = j;
- niza = new WebPage[n];
- for(int i = 0; i < n; i++) {
- niza[i] = tmp_niza[i];
- }
- }
- void listPages() {
- for(int i = 0; i < n; i++) {
- niza[i].print();
- }
- }
- };
- int main()
- {
- WebPage wp1 ("http://www.google.com", "The search engine");
- WebPage wp2 ("http://www.finki.ukim.mk", "FINKI");
- WebPage wp3 ("http://www.time.mk", "Site vesti");
- WebServer ws(" Server ");
- ws.addPage(wp1) ;
- ws.addPage(wp2);
- ws.addPage(wp3) ;
- ws.listPages ();
- cout << "\nAfter delete: \n";
- ws.deletePage(wp3);
- ws.listPages ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement