Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Jilebi Nimki
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 //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> using namespace std; class Snack{ protected: int price, qty; string color; public: void set(int a, int b, string t) { price =a; qty= b; color=t;} string get(){return color;} virtual int cost() { return 0;} }; class Nimki : public Snack { public: int cost() { return price ;} }; class Jilebi : public Snack{ public: int cost() { return price *qty;} }; int main () { Nimki n; Jilebi j; Snack * s1=&n; Snack * s2=&j; s1->set(5,2,"Brown"); s2->set(10,1,"Red"); cout<<"Nimki is "; cout<<s1->get(); cout<<" & a pair cost Tk "; cout<<s1->cost(); cout <<".\n"; cout<<"Jilebi is "; cout<<s2->get(); cout<<" & costs Tk "; cout<<s2->cost(); cout<<endl; return 0; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.42 sec, absolute running time: 0.16 sec, cpu time: 0.01 sec, memory peak: 5 Mb, absolute service time: 0,77 sec
edit mode
|
history
|
discussion
Nimki is Brown & a pair cost Tk 5. Jilebi is Red & costs Tk 10