Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
VirtualRestoPoint
//g++ 7.4.0 //Virtual Resto Point: ADT, derived class and use of pointer to call correct instances and methods //code is created by Rezaul Hoque on May 08,2021 //please contact at jewelmrh@yahoo.com #include <iostream> using namespace std; //This class is the Abstract Data Type with three pure virtual functions,which will be overridden in the subsequent derived classes class EatOut{ public: virtual void greeting()=0; virtual void menu()=0; virtual void cost() =0; virtual void thankYou()=0; }; void EatOut::thankYou(){ cout<<"Thank you for choosing us.\n";}//implementation of pure virtual function in ADT, rare case, in order to provide common feature in all the subsequent overridden functions class Breakfast : public EatOut{ public: void greeting() { cout<<"Good morning.\n";} void menu() { cout<<"To kick start your day we are offering:\n"; cout<<" lemonade(1 glass), rumali roti(2 pieces), dal bhuna(1 cup), vegetable stew(1 cup) and chaï( 1 cup).\n"; } void cost() { cout <<" The Breakfast package costs Tk 50.\n"; } void thankYou(){ cout<<"Hope you like our breakfast.\n"; EatOut::thankYou(); } }; class Lunch : public EatOut{ public: void greeting() { cout<<"Good afternoon.\n";} void menu() { cout<<"Our lunch menu for one can easily satisfy two people and we are offering:\n"; cout<<" coke(1 glass), shorshe shak(1 plate), rice (2 plates), lentil soup(1 cup), shol fish dopeyaja(1 cup) and kheer( 1 cup).\n"; } void cost() { cout <<" The lunch package costs Tk 90.\n"; } void thankYou(){ cout<<"Dhonnobad.\n"; EatOut::thankYou(); } }; class Dinner : public EatOut{ public: void greeting() { cout<<"Good evening.\n";} void menu() { cout<<"We have the best dinner menu in the town and we are offering:\n"; cout<<" borhani(1 glass), moglaï parota(1 piece),salad(1 plate) and mishti doï( 1 cup).\n"; } void cost() { cout <<" The dinner package costs Tk 50.\n"; } void thankYou(){ cout<<"Bon appétit.\n"; EatOut::thankYou(); } }; int main() { EatOut *point = NULL;//point is a pointer to EatOut type and initialized to NULL int pick; bool fQuit = false; while(true)// alternatively fQuit== false { cout<<"(1) Breakfast (2) Lunch (3) Dinner (0) Quit:\n"; cin>>pick; switch(pick) { //point is used to point to the instances of derived classes case 1: point = new Breakfast; break; case 2: point = new Lunch; break; case 3: point = new Dinner; break; default: fQuit = true; break; } if (fQuit) // fQuit== true break; //Reading the user's choice, correct methods are called point->greeting(); point->menu(); point->cost(); point->thankYou(); delete point; cout<<"\n"; } return 0; }
run
|
edit
|
history
|
help
0
MINVEST
diamond
4149 coj WIP
Minimum Vertices to Traverse Directed Graph
test
read_write_lock_acc
k1
Such case
Nth max element in BST
NamespaceOverload