c++ Write a program that lets a maker of chips and salsa keep track of sales for
ID: 3814200 • Letter: C
Question
c++
Write a program that lets a maker of chips and salsa keep track of sales for five different types of salsa: mild, medium, sweet, hot, and zesty. The program should use two parallel 5- element arrays: an array of strings that holds the five salsa names and an array of integers that holds the number of jars sold during the past month for each salsa type. The salsa names should be stored using an initialization list (using {}) at the time the name array is created. The program should prompt the user to enter the number of jars sold for each type. Once this sales data has been entered, the program should produce a report that displays sales for each salsa type, total sales, and the names of the highest selling and lowest selling products.
create the following
fillJarsSoldArray – prompts the user to enter the number of jars sold for each type and fills the jars sold array.
printSales – displays sales for each salsa type.
getTotal – returns the total sales. Display the total in the main.
getHighestLowestSelling – returns the indices of the highest and lowest selling salsas. Do not pass the name array to this function. Display the highest and lowest selling types in the main.
Enter the number of jars sold for mild: -1 Enter the number of jars sold for mild: -100 Enter the number of jars sold for mild: 100 Enter the number of jars sold for medium 500 Enter the number of jars sold for sweet: 0 Enter the number of jars sold for hot 250 Enter the number of jars sold for zesty: 1000 mild 100 500 medium 3Weet 250 hot 1000 Ze3ty The total number of jars sold is 1850 The highest selling type is zesty The lowest selling type is sweetExplanation / Answer
#include<iostream>
#include <string>
using namespace std;
void fillJarsSoldArray(string names[], int *numOfJars) //Function to get number of jars sold for each type
{
int n=-1;
for(int i=0;i<5;i++)
{
do{
cout<<"Enter the number of jars sold for "<<names[i]<<": ";
cin>>n;
}while(n<0);
numOfJars[i]=n;
cout<<endl;
}
}
void printSales(string names[], int numOfJars[]) //Function to print sales of each type of salsa
{
for(int i=0;i<5;i++)
{
cout<<" "<<names[i]<<" "<<numOfJars[i];
}
}
int getTotal(int numOfJars[]) //Function to get total
{
int total = 0;
for(int i=0;i<5;i++)
{
total += numOfJars[i];
}
return total;
}
void getHighestLowestSelling(int numOfJars[],int& highestSelling,int& lowestSelling) //Function to get highest and lowest selling salsa
{
highestSelling =numOfJars[0];
lowestSelling=numOfJars[0];
for(int i=1;i<5;i++)
{
if(numOfJars[i]>highestSelling)
highestSelling = i;
if(numOfJars[i]<lowestSelling)
lowestSelling = i;
}
}
int main()
{
string names[]= {"mild","medium","sweet","hot","zesty"};
int numOfJars[5];
fillJarsSoldArray(names,numOfJars);
printSales(names,numOfJars);
int total = getTotal(numOfJars);
cout<<" The total number of jars sold is "<<total;
int highestSelling,lowestSelling;
getHighestLowestSelling(numOfJars,highestSelling,lowestSelling);
cout<<" The highest selling type is "<<names[highestSelling];
cout<<" The lowest selling type is "<<names[lowestSelling];
cout<<endl;
return 0;
}
Sample Output
Enter the number of jars sold for mild: -1
Enter the number of jars sold for mild: -100
Enter the number of jars sold for mild: 100
Enter the number of jars sold for medium: 500
Enter the number of jars sold for sweet: 0
Enter the number of jars sold for hot: 250
Enter the number of jars sold for zesty: 1000
mild 100
medium 500
sweet 0
hot 250
zesty 1000
The total number of jars sold is 1850
The highest selling type is zesty
The lowest selling type is sweet
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.