Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cppPySlots3
//g++ 7.4.0 //cppPySlots3: C++ equivalent of PySlots3 program //this code is created by Rezaul Hoque on February 08,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> //PySlots3(created on January 09,2022) looks like this /**** class Food: def __init__(self, food,color): self.food = food self.color = color class CookedFood(Food): __slots__= ('price',) def __init__(self,food,color,price): super().__init__(food,color) self.price = price def __banner(self): print("Example: Subclass uses slots but base class doesn't") if __name__ == '__main__': ic= CookedFood('Icecream','white',10) ic._CookedFood__banner() print (ic.__slots__) print(ic.__dict__) ic.taste='good' print(ic.__dict__) ****/ //C++ equivalent of the above program is: class Food{ protected: std::string food,color; public: Food(){} Food(std::string f,std::string c){ food=f; color=c;} Food(Food& c){ food=c.food; color=c.color;} ~Food(){} virtual std::string getF() const { return food;} virtual std::string getC() const { return color;} }; class CookedFood: public Food{ protected: std::string taste; int price; public: CookedFood(){} CookedFood(std::string f,std::string c,int p):Food(f,c),price(p){} ~CookedFood(){} virtual std::string getT() const { return taste;} virtual int getP() const { return price;} void setT(std::string t){ taste=t;} void slots() { std::cout<<"('price',)\n"; } void dict() { std::cout<<"{'food': "; std::cout<<this->getF(); std::cout<<","; std::cout<<"'color': "; std::cout<<this->getC(); std::cout<<","; std::cout<<"'taste': "; std::cout<<this->getT(); std::cout<<"}\n"; } void banner() { std::cout<<"C++ equivalent of PySlots3 program:\n";} }; int main() { CookedFood ic("icecream","white",10); ic.banner(); ic.slots(); ic.dict(); ic.setT("good"); ic.dict(); return 0; }
run
|
edit
|
history
|
help
0
pyramid
Void main
Test 10(2020)
cppPySuper
sd5
Silly circular pointer
topological sort
word shufle match
Fractional Knapsack
Graph Theory 2