Question
C++ ( please help this is my second time posting) Do programming exercise top_div_array.cpp : Winning Division app (top_div.cpp) revisited to use arrays This is
C++ ( please help this is my second time posting)
Do programming exercise top_div_array.cpp: Winning Division app (top_div.cpp) revisited to use arrays This is the same program done last week but using and passing arrays instead of individual variables.
Start with the following file:
top_div_array_start.txt
(code)
#include#include #include using namespace std; // Function Prototypes // These prototypes already contain the proper parameters - // match your work accordingly void populate_div_sales(float[], string[], int); int findHighest (float[], int); // this function will now return the index for // the highest division sales void print_result(float[], string[], int); // displays result based on the index of // highest division sales //************************************************* //************ main ******************************* //************************************************* main () { int top_div_index = 0; // will be assigned the index of the top division sales float div_sales[4]; // array holding the divisions' sales amounts string div_regions[4]; // array holding division names // populate div_regions array div_regions[0] = "Northeast"; div_regions[1] = "Southeast"; // etc. populate_div_sales(div_sales, div_regions, 4); // params are already given to // help get started // leave debug statement in final product cout << "debug print for array div_sales_array" << endl; for (int i=0; i<4; i++) { cout << div_sales[i] << endl; } top_div_index = findHighest(..parameters here..); //will no longer prints the result // leave debug statement in final product cout << "debug for top_div_index: " << top_div_index << endl; print_result(..parameters here..); return 0; } //************ subroutine definitions below ******************* //************************************************* //************ populate_div_sales ***************** //************************************************* // The params for the function definition are given to help get started // - note the f_ preceding variable names. Use // this convention to help relate and contrast both the calling and the // receiving variables. void populate_div_sales(float f_div_sales[], string f_div_regions[], int f_size ) { // loop to input quarterly sales } //************************************************* //************ findHighest ************************ //************************************************* int findHighest (..add parameters..) { float greatestSalesAmount = 0; int save_index; // Use a 'for' loop to help determine the array element with highest sales and // saves the winner's index to save_index return save_index; } //************************************************* //************ print_result *********************** //************************************************* void print_result(..add parameters..) { // Be sure to include the division name and quarterly Sales in the final display }
(code end)
Comments for the necessary work are included in the start file, but here they are in brief:
This app will use two arrays of equal length - one for sales and the other for the divisions names.
The data in these arrays will be positioned so that the divisions will share the same indexes in both arrays.
Work with the data, which is already included with the start file.
Note that there are three functions instead of two, this time.
From now on, use the convention of adding f_ in front of variables passed to a function definition, in order to be clear that it relates directly to the calling variable but lives in the function (f_). For example: populate_div_sales(div_sales, div_regions, 4); //function call void populate_div_sales(float f_div_sales[], string f_div_regions[], int size ) //function definition
Same as always, do not accept dollar amounts less than $0.00.
Do keep the commented program structure and formatting. Remember, something similar is required until the end of the semester.
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