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
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int GetSalesData (string [], int []);
int PositionOfLargest (int []);
int PositionOfSmallest (int []);
void DisplayReport (string[], int[], int);
const int Size = 5;
int main()
{
string Name[Size] = {"mild", "medium", "sweet","hot" , "zesty"};
int Sales[Size];
int TotalJarsSold = GetSalesData(Name, Sales);
DisplayReport(Name ,Sales ,TotalJarsSold);
return 0;
}
int GetSalesData(string Name[], int Sales[])
{
int Total = 0;
for (int Type = 0; Type < Size; Type++)
{
cout << "Jard sold last month of " << Name[Type] << ": ";
cin >> Sales[Type];
while (Sales[Type] <0)
{
cout << "Jars sold must be 0 or more. Please re-enter: ";
cin >> Sales[Type];
}
Total += Sales[Type];
}
return Total;
}
void DisplayReport (string Name[], int Sales[], int Total[])
{
int HighSalesProduct = PositionOfLargest(Sales);
int LowSalesProduct = PositionOfSmallest(Sales);
cout << "\n\n Salsa Sales Report \n\n";
cout << "Name Jars Sold \n";
cout << "______________________\n";
for (int Type = 0; Type < Size; Type++)
cout << Name[Type] << setw(11) << Sales[Type] << endl;
cout << "\nTotal Sales:" << Total << endl;
cout << "\nHigh Seller:" << Name[HighSalesProduct] << endl;
cout << "\nLow Seller:" << Name[LowSalesProduct] << endl;
}
int PositionOfLargest(int array[])
{
int IndexOfLargest = 0;
for (int Pos = 1; Pos < Size; Pos++)
{
if (array[Pos] > array[IndexOfLargest])
IndexOfLargest = Pos;
}
return IndexOfLargest;
}
int PositionOfSmallest(int array[])
{
int IndexOfSmallest = 0;
for (int Pos = 1; Pos < Size; Pos++)
{
if (array[Pos] < array[IndexOfSmallest])
IndexOfSmallest = Pos;
}
return IndexOfSmallest;
}
|