Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
NamespaceOverload
//g++ 7.4.0 //namespace & operator overloading: use of different namespaces and operator overloading //this code is created by Rezaul Hoque on August 29,2021;contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> namespace Garden{ class Vegetable{ friend int operator==( const Vegetable& x, const Vegetable& y){ return (x.l*x.b == y.l*y.b) ;}//equality operator private: int l, b; public: Vegetable (){}//default constructor Vegetable (int vl,int vb){ l=vl; b=vb;}//Vegetable(int,int ) constructor Vegetable (const Vegetable& v){l=v.l; b=v.b;}//copy constructor Vegetable& operator=(const Vegetable& eq){ l=eq.l; b=eq.b; return *this;}//assignment operator int area(){return l*b;} void greet(){ std::cout<<"This is the vegetable plot.";} void tomato(){std::cout<<"tomato ";} void cucumber(){std::cout<<"cucumber ";} void pumpkin(){std::cout<<" pumpkin";} void ocra(){ std::cout<<"ocra ";} void lettuce(){std::cout<<"lettuce";} void brinjal(){std::cout<<"brinjal ";} }; class Flower{ friend int operator==( const Flower& x, const Flower& y){ return (x.l*x.b == y.l*y.b) ;} private: int l, b; public: Flower(){} Flower(int fll,int flb){ l=fll; b=flb;} Flower(const Flower& f){l=f.l; b=f.b;} Flower& operator=(const Flower& eq){ l=eq.l; b=eq.b; return *this;} int area(){ return l*b;} void greet(){ std::cout<<"This is the flower plot.";} void rose(){ std::cout<<"rose";} void nightqueen(){std::cout<<"night queen ";} void chirose(){std::cout<<"china-rose\t";} void sunfl(){std::cout<<"sunflower.";} }; class Fruit { friend int operator==( const Fruit& x, const Fruit& y){ return (x.l*x.b == y.l*y.b);} private: int l, b; public: Fruit(){} Fruit (int fl,int fb){ l=fl; b=fb;} Fruit (const Fruit& f){l=f.l; b=f.b;} Fruit& operator=(const Fruit& eq){ l=eq.l; b=eq.b; return *this;} int area(){ return l*b;} void greet(){ std::cout<<"This is the fruit plot.";} void guava(){std::cout<<"guava ";} void mango(){std::cout<<"mango\t";} void muskmelon(){std::cout<<"muskmelon\t";} void jujube (){std::cout<<"jujube\t";} void strawberry(){std::cout<<"strawberry";} void papaya(){std::cout<<"papaya ";} }; } namespace Greetings{ void Start(){std::cout<<"Welcome to my garden.";} void Pose(){std::cout<<"Isn’t it beautiful?";} void Fin(){std::cout<<"Hope you enjoy the tour at my garden.";} void look(){std::cout<<"Over there,that’s my neighbor's garden.\t";} } int main() { Garden::Vegetable veg(4,5),veg2(5,4),veg3; Garden::Flower flow(4,4),flow2(3,4); Garden::Fruit fr(6,5),fr2(7,5); Greetings::Start(); std::cout<<"\n"; veg.greet(); std::cout<<"\n"; std::cout<<"Here we have "; veg.tomato(); std::cout<<","; veg.cucumber(); std::cout<<"&"; veg.pumpkin(); std::cout<<"."; std::cout<<" \n"; Greetings::Pose(); std::cout<<"\n"; flow.greet(); std::cout<<"\n"; std::cout<<"Here we have "; flow.nightqueen(); std::cout<<"&"; flow.rose(); std::cout<<"."; std::cout<<"\n"; Greetings::Pose(); std::cout<<"\n"; fr.greet(); std::cout<<"\n"; std::cout<<"Here we have "; fr.guava(); std::cout<<","; fr.papaya(); std::cout<<"& "; fr.strawberry(); std::cout<<"."; std::cout<<"\n"; Greetings::look(); std::cout<<"There,in the vegetable plot,he grows "; veg2.ocra(); std::cout<<","; veg2.brinjal(); std::cout<<"& "; veg2.lettuce(); std::cout<<"."; std::cout<<"\n"; std::cout<<"There, in the flower plot,he grows "; flow2.chirose(); std::cout<<"& "; flow2.sunfl(); std::cout<<"\n"; std::cout<<"Sizes of my vegetable plot,flower plot and fruit plot are "<<veg.area()<<" sq. meter"<<flow.area()<<" sq. meter & "<<fr.area()<<" sq. meter respectively.\n"; veg3=veg;//assignment operator is called if(veg3==veg2) //equality operator is called std::cout<<"Me and my neighbor have vegetable plots of same size but we grow different crops.\n"; else std::cout<<"Me and my neighbor have vegetable plots of different size and we grow different crops.\n"; Greetings::Fin(); return 0; }
run
|
edit
|
history
|
help
0
Web Browser History - SET
Reverese every K node in list
II-32bit
MINVEST
Zadanie Kolokwium 2013: Trójkąty i trójkąty
vertical sum
sgfsfdgsfd
Reverse factorial
max subsequence of array
scemo le