Write code using struct-defined data types Organize source code in multiple header and implementation files (.h and
Question:
- Write code using struct-defined data types
- Organize source code in multiple header and implementation files (.h and .cpp files).
- Create, initialize, read, update, and display the contents of struct variables
- Use functions with struct parameters and return types
- Read from an input data file
- Use C-strings to represent character strings
Task - This is the Grade C version.
Programming Task
You are asked to write a program in C++ to keep track of a list of doughnuts. The program should load all doughnut information from a data file (voodoo.txt)once the app is started. The program will allow the user to view, add, remove, and search for doughnuts. The app should save the data back to the same data file when the program exits. Please see Sample Run under Criteria for Success.
In order to earn a C your Program Should Do
- Write an interactive text based menu interface (using a loop) that will allow the user to
- Enter information for a new doughnut.
- Display information for all the doughnuts in the database sorted by the name with index number for each doughnut.
- Quit
For each doughnut type, you need to keep track of:
- Number in inventory (any whole number between 1 and 200). Assume that there will be at least one and not more than 200 of each kind on hand.
- Doughnut name (e.g., Voodoo Doll)
- Price. Assume that the price will be between $1.00 and $10.00.
- Toppings and/or filling (e.g., bacon and maple frosting)
- Type - Ring, Round, Bar, Cannoli, or Other. The type is represented by an enumeration value or a constant.
Allow the program to keep looping until the user wants to quit. When the program starts, it should load the doughnuts from an external file (”voodoo.txt”) into memory.
- When the program loads the data into the array, it should insert them sorted alphabetically by the doughnut’s name. Do not use a sorting algorithm - as you insert the doughnut into the array, make sure they are inserted in the right position alphabetically.
- When a user enters information about the new doughnut, the program needs to read them in, and insert them in the correct position alphabetically.
- When the user is running the program, keep the doughnut list saved in memory. When the user quits the program, write them to the external data file (”voodoo.txt”). Only write to the file at program termination. Use semicolons for the data delimiter. The file format could look like:
Inventory count;doughnut name;price;ingredients;type
150;Voodoo Doll;4.5;raspberry jelly and chocolate frosting;4
25;Ring of Fire;2.5;cinnamon sugar and cayenne pepper;0
20;Wild Berry Cannolo;3.5;berry filling cinnamon and sugar;3
50;Portland Creme;3.5;Bavarian creme and chocolate frosting;1
30;Strawberry Go-Tart;4.0;strawberry filling and vanilla frosting;2
20;Oh captain my captain;3.0;vanilla frosting and captain crunch;1
20;Sweet cream Cannoli;3.5;Bavarian sweet cream;3
40;Marshall Mathers;3.0;vanilla frosting and mini M&Ms;0
35;Memphis Mafia;5.5;banana cinnamon chocolate peanut butter;4
65;Bacon Maple Bar;4.5;maple frosting and bacon;2
- The ';' is used as a delimiter or field separator. Each record ends with a new line character, including the last line.
- You may include the column header information on the first line of the data file, or you may remove it. If you include the column headers, make sure you skip over it before loading data.
- The numbers at the end of each record - 0 through 4 - identify the Type of the doughnut as an enumeration or constant integer. For example, 0 could be Ring, 1 could be Round, 2 could be Bar, 3 could be Cannoli, and 4 could be Others (fritters, dolls, etc. that don’t have a typical shape).
- Use a struct named Doughnut to model each doughnut. For the string attributes, such as doughnut name and ingredients, you are required to use a C-string, a character array terminated by ‘0’ (the null terminator). You can not use the library or declare any string objects, but you may use the and libraries to manipulate c-strings and characters. For this first assignment, use a constant value for the maximum c-string length, such as 101 characters (100 + 1 for the null character). Make sure to use a separate constant value for the size of the array (30 maximum).
- Use an integer for the inventory count.
- For the Type attribute, you can use enum or named integer constants.
- You may not use any while (true) loops or any break statements inside of while loops. Use sentinel, flag or counter controlled loops only.
- No global variables. Globals are also referred to as variables declared at file scope, declared outside of a function. You may declare constant globals (because they are not variables).
- Data Validation: (Data validation changes for each grade level - check carefully when you go from one grade level to the next.)
- Data validation includes checking for values within proper ranges (such as 1 to 200 for the inventory count).
- You must do data validation for new data entered by the user for the items listed below. You do not need to do data validation for data read from the file (assume the data in the file is correct, and if it’s not, then correct it).
- You must do data validation for the menu options (see Sample Run in Criteria for Success). Your program must accept uppercase and lowercase letters for menu options.
- You must do data validation for inventory count (1 to 200 inclusive).
- You must do data validation for price (must be between $1.00 and $10.00 inclusive).
- You must follow the C++ style guidelines. This document is also linked from “C++ code/style guide” in the Class Details module under the Content menu on D2L.
- Use an array of structs to model the collection of doughnuts. You can have a maximum of 30 doughnuts in your list (and check for index out of bounds).
- See the Inventory example in zyBooks. 15: CS161B: Section 15.2 (strstr and strcmp examples), the video store example in 15: CS161B: Section 15.6 (enums and multiple files and looping menu), and 15:CS161B: Section 15.7, Example to insert sorted into an array. You can find links to these under Criteria for Success.
- For submission, your data file should contain at least 10 lines of test data. It should have test cases for different doughnut names, ingredients, prices and so on.
- You must have multiple files for this assignment. doughnuts.h for the struct and the function prototypes, doughnuts.cpp for the function implementations, and main.h and main.cpp for other functions and implementations, and the main() function.
Criteria for Success
Sample Run
The below sample run is an example of how the output should look. The user responses are in Blue. Notice that both lowercase and uppercase valid choices are accepted. For list output, you may make the extra effort to add column headers, have column-formatted output using setw(), use dollar signs, etc. if you wish. Notice that the prices are set to two decimal places (using , setprecision(), showpoint, etc.) and the type names are used (“Bar” rather than 2):
Welcome to Voodoo Doughnut! This program will help you manage your doughnut inventory. 10 doughnuts added from the data file.
Pick an option from below:
(A)Add a new doughnut (L)List doughnuts by name (Q)Quit
L 1. 65;Bacon Maple Bar;4.50;maple frosting and bacon;Bar 2. 40;Marshall Mathers;3.00;vanilla frosting and mini M&Ms;Ring 3. 35;Memphis Mafia;5.50;banana cinnamon chocolate peanut butter;Other 4. 20;Oh captain my captain;3.00;vanilla frosting and captain crunch;Round 5. 50;Portland Creme;3.50;Bavarian creme and chocolate frosting;Round 6. 25;Ring of Fire;2.50;cinnamon sugar and cayenne pepper;Ring 7. 30;Strawberry Go-Tart;4.00;strawberry filling and vanilla frosting;Bar 8. 20;Sweet cream Cannoli;3.50;Bavarian sweet cream;Cannoli 9. 150;Voodoo Doll;4.50;raspberry jelly and chocolate frosting;Other 10. 20;Wild Berry Cannolo;3.50;berry filling cinnamon and sugar;Cannoli
Pick an option from below:
(A)Add a new doughnut (L)List doughnuts by name (Q)Quit
p Invalid option!! Please try again!
Pick an option from below:
(A)Add a new doughnut (L)List doughnuts by name (Q)Quit
a Enter the quantity (whole numbers between 1 and 200): 250 Invalid quantity! Must be between 1 and 200 inclusive! Enter the quantity (whole numbers between 1 and 200): 80 Enter the doughnut name (100 characters or less): Banana Cream Pie Enter the price (between 1.00 and 10.00): -8.0 Invalid price! Must be between 1.00 and 10.00 inclusive! Enter the price (between 1.00 and 10.00): 3.75 Enter the ingredients (100 characters or less): Banana Bavarian cream vanilla frosting cinnamon Enter the type 0-Ring, 1-Round, 2-Bar, 3-Cannoli, and 4-Others): 6 Invalid Type! Enter the type 0-Ring, 1-Round, 2-Bar, 3-Cannoli, and 4-Others): 1
Doughnut added!
1. 65;Bacon Maple Bar;4.50;maple frosting and bacon;Bar 2. 80:Banana Cream Pie;3.75;Banana Bavarian cream vanilla frosting cinnamon;Round 3. 40;Marshall Mathers;3.00;vanilla frosting and mini M&Ms;Ring 4. 35;Memphis Mafia;5.50;banana cinnamon chocolate peanut butter;Other 5. 20;Oh captain my captain;3.00;vanilla frosting and captain crunch;Round 6. 50;Portland Creme;3.50;Bavarian creme and chocolate frosting;Round 7. 25;Ring of Fire;2.50;cinnamon sugar and cayenne pepper;Ring 8. 30;Strawberry Go-Tart;4.00;strawberry filling and vanilla frosting;Bar 9. 20;Sweet cream Cannolo;3.50;Bavarian sweet cream;Cannoli 10. 150;Voodoo Doll;4.50;raspberry jelly and chocolate frosting;Other 11. 20;Wild Berry Cannolo;3.50;berry filling cinnamon and sugar;Cannoli
Pick an option from below:
(A)Add a new doughnut (L)List doughnuts by name (Q)Quit |
Systems Analysis And Design
ISBN: 9781118057629
5th Edition
Authors: Alan Dennis, Barbara Haley Wixom, Roberta M. Roth