Question
This lab assignment is designed to give you practice working with arrays. Work with a partner to create a program to read in and process
This lab assignment is designed to give you practice working with arrays. Work with a partner to create a program to read in and process data from the "Best BG Pizza" contest. Each partner can take a turn typing in a function but both partners should contribute to solving, testing and debugging each function.
Students were asked to "vote" for their favorite pizza place by buying pizza from that location on a particular weekend. The data file lab12.txt contains the number of pizzas sold that weekend by six pizza stores in BG. There are a total of 12 values in the file. The first six numbers are the number sold on Friday for each pizza place; the next six numbers are the number sold on Saturday for each place.
1. First create a new Visual Studio C++ project and a .cpp file with a main function. In the main function define a constant for the size declarator with the value 12. Use the constant to declare an array to hold the pizza data. Note: One array should be used to hold all 12 values.
For each task below, add a function prototype before the main function, a function call in the main function and the function definition after the main function. Typically, the array and its size are passed as arguments to each function but you may have other arguments and return values. Make sure each function is working before you go on to the next one. Tip: Arrays are passed by reference by default but no ampersand (&) is necessary.
2. Copy the data file lab12.txt to your project folder. Then add a function to read the data from the file and store it in your array. The code in the function should open the file, test the success of the open, read in the data from this file and store it in the array and close the file.
Note: The remaining tasks will use the data stored in the array.
3. Write a function to display the value stored in each element of the array using a loop. Your output should look something like this:
BG's Best Pizza
Your names
Element Pizzas Sold
0 25
1 40
2 20
etc. etc.
4. Write a function to find and return the total number of pizzas sold overall by the pizza stores for the weekend using a loop to find the sum of all the values in the array. The main function should display the result with a descriptive label. Make sure your total is correct.
* To earn the points for each function you must use a loop correctly to do the task, not separate assignment statements.
Bonus 1: (1 pt) Write a function to find and return the total number of pizzas sold on Friday by the six pizza stores. Note that the values for Friday's sales are stored in the first six elements of the array. The main function should display the result with a descriptive label. Make sure the total is correct. Then call the function a second time to find and return the total number of pizzas sold on Saturday by the six pizza stores. Note that these are the values stored in the last six elements of the array.
Discuss with your partner how you might change the function to be able to find either Friday or Saturday's total. Hint: One way would be to add another argument to the function to pass the starting position in the array for the six values to be totaled.
Bonus 2: (1 pt) Write a function to find the number of pizzas sold by each store over the weekend. For example, the number of pizzas sold by Store 1 on Friday is the value stored in the first array element and its number sold on Saturday is the value stored in the seventh array element so its total sales would be the sum of these two values. Store 2's values are stored in the second and eighth elements and so on. Figure out how to add the values in the correct pair of array elements for each store and print out a table like this:
Store number Pizzas sold on weekend
1 55
2 85
etc. etc.
Bonus 3: (1 pt) Write a recursive function to display the value stored in each element of the array. See slide 19-18 for one way to do this. Call this function right after your original display function and check that the output is the same.
CS2010 Lab 12: Grading Rubric
.cpp file turned in on Canvas, named with your last names.
2 main function correctly reads in pizza data from file and stores it in array.
1.5 Function correctly displays pizza data stored in the array. Function prototype, call and definition correct, parameters passed by value/by reference as needed.
1.5 Function correctly finds and returns total number of pizzas sold for the weekend by all stores. Function prototype, call and definition correct, parameters passed by value/by reference as needed.
Bonus 1! (1 pt) Function correctly finds and returns total number of pizzas sold on Friday/Saturday calling same function twice to get either Friday or Saturday's total.
Bonus 2! (1 pt) Function correctly finds and displays total number of pizzas sold by each store.
Bonus 3! (1 pt) Function recursively display array contents.
---------------------------------------------
5 Total Points (8 with bonuses)
lab12.txt contents:
25
40
20
55
15
20
30
45
20
40
25
30
sample
Fri Sat Total
25 30 55
40 45 85
20 20 40
55 40 95
15 25 40
20 30 50
175 190 365
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started