Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
The Menu
//g++ 7.4.0 #include <iostream> #include <string> using namespace std; class Menu { public: Menu (){}//default constructor Menu(string n, int q,int p){ name=n; qty=q; price =p;}//(string,int,int) constructor Menu(Menu& c) { name = c.name; qty= c.qty; price = c.price;}//copy constructor ~Menu(){}//destructor virtual string getIt() const { return name;}//accessor function to fetch private or protected member virtual int getqty() const { return qty;}//accessor function to fetch private or protected member virtual int getprice() const { return price;}//accessor function to fetch private or protected member private: string name; int qty; int price; }; int main() { const int max=5; Menu* theMenu;//theMenu is pointer to Menu object theMenu= new Menu[max];//new operator allocates memory to 5 Menu objects; theMenu is a pointer to a block of 5 Menu objects theMenu[0]={"Paratha",1,8};//assign values theMenu[1]={"Naan",1,6}; theMenu[2]={"Roti",1,5}; theMenu[3]={"Dal",1,10}; theMenu[4]={"Egg",1,10}; cout <<"Item Quantity Price:\n"; for(int i=0; i<max;i++){ cout <<"\n"; cout <<theMenu[i].getIt()<<"\t"; cout <<theMenu[i].getqty()<<"\t"; cout <<theMenu[i].getprice(); cout <<endl; } delete [] theMenu;//free the memory return 0; }
run
|
edit
|
history
|
help
0
selection_sort
Hello World - verbose
execution of constructor and destructor
a
დიოფანტეს განტოლება
ახარისხება~ფინალური
Networked path_dp
Expected types
ThreadContext
Insertion Sort