Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cppPyPoly
//g++ 7.4.0 //cppPyPoly: c++ equivalent of PyPoly program(created on April 05,2022) //this code is created by Rezaul Hoque on April 05,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https:/rezaulhoque.wordpress.com,https://hoquestake.blogspot.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> #include <string> //PyPoly program looks like this: /*** class Polyex1(): name='ABC' address='road 00, city noville, country nulpart' occupation='xzc' def namad(self): s1=f"""name:{self.name}\naddress:{self.address}""" print(s1) def occu(self): s2=f'occupation:{self.occupation}' print(s2) class Polyex2(): name='XYZ' address="road 0, city Utoville, country zeroland" occupation="fgh" def namad(self): s1=f"""name:{self.name}\naddress:{self.address}""" print(s1) def occu(self): s2=f'occupation:{self.occupation}' print(s2) def display(a): a.namad() a.occu() inst1=Polyex1() inst2=Polyex2() display(inst1) display(inst2) ****/ //C++ equivalent of above program is: class Polyex{ protected: std::string name; std::string address; std::string occupation; public: Polyex(std::string a,std::string b,std::string c){ name=a; address=b; occupation=c;} Polyex (Polyex & c){ name=c.name;address=c.address; occupation=c.occupation;} std::string getNam(){ return name;} std::string getAd(){return address;} std::string getOccu(){return occupation;} void display (){ std::cout<<"name:"<<this->getNam(); std::cout<<"\n"; std::cout<<"address:"<<this->getAd(); std::cout<<"\n"; std::cout<<"occupation:"<<this->getOccu(); std::cout<<"\n"; } }; class Polyex1:public Polyex{ public: Polyex1(std::string a,std::string b,std::string c):Polyex (a,b,c) {} Polyex1(Polyex1 & c):Polyex(c){} }; class Polyex2:public Polyex{ public: Polyex2(std::string a,std::string b,std::string c):Polyex (a,b,c) {} Polyex2(Polyex2 & c):Polyex (c){} }; int main() { Polyex* p1=new Polyex1("ABC","road:00,city:noville,country: nulpart","xzc"); Polyex * p2= new Polyex2("XYZ","road: 0,city:Utoville,country: zeroland","fgh"); p1->display(); std::cout<<"\n"; p2->display(); delete p1; delete p2; return 0; }
run
|
edit
|
history
|
help
0
Dictionary
带头结点的单链表
ddd
w1
numberOftweets
queueArray
Bitset Operators
a ko z and z ko n string printing
3
Tray