I need help with this project. I am on #6 - display all pizzas by a specific sty
ID: 3764860 • Letter: I
Question
I need help with this project. I am on #6 - display all pizzas by a specific style.
Create a program that loads pizza information (style, name, sauce, toppings, family calories, large calories) from the attached file*.
Define a structure to hold the pizza information (style, name, sauce, toppings, family calories, large calories).
In the main function, declare an array of structures to hold the data. (Allow for 30 pizzas.)
The program will initially display a welcome message that includes your name.
Then the program will repeatedly display a menu that allows the user to query and display the pizza information.
Menu options in the main menu allow the user to:
Display all pizzas,
display all pizzas by a specific style,
display a specific pizza by name,
display pizzas under a specific calorie count (for large size),
Exit.
Create and call functions to perform the processing for options 1-4. Allow the user to repeatedly select menu options before choosing to exit.
Allow the user to:
Display the data for all pizzas
Display the data for all pizzas of a specific style
Search for pizzas by name (case insensitive match, allow for partial matches) and display the data
Search for pizzas under a specific calorie count
Exit the program
Stuffed|5-Meat|Red|Canadian Bacon, Pepperoni, Sausage, Bacon, Ground Beef|460|490
Gourmet|Angus Steak & Roasted Garlic|Creamy Garlic|Angus Steak, Roasted Garlic, Mushrooms, Green Onions, Parmesan|330|370
Stuffed|Chicago-Style|Red|Salami, Pepperoni, Sausage, Ground Beef, Mixed Onions, Tomatoes, Green Onions|450|490
Stuffed|Chicken Bacon|Creamy Garlic|Chicken, Bacon, Tomatoes, Mixed Onions|450|480
Gourmet|Chicken Bacon Artichoke|Creamy Garlic|Chicken, Bacon, Artichoke Hearts, Spinach, Parmesan, Zesty Herbs|350|400
Signature|Chicken Garlic|Creamy Garlic|Chicken, Tomatoes, Green Onions, Herbs & Cheese|340|380
Signature|Cowboy|Red|Pepperoni, Sausage, Mushrooms, Black Olives, Herbs & Cheese|370|410
Signature|Garden Veggie|Red|Mushrooms, Black Olives, Mixed Onions, Green Peppers, Tomatoes|270|310
Gourmet|Gourmet Vegetarian|Creamy Garlic|Spinach, Zucchini, Mushrooms, Artichoke Hearts, Tomatoes, Mixed Onions, Herbs & Cheese|320|360
Gourmet|Herb Chicken Mediterranean|Olive Oil & Garlic|Herb Chicken, Spinach, Sun-dried Tomatoes, Feta, Zesty Herbs|330|380
Signature|Murphy's Combo|Red|Salami, Pepperoni, Sausage, Mushrooms, Mixed Onions, Black Olives|350|400
Signature|Papa's All Meat|Red|Canadian Bacon, Salami, Pepperoni, Sausage, Ground Beef|350|400
Signature|Papa's Favorite|Red|Pepperoni, Sausage, Ground Beef, Mushrooms, Mixed Onions, Green Peppers, Black Olives|350|400
Gourmet|Spicy Fennel Sausage|Creamy Garlic|Spicy Fennel Sausage, Sun-dried Tomatoes, Mushrooms, Spinach, Parmesan|350|410
Explanation / Answer
using System;
public struct PizzaDetails
{
public string style;
public string name;
public string sauce;
public string toppings;
public int familyCalories;
public int largeCalories;
}
namespace pizza
{
class Program
{
public static void Main(string[] args)
{
//array of structures to hold info about 30 pizza details
PizzaDetails[] pizzas = new PizzaDetails[30];
Console.WriteLine("Enter Your name:");
string UserName=Console.ReadLine();
Console.WriteLine("Hi, "+UserName+"!!! Welcome to Pizza world ");
// Read each line of the file into a string array. Each element
// of the array is one line of the file.
// pizza.txt file should be placed in proper location
string[] lines = System.IO.File.ReadAllLines("pizza.txt");
string[][] array =lines.Select(line => line.Split('|')).ToArray();
for(int j=0;j<array.Length;j++)
{
pizzas[j].style=array[j][0];
pizzas[j].name=array[j][1];
pizzas[j].sauce=array[j][2];
pizzas[j].toppings=array[j][3];
pizzas[j].familyCalories=Convert.ToInt32(array[j][4]);
pizzas[j].largeCalories=Convert.ToInt32(array[j][5]);
}
int choice=1;
while(choice<5)
{
Console.WriteLine("1.Display all pizzas");
Console.WriteLine("2.Display all pizzas by a specific style");
Console.WriteLine("3.Display a specific pizza by name");
Console.WriteLine("4.Display pizzas under a specific calorie count");
Console.WriteLine("5.Exit");
Console.WriteLine("Enter your choice");
choice= Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
DisplayAll(pizzas);
break;
case 2: Console.WriteLine("Enter a style");
string style=Console.ReadLine();
DisplayByStyle(pizzas,style);
break;
case 3: Console.WriteLine("Enter a name");
string name=Console.ReadLine();
DisplayByName(pizzas,style);
break;
case 4: Console.WriteLine("Enter Calorie Count");
int calorie=Convert.ToInt32(Console.ReadLine());
DisplayByCalorie(pizzas,calorie);
break;
}
}
// Keep the console window open in debug mode.
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
void DisplayAll(PizzaDetails []pizzas )
{
for(int i=0;i<30;i++)
{
Console.WriteLine("");
Console.Write(" "+pizzas[i].name+" "+pizzas[i].style+" "+pizzas[i].sauce);
Console.Write(" "+pizzas[i].toppings+" "+pizzas[i].familyCalories+" "+pizzas[i].largeCalories);
Console.WriteLine("");
}
}
void DisplayByStyle(PizzaDetails []pizzas, string style )
{
for(int i=0;i<30;i++)
{
if(style.Equals(pizzas[i].style))
{
Console.WriteLine("");
Console.Write(" "+pizzas[i].name+" "+pizzas[i].style+" "+pizzas[i].sauce);
Console.Write(" "+pizzas[i].toppings+" "+pizzas[i].familyCalories+" "+pizzas[i].largeCalories);
Console.WriteLine("");
}
}
}
void DisplayByName(PizzaDetails []pizzas, string name )
{
for(int i=0;i<30;i++)
{
if(name.Equals(pizzas[i].name))
{
Console.WriteLine("");
Console.Write(" "+pizzas[i].name+" "+pizzas[i].style+" "+pizzas[i].sauce);
Console.Write(" "+pizzas[i].toppings+" "+pizzas[i].familyCalories+" "+pizzas[i].largeCalories);
Console.WriteLine("");
}
}
}
void DisplayByCalorie(PizzaDetails []pizzas, int calorie )
{
for(int i=0;i<30;i++)
{
if(pizzas[i].largeCalories<=calorie)
{
Console.WriteLine("");
Console.Write(" "+pizzas[i].name+" "+pizzas[i].style+" "+pizzas[i].sauce);
Console.Write(" "+pizzas[i].toppings+" "+pizzas[i].familyCalories+" "+pizzas[i].largeCalories);
Console.WriteLine("");
}
}
}
}
}