Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that keeps track of the sales for different types of salsa. The

ID: 3674214 • Letter: W

Question

Write a program that keeps track of the sales for different types of salsa. The program should use two arrays, one being an array of strings to hold the types of the salsa, and the other array being an array of integers that holds the number of jars sold during the past month for each salsa type.

Your program must have the following requirements:

A method that creates the array of salsa types. The method shall take the size of the array as a

parameter. The method shall ask the user for the types of salsa, and store each type in an array. For

simplicity sake, assume the salsa types will only be one word. This method shall return the array.

A method that creates the array of amounts sold. The method shall take the size of the array as a

parameter and the array of salsa types as a parameter. The method shall prompt the user to enter the amounts sold for each type of salsa. The method shall display the types of salsa in the prompts. The method shall return the array of amounts.

A method that computes the total salsa sold.

A method that returns the name of the best selling salsa type.

A method that returns the worst selling salsa type.

Use the above methods to create a program which:

Asks the user how many types of salsa were sold.

Asks the user for the names of each type of salsa.

Asks the user for the amounts sold for each type of salsa.

Displays a sales report in the format given in the sample below.

Explanation / Answer

#include <iostream>
using namespace std;

string* getSalsa(int n){
   string *salsa = new string[n];
   cout<<"Enter "<<n<<" salsa name."<<endl;
   for(int i=0; i<n; i++){
       cin>>salsa[i];
       }
   return salsa;
   }
  
int *getSalsaSold(string* salsa, int n){
   int *salsaSold = new int[n];
   for(int i=0; i<n; i++){
       cout<<"Enter amount sold of type "<<salsa[i]<<":";
       cin>>salsaSold[i];
       }
   return salsaSold;
   }
  
string getMaxSoldSalsa(int *salsaSold,string *salsa, int n){
   string maxSoldSalsa = salsa[0];
   int max = salsaSold[0];
   for(int i=1; i<n; i++){
       if(max < salsaSold[i]){
           max = salsaSold[i];
           maxSoldSalsa = salsa[i];
       }
       }
   return maxSoldSalsa;
   }
  
string getMinSoldSalsa(int *salsaSold,string *salsa, int n){
   string minSoldSalsa = salsa[0];
   int min = salsaSold[0];
   for(int i=1; i<n; i++){
       if(min > salsaSold[i]){
           min = salsaSold[i];
           minSoldSalsa = salsa[i];
       }
       }
   return minSoldSalsa;
   }
      
int getTotalSold(int *salsaSold, int n){
   int total = salsaSold[0];
   for(int i=1; i<n; i++){
       total = total + salsaSold[i];
       }
   return total;
   }
  
int main() {
   int n;
   cout<<"How many types of salsa has sold: ";
   cin>>n;
  
   string *salsa = getSalsa(n);
   int *slasaSold = getSalsaSold(salsa,n);
  
   int total = getTotalSold(slasaSold,n);
   cout<<"Total sold salsa: "<<total<<endl;
  
   string minSoldSalsa = getMinSoldSalsa(slasaSold, salsa,n);
   cout<<"Min sold salsa: "<<minSoldSalsa<<endl;
  
   string maxSoldSalsa = getMaxSoldSalsa(slasaSold, salsa,n);
   cout<<"Max sold salsa: "<<maxSoldSalsa<<endl;
  
  
return 0;
}

/*

Output:

How many types of salsa has sold: 5
Enter 5 salsa name.
Tomato
Chilly
Spicy
Veg
Carrot
Enter amount sold of type Tomato:12
Enter amount sold of type Chilly:32
Enter amount sold of type Spicy:45
Enter amount sold of type Veg:34
Enter amount sold of type Carrot:23
Total sold salsa: 146
Min sold salsa: Tomato
Max sold salsa: Spicy

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote