Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cppPySuper
//g++ 7.4.0 //cppPySuper: C++ equivalent of PySuper program //this code is created by Rezaul Hoque on February 10,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> //PySuper(created on January 05,2022) looks like: /**** class Fruit: def __init__(self,fruit, color, price, qty): self.fruit= fruit self.color= color self.price = price self.qty = qty def cost(self): return self.price*self.qty class Mango(Fruit): def __init__(self, fruit,color,price,qty,charge): super().__init__(fruit,color,price,qty) self.charge= charge def cost(self): return super().cost() + self.charge if __name__ == '__main__': m = Mango('Khirsapati','Green',50,1,20) print(m.cost()) ***/ //C++ equivalent of the above program is: class Fruit { protected: std::string fruit, color; int price,qty; public: Fruit(){} Fruit(std::string f, std::string c,int p,int q){ fruit=f; color=c; price=p; qty=q;} Fruit(Fruit & c){ fruit=c.fruit; color=c.color; price=c.price; qty=c.qty;} ~Fruit(){} virtual std::string getF() const { return fruit;} virtual std::string getC() const { return color;} virtual int getP() const { return price;} virtual int getQ() const { return qty;} virtual int cost()=0; }; class Mango:public Fruit{ protected: int charge; public: Mango(){} Mango(std::string f,std::string c,int p,int q,int ch):Fruit(f,c,p,q),charge(ch){} ~Mango(){} virtual int getCh() const { return charge;} int cost(){ return (price*qty)+charge;} }; int main() { Mango m("Khirshapati","green",50,1,20); std::cout<<m.cost(); return 0; }
run
|
edit
|
history
|
help
0
prepend
4
Day3
СП КИ ЭТАП 2
Prime calculator using bool
Rzutka gra 2
¡Arriba, Papalotes, Arriba! v2
Prime_Number_Cpp
12/13 quiz shickes
Dar