Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cppPySuper
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.83 sec, absolute running time: 0.2 sec, cpu time: 0.02 sec, memory peak: 5 Mb, absolute service time: 1,08 sec
edit mode
|
history
|
discussion
70