Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BreakfastMenu array
//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> using namespace std; class Menu{ public: virtual void pack() const {cout<<"Default package has 2 parathas, 1 scrambled egg and 1 chai. It costs Tk 50.\n"; } }; class Pack1:public Menu{ public: void pack() const { cout<<"Package 1 has 2 rotis, 1 dal and 1 coffee. It costs Tk 80.\n";} }; class Pack2: public Menu{ public: void pack() const { cout<<"Package 2 has 3 slices of bread, jelly, banana and chai. It costs Tk 40.\n";} }; class Pack3:public Menu { public: void pack() const { cout<<"Package 3 has 1 plate of khichri. It costs Tk 60.\n";} }; int main() { Menu * list[4]; Menu * ptr; int choice; for (int i=0;i<4;i++) { cout <<"(1) Pack1 (2) Pack2 (3) Pack3 :\n"; cin>>choice; switch(choice) { case 1: ptr = new Pack1; break; case 2: ptr = new Pack2; break; case 3: ptr = new Pack3; break; default: ptr = new Menu; break; } list[i] = ptr; } for(int i=0;i<4;i++) list[i]->pack(); return 0; }
run
|
edit
|
history
|
help
0
exception
C++ lesson
Sieve of Eratosthenes
on_off
LRU - DLL
TmpFib
swastic
Bitwise - Check power of 2 or not
PriQHotel
0/1Knapsack