1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#include <iostream>
#include <string>
#include <iomanip>
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 *******************************
//*************************************************
int 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";
div_regions[2] = "Northwest";
div_regions[4] = "Southwest";
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(div_sales, top_div_index); //will no longer print the result
// leave debug statement in final product
cout << "debug for top_div_index: " << top_div_index << endl;
print_result(div_sales, div_regions, 4);
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 )
{
for(int i = 0; i<f_size; i++){
cin >> f_div_sales[i];
// loop to input quarterly sales
while (f_div_sales[i] <=0){
cout << "Enter quarterly sales for the " << f_div_regions[i] << "division:$ ";
}
}
}
//*************************************************
//************ findHighest ************************
//*************************************************
int findHighest (float f_div_sales[], int top_div_index)
{
float greatestSalesAmount = 0;
int save_index;
for(int i =0; i < top_div_index; i++) {
if(f_div_sales[i] > greatestSalesAmount){
greatestSalesAmount = f_div_sales[i];
save_index = i;
}
}
// 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(float f_div_sales[], string f_div_regions[], int index)
{
cout << "The division with the highest sales is " << f_div_regions[index] << "with $" << f_div_sales[index] << "\n";
// Be sure to include the division name and quarterly Sales in the final display
}
|