Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is my class assignment, which I do not understand. I have 100% in this class so far 4th week in and have a 3.8 GPA right now. This topic is confusing to me.

I understand structs for the most part. What I don't understand is the context:

Use an array, menuList, of the struct menuItemType, that you just defined.

Write a program to help a local restaurant automate its lunch billing system. The program should do the following:
Show the customer the different lunch items offered by the restaurant.
Allow the customer to select more than one item from the menu.
Calculate and print the bill. Assume that the restaurant offers the following lunch items (the price of each item is shown to the right of the item):

Ham and Cheese Sandwich

Tuna Sandwich

Soup of the Day

Baked Potato



French Fries

Bowl of Fruit

Define a struct, menuItemType, with two components: menuItem of type string and menuPrice of type double.
Use an array, menuList, of the struct menuItemType, that you just defined.
Your program must contain at least the following functions:
Function getData: This function loads the data into the array menuList.
Function showMenu: This function shows the different items offered by the restaurant and tells the user how to select the items.
Function printCheck: This function calculates and prints the check. (Note that the billing amount should include a 5% tax.) A sample output is:
Welcome to Bob’s Restaurant:
Ham and Cheese Sandwich





What I have tried:

I dont understand what it's asking or how this "program" is supposed to operate. I'm overly analytical sometimes... Can someone just give an example of using an array of a struct type so I have an idea of the concept? TIA!!!!
Updated 4-Mar-21 5:22am
PIEBALDconsult 4-Mar-21 12:32pm    
That is definitely _not_ a fourth week topic.
BillWoodruff 5-Mar-21 3:08am    
What stops you from asking the instructor for clarification ?

Structure types - C# reference | Microsoft Docs[^]. Arrays - C# Programming Guide | Microsoft Docs[^].

So once you have defined your struct and its members you can create the individual instances of it. And each instance you create needs to be added to your menuList array.
Share this answer
Using an array of struct items is exactly the same as using an array of class items, with a few exceptions.
You declare it the same way:
myStruct[] array = new myStruct[10];

But because all struct items are value types rather than reference types, you don't need to explicitly create each item as you would normally for a reference type:
myClass[] arrayOfReferenceType = new myClass[10];
for (int i = 0; i < 10; i++)
   arrayOfReferenceType[i] = new myClass();

And you can then treat them pretty much the same after than, except ... when you use a reference type you use a copy of the reference, not the value. With a value type, you use a copy of the value, so any changes you make to it will not be reflected back in eth original.

This may help: Using struct and class - what's that all about?[^] - but there may be some stuff in there that's a little beyond your level at the moment.
Share this answer
Richard MacCutchan 4-Mar-21 12:07pm    
Not sure why teacher chose a struct rather than a class here, but it helped me to learn something new. As did your nice article.
OriginalGriff 4-Mar-21 12:28pm    
Thank you!

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