Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#include<iostream>
#include<conio.h>
using namespace std;

class pizza
{
	public:
		int choice=0;
		int pchoice,pchoice1, quantity;
		char pizza1='Chicken Fajita' ,pizza2='Chicken Bar BQ' ,pizza3='Chicken Tikka' ,pizza4='Chicken Cheese'; 
		int getdata()
		{
			cout<<"1) "<<pizza1<<endl;
			cout<<"2) "<<pizza2<<endl;
			cout<<"3) "<<pizza3<<endl;
			cout<<"4) "<<pizza4<<endl<<endl;
			cout<<"Please Enter which Flavour would you like to have? : ";
			cin>>pchoice;
			cout<<endl;
		if(pchoice>=1 && pchoice<=5)
		{
			cout<<"1) Small Rs.250"<<endl;
			cout<<"2) Regular Rs.500"<<endl;
			cout<<"3) Large Rs.900"<<endl<<endl;
			cout<<"Choose Size of Pizza Please : ";
			cin>>pchoice1;
			if(pchoice1>=1 && pchoice1<=3)
			cout<<endl;
			cout<<"Please Enter Quantity: ";
			cin>>quantity;
			switch(pchoice1)
			{
			case 1: choice = 250*quantity;
			break;
			case 2: choice = 500*quantity;
			break;
			case 3: choice = 900*quantity;
			break;
			}
			system("CLS");
			switch (pchoice1)
			{
			 case 1:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<pizza1<<endl;
			 cout<<"Your Total Bill is"<<choice<<endl<<"Your Order Will be delivered in 30 Minutes";
			 cout<<endl<<endl;
			 cout<<"------Thank you For Ordering From Niba and Rohma Fast Food------"<<endl;
			 break;
			 case 2:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<"  "<<pizza2<<endl;;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 30 Minutes";
			 cout<<endl<<endl;
			 cout<<"------Thank you For Ordering From Niba and Rohma Fast Food------"<<endl;
			 break;
			 case 3:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<pizza3<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 30 Minutes";
			 cout<<endl<<endl;
			 cout<<"------Thank you For Ordering From Niba and Rohma Fast Food------"<<endl;
			 break;
			 case 4:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<pizza4<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 30 Minutes";
			 cout<<endl<<endl;
			 cout<<"------Thank you For Ordering From Niba and Rohma Fast Food------"<<endl;
			 break;

			}
			cout<<"Would you like to order anything else? Y / N:";
			cin>>gotostart;
			if(gotostart=='Y' || gotostart=='y')
			{
			  goto beginning;
			  //return 0;
			}
		}
		}
};
class burger
{
	public:
		int choice=0;
		int pchoice,pchoice1, quantity;
		char bur1='Zinger Burger',bur2='Chicken Burger',bur3='Beef Burger';
	int getdata()
	{
		cout<<"1) "<<bur1<<" Rs.100"<<endl;
		cout<<"2) "<<bur2<<" Rs.150"<<endl;
		cout<<"3) "<<bur3<<" Rs.200"<<endl;
		cout<<"Please Enter which Burger you would like to have?: ";
		cin>>pchoice1;
		if(pchoice1>=1 && pchoice1<=3)
		{
			cout<<endl;
			cout<<"Please Enter Quantity: ";
			cin>>quantity;
			switch(pchoice1)
			{
			case 1: choice = 100*quantity;
			break;
			case 2: choice = 150*quantity;
			break;
			case 3: choice = 200*quantity;
			break;
			}
			system("CLS");
			switch (pchoice1)
			{
			 case 1:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<bur1<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 40 Minutes"<<endl;
			 cout<<"Thank you For Ordering From NibA and Rohma Fast Food"<<endl;
			 case 2:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<bur2<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 40 Minutes"<<endl;
			 cout<<"Thank you For Ordering From NibA and Rohma Fast Food"<<endl;
			 case 3:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<bur3<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 40 Minutes"<<endl;
			 cout<<"Thank you For Ordering From NibA and Rohma Fast Food"<<endl;
			 break;
			}
			cout<<endl;
			cout<<"Would you like to order anything else? Y / N:";
			cin>>gotostart;
			if(gotostart=='Y' || gotostart=='y')
			{
			  goto beginning;
			  //return 0;
			}
 		}
	}
};
class sandwich
{
	public:	
	int choice=0;
	int pchoice,pchoice1, quantity;
	char sand1='Club Sandwich', sand2='Chicken Crispy Sandwich', sand3='Extream Veg Sandwich';
	int getdata()
	{
		cout<<endl;
		cout<<"1)  "<<sand1<<" Rs.240"<<endl;
		cout<<"2)  "<<sand2<<" Rs.160"<<endl;
		cout<<"3)  "<<sand3<<" Rs.100"<<endl<<endl;
		cout<<"Please Enter which Sandwich you would like to have? : ";
		cin>>pchoice1;
		if(pchoice1>=1 && pchoice1<=3)
		{
			cout<<endl;
			cout<<"Please Enter Quantity: ";
			cin>>quantity;
			switch(pchoice1)
			{
			case 1: choice = 240*quantity;
			break;
			case 2: choice = 160*quantity;
			break;
			case 3: choice = 100*quantity;
			break;
			}
			system("CLS");
			switch (pchoice1)
			{
			 case 1:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<sand1<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 50 Minutes"<<endl;
			 cout<<"Thank you For Ordering From NibA and Rohma Fast Food"<<endl;
			 break;
			case 2:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<sand2<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 50 Minutes"<<endl;
			 cout<<"Thank you For Ordering From NibA and Rohma Fast Food"<<endl;
			 break;
 			case 3:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<sand3<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 50 Minutes"<<endl;
			 cout<<"Thank you For Ordering From NibA and Rohma Fast Food"<<endl;
			 break;
			}
			cout<<"Would you like to order anything else? Y / N:";
			cin>>gotostart;
			if(gotostart=='Y' || gotostart=='y')
			{
			  goto beginning;
			  //return 0;
			}
		}
	}
};
class roll
{
	public:
		int choice=0;
		int pchoice,pchoice1, quantity;
		char roll1='Chicken Chatni Roll', roll2='Chicken Mayo Roll', roll3='Veg Roll With Fries';
		int getdata()
		{
		cout<<"1) "<<roll1<<" Rs.150"<<endl;
		cout<<"2) "<<roll2<<" Rs.100"<<endl;
		cout<<"3) "<<roll3<<" Rs.120"<<endl<<endl;
		cout<<"Please Enter which you would like to have?: ";
		cin>>pchoice1;
		if(pchoice1>=1 && pchoice1<=3)
		{
			cout<<endl;
			cout<<"How Much Rolls Do you want: ";
			cin>>quantity;
			switch(pchoice1)
			{
			case 1: choice = 150*quantity;
			break;
			case 2: choice = 100*quantity;
			break;
			case 3: choice = 120*quantity;
			break;
			}
			system("CLS");
			switch (pchoice1)
			{
			 case 1:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<roll1<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 60 Minutes"<<endl;
			 cout<<"Thank you For Ordering From NibA and Rohma Fast Food"<<endl;
			 break;
			case 2:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<roll2<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 60 Minutes"<<endl;
			 cout<<"Thank you For Ordering From NibA and Rohma Fast Food"<<endl;
			 break;
			case 3:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<roll3<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 60 Minutes"<<endl;
			 cout<<"Thank you For Ordering From NibA and Rohma Fast Food"<<endl;
			 break;
			}
 		}
	}
		
};
class biryani
{
	public:
		int choice=0;
		int pchoice,pchoice1, quantity;
		char bir1='Chicken Biryani', bir2='Sindhi Biryani', bir3='Beef Biryani';
		int getdata()
		{
			cout<<"1) "<<bir1<<" Rs.160"<<endl;
		cout<<"2) "<<bir2<<" Rs.220"<<endl;
		cout<<"3) "<<bir3<<" Rs.140"<<endl<<endl;
		cout<<"Please Enter which Biryani you would like to have?:";
		cin>>pchoice1;
		if(pchoice1>=1 && pchoice1<=3)
		{
			cout<<endl;
			cout<<"Please Enter Quantity: ";
			cin>>quantity;
			switch(pchoice1)
			{
			case 1: choice = 160*quantity;
			break;
			case 2: choice = 220*quantity;
			break;
			case 3: choice = 140*quantity;
			break;
			}
			system("CLS");
			switch (pchoice1)
			{
			 case 1:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<bir1<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 30 Minutes"<<endl;
			 cout<<"Thank you For Ordering From NibA and Rohma Fast Food "<<endl;
			 break;
			 case 2:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<bir2<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 30 Minutes"<<endl;
			 cout<<"Thank you For Ordering From NibA and Rohma Fast Food "<<endl;
			 break;
			 case 3:
			 cout<<"\t\t--------Your Order---------"<<endl;
			 cout<<""<<quantity<<" "<<bir3<<endl;
			 cout<<"Your Total Bill is "<<choice<<endl<<"Your Order Will be delivered in 30 Minutes"<<endl;
			 cout<<"Thank you For Ordering From NibA and Rohma Fast Food "<<endl;
			 break;
			}
			cout<<"Would you like to order anything else? Y / N:";
			cin>>gotostart;
			if(gotostart=='Y' || gotostart=='y')
			{
			  goto beginning;
			  //return 0;
			}
		}
	}
};
class food
{
	private:
			char name[30];

			int choice=0;
			int pchoice,pchoice1, quantity;
			pizza p;
			burger b;
			sandwich s;
			roll r;
			biryani bi;
		public:
		int getdata()
		{
			beginning:
			system("CLS");
			cout<<"\t\t----------NibA and Rohma Fast Food-----------"<<endl<<endl;
			cout<<"Please Enter Your Name: ";
			cin>>name;
			cout<<"Hello "<<name<<endl<<"What would you like to order?"<<endl<<endl;
			cout<<"\t--------Menu--------"<<endl<<endl;
			cout<<"1) Pizzas"<<endl;
			cout<<"2) Burgers"<<endl;
			cout<<"3) Sandwich"<<endl;
			cout<<"4) Rolls"<<endl;
			cout<<"5) Biryani"<<endl;
			cout<<endl;
			cout<<"Please Enter your Choice: ";
			cin>>choice;
			if(choice==1)
			{
				p.getdata();
			}
			else if(choice==2)
	 		{
				b.getdata();
			}
			else if(choice==3)
			{
				s.getdata();
			}
			else if(choice==4)
			{
				r.getdata();
			}
			else if(choice==5)
			{
				bi.getdata();
			}
			else
			{
				system("CLS");
				cout<<"Please Select Right Option: "<<endl;
				cout<<"Would You like to Start the program again? Y / N: " ;
				cin>>gotostart;
				if(gotostart=='Y' || gotostart=='y')
				{
				  goto beginning;
			  //return 0;
				}
			}
		}
};

int main()
{
	food f;
	f.getdata();
	getch();		
}


What I have tried:

the code is giving me these errors:
1. [Warning] overflow in implicit constant conversion [-Woverflow]
2. [Error] 'gotostart' was not declared in this scope
3. [Error] label 'beginning' used but not defined>
4. [Warning] non-static data member initializers only available with -std=c++11 or -std=gnu++11
Posted
Updated 5-Jan-20 7:19am
v2

I believe Mr. K5054 has given very valuable advice. After looking over your code, I think you should step back and take a "bigger picture" look at your code. I noticed you have a common pattern in your classes that should be moved into a base class that other classes derive from. This base class will do the following : display a list of the options and their prices; accept input of the choice(s) and quantities; display order summary, cost, and estimate of delivery time. Every single one of your food classes does these same things. The only differences are their text names, prices, and delivery times so each of these should be data parameters. I would make two classes to handle this. One would be a food item that contains a text name (used in prompting) and a cost. The second would be the order. It contains groups of food items, the total cost, and an estimated delivery time for them. This class would be the base class mentioned above.

Taking this approach would shrink the amount of code you have considerably since so much of it is repeated. To get you started, I will show you what a food item class might like like.
C++
class FoodItem
{
public:
   const char * name  { nullptr };
   int cost           { 0 };
   int count          { 0 };

public:
   FoodItem()  {}

   FoodItem( const char * n, int c ) { Set( n, c ); }

   void Set( const char * n, int c )
   {
       name = n;
       cost = c;
   }

   int GetCost() const
   {
       return count * cost;
   }
};

// here are some instances

const FoodItem biryanis[3];
biryani[0].Set( "Chicken Biryani", 160 );
biryani[1].Set( "Sindhi Biryani", 220 );
biryani[2].Set( "Beef Biryani", 140 );
You can defined groups of food items for each type you have. Then implement the class that does the prompting and acquires the order data. Here is a prototype for the function that gets the order :
C++
int GetOrder( FoodItem items[], int itemcount, int deliveryTime );

//and you could call it like this:

int rv = GetOrder( biryanis, 3, 30 );
Note that the food item class contains the number of items ordered. You could make several groups of food items, one for each kind, and this would represent one order. Here is what the data members for an order class might look like:
class FoodOrder
{
public:
   FoodItem pizzas[3];
   FoodItem burgers[3];
   FoodItem sandwiches[3];
   FoodItem rolls[3];
   FoodItem biryanis[3];
};
If this were my project, I would split the name into two parts : a type (biryani) and the variety (chicken). Then I would have a vector for all of those so I could have as many of them as I wanted to. The prompting would first ask for what type and then it would display a list of all options of that type. It would make things much more flexible and open-ended. In fact, you could have a vector of food types and options with no limit on either. If you wanted, you could view this as configuration data that is loaded from a file when the program starts. The program could figure out how many different types there are and operate accordingly.
 
Share this answer
 
1. Not many people are going to wade through 300+ lines of code to figure out what overflowed. Please include line numbers for warning/error statements you get.

2. you forgot to define gotostart. Take a look at your program, and decide the best place to define it.

3. you have a goto but no label defined. Add the label. In general, though, use of goto should be avoided. If this is a school assignment, you will probably get marks deducted for using a goto.

4. only static members of a class can be initialized at compile time. If you want to initialize variables when a class object is constructed, you should use a class constructor method, something like
C++
class MyClass {
int counter;
public:
    MyClass() {
       counter = 0;
    }
}


There's other things I notice too, for example, you should be getting an error on
C++
char pizza1='Chicken Fajita', ...
Variables of type char are a single character. You probably want an array of chars e.g.
C++
char pizza1[] = "Chicken Fajita"
, or better yet a c++ string type. But even so, that's not the way to go about creating a class item with a constant string name .. see (4), above.

A more OO approach might be to have a food item class with name and price, then derive pizza, sandwiches, etc from those and then have an order class which does the I/O and adds food items to the order. Of course there's other ways you could approach this, too, that's just one suggestion.
 
Share this answer
 
v2
Dont use goto but a while loop with some flag. Take a closer look on the lines which your compiler bitched about.

C++
bool looping = true;

while( looping ) {

 // some exit case 
looping = false;
}
It shouldnt be too hard.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900