Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class WebPage{
- private:
- char url[100];
- char *sodrzina;
- public:
- WebPage(){
- char url='\0';
- char sodrzina='0';
- }
- WebPage(char *url,char *sodrzina){
- strcpy(this->url,url);
- this ->sodrzina = new char[strlen(sodrzina)+1];
- strcpy(this->sodrzina,sodrzina);
- }
- WebPage(const WebPage &p){
- strcpy(this->url,p.url);
- this ->sodrzina = new char[strlen(p.sodrzina)+1];
- strcpy(this->sodrzina,p.sodrzina);
- }
- char *getUrl(){
- return url;
- }
- ~WebPage () {
- delete [] sodrzina ;
- }
- WebPage&operator = (const WebPage &p){
- if(this!=&p){
- strcpy(this->url,p.url);
- delete [] sodrzina ;
- this ->sodrzina = new char[strlen(p.sodrzina)+1];
- strcpy(this->sodrzina,p.sodrzina);
- }
- return *this;
- }
- bool operator==(WebPage &p)
- {
- return strcmp(url,p.url)==0;
- }
- };
- class WebServer{
- private:
- char ime[30];
- WebPage *webpage;
- int brojElemnti; //sama si go dodavam i moram sekogash da ja imam ovaa promenliva koga imam dinamichki alocirana niza od objekti
- public:
- WebServer(const char *ime=" ", WebPage *webpage=0,int brojElemnti=0){
- strcpy(this->ime,ime);
- this->webpage=new WebPage[brojElemnti];
- for(int i=0;i<brojElemnti;i++){
- this->webpage[i]=webpage[i];
- }
- this->brojElemnti=brojElemnti;
- }
- WebServer(const WebServer &s){
- strcpy(this->ime,s.ime);
- this->webpage=new WebPage[brojElemnti];
- for(int i=0;i<brojElemnti;i++){
- this->webpage[i]=s.webpage[i];
- }
- this->brojElemnti=s.brojElemnti;
- }
- WebServer&operator = (const WebServer &s){
- if(this!=&s)
- {
- strcpy(this->ime,s.ime);
- delete []this -> webpage;
- this->webpage=new WebPage[brojElemnti];
- for(int i=0;i<brojElemnti;i++){
- this->webpage[i]=s.webpage[i];
- }
- this->brojElemnti=s.brojElemnti;
- }
- return *this;
- }
- ~WebServer () {
- delete [] webpage;
- }
- WebServer &operator+=(WebPage p)
- {
- WebPage *tmp= new WebPage[brojElemnti+1];//samo rezerviram memorija
- for(int i=0;i<brojElemnti;i++)
- {
- tmp[i]=webpage[i];// site elementi od niza[i ] kje se iskopiraat vo nizata tmp
- }
- tmp[brojElemnti++]=p;//na poslednoto mesto od tmp kje dodadam nova strana(objekt od klasata WebPage)
- delete [] webpage;
- webpage=tmp;
- return *this;
- }
- WebServer &operator-=(WebPage p)
- {
- int novbrojac=0;
- WebPage *tmp= new WebPage[brojElemnti];
- for(int i=0;i<brojElemnti;i++)
- {
- if(!(webpage[i]==p))
- tmp[novbrojac++]=webpage[i];
- }
- delete [] webpage;
- webpage=tmp;
- brojElemnti=novbrojac;
- return *this;
- }
- void pecati(){
- for(int i=0 ; i<brojElemnti;i++){
- cout<<webpage[i].getUrl()<<endl;
- }
- }
- };
- 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 += wp1 ;
- ws += wp2 ;
- ws += wp3 ;
- ws.pecati ();
- ws-= wp3;
- ws.pecati ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement