Assignment 07

Due: Monday, Oct. 22, 2018, at noon, 100 points

For this assignment you will submit (in the usual way) multiple files. These files will contain a C++ program that you have named appropriately, each file with an appropriate name and appropriate extension. Be sure that your program compiles using the g++ compiler before you submit it. To compile a program with multiple files, use the usual g++ command but instead of the single file you compiled before, compile *.cpp and the compiler will "grab" all the cpp files in that directory. So, you see, it's important that you put all the files for a particular program in their own directory! You don't have to list the header files; that will happen automatically. Use cssubmit in the usual way.

Background: assignment #3. You might have noticed while you were coding hw 3 that you were allowing Krusty to create new burgers, but not remembering the old burgers. That's a shame, to say the least. At worst, this violates all sorts of state and federal burger production laws1. Well, Krusty doesn't want to break all sorts of laws1. He wants to save a list of the burgers that he has offered on his menus, past and present. Krusty wants to be able to revisit his old pals (Krusty Double Wilbur Kermit Burger, Krusty Triumph Klogger Pickly Burger, Krusty Koronary Burger, .... )

Specifications: Your program is to be "menu driven" (that means you will present the user with a menu) with options: generate a new burger name; print list of burgers (alphabetically); remove a name from list; and, quit.

Details:

    • When option 1 is chosen, your program generates a name for a burger. But now, it's different! Krusty has reached a new level of laziness. Your program will not ask for a code. Oh no, that would take effort from Mr. K. No, your program will generate a burger for Krusty at random. You will use the system's rand() function to generate random integers for the quantities of each ingredient. Of course, these must meet the specs of a burger detailed in hw 3 (no more than 3 pickles, never 0 patties, etc.). The name will be generated and output to the user. But the name will also be put into a list of burger names that can be refered back to when necessary. However, if the burger name is already in the list, you will not add it to the list.

    • When option 2 is chosen, your program should present an alphabetical listing of the burgers along with their specs. Here's a good format to follow:

      • Krusty Double Wilbur Kermit Burger

  • 2 patties, 2 bacons, 3 pickles Krusty Veggie Burger 1 patty, 0 bacons, 3 pickles ...etc...

    • When option 3 is chosen, your program must ask the user for information identifying the burger to be removed. We can't do this by name since we don't yet know how to read past whitespace. So, specs on the burger's contents have to be used. You can either read them in individually, or prompt for our old friend the 'code'. If you bring back the code, then you'll have to write a function to extract the burger information from the code OR associate a code with each burger. You choose. And, if that information corresponds to no burger in the list, an error message is output.

    • Quiting the menu should be accomplishable via choosing the quit option only.

Details upon details:

    • The list that you will keep is to be implemented using an array of "burgers". Thus, you will have to structure your recording of burger information in a structured way using a structure in C++ that allows you to bundle structured information. The information on burgers that is to be included in this structured sorta thingy includes (but is not limited to)

        • burger name, a string

        • number of patties

        • number of bacons

        • number of pickles

        • burger code, an int (depending on your implementation choice)

    • Make the array of size 37; you'll never have more names than this for this assignment.

    • You will also have to declare an integer representing the size of the data set in the array so as to keep track of how many cells of the aforementioned array are actually data and not junk. When you add to the array (list of burgers), you have to incremet this integer. When you remove, decrement it. Also, your program should use this value to prevent the overflow of the array, and removal from an empty list.

    • Since you have to present the list in alphabetical order, you will have to write a sorting algorithm that sorts an array of burgers on name. You can use any sort you like, but write it yourself! Bubble sort is simple; compare on name only. Yes, the < , > , etc and == operators are defined for string objects.

    • Once you find a burger in the list, removing it from the list will be the hardest part of this assignment. First, your program has to determine if the code/burger is in the list. If so, you have to figure out a way to "remove" it. This can be done in several ways. There are easy ways and there are hard ways. Think carefully about how to accomplish this. And, ask yourself if you have to "actually remove" it. Be clever, and the C++ Gods will smile on you.

You are to use functions smartly! Think about your code before and during your marathon coding sessions. Plan!

Dont' Forget:

    1. use constants when applicable.

    2. make parameters const when applicable.

    3. write good function documentation.

When you submit:

    1. attempt to remove a burger w/ 2 patties, 2 bacons, 2 pickles

    2. generate a new burger....four times.

    3. print the list (of four burgers)

    4. remove the first burger listed

    5. remove the last burger

    6. print

    7. quit

As always, if you have questions, don't hesitate to ask your instructor

or the LEAD tutors.

1 NOT !