83.8k views
2 votes
Write a program that lets the Michigan Popcorn Company keep track of their sales for seven different types of popcorn they produce: plain, butter, caramel, cheese, chocolate, turtle and zebra. It should use two parallel seven-element arrays: an array of strings that holds the seven popcorn names and an array of integers that holds the number of bags of popcorn sold during the past month for each popcorn flavor. The names should be stored using an initialization list at the time the flavors array is created. The program should prompt the user to enter the number of bags sold for each flavor. Once the popcorn data has been entered, the program should produce a report for each popcorn type, total sales, and the names of the highest selling and lowest selling products. Be sure to include comments throughout your code where appropriate. Complete the C++ code using Visual Studio or Xcode, compress (zip) and upload the entire project folder to the Blackboard assignment area by clicking on the Browse My Computer button or by dragging the file inside the Attach Files box g

User DonnaLea
by
7.0k points

1 Answer

4 votes

Answer:

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. // declare and initialize popcorn name array
  6. string popcorn_name[7] = {"plain", "butter", "caramel", "cheese", "chocolate", "turtle", "zebra"};
  7. // declare and initialize sales array with 7 elements
  8. int sales[7];
  9. // A loop to prompt user to enter sales for each popcorn
  10. for(int i=0; i < 7; i++){
  11. cout<<"Enter number of sales for " + popcorn_name[i] + " :";
  12. cin>>sales[i];
  13. }
  14. // Find maximum sales
  15. int max = sales[0];
  16. int maxIndex = 0;
  17. for(int j=1; j < 7; j++){
  18. if(max < sales[j]){
  19. max = sales[j];
  20. maxIndex = j;
  21. }
  22. }
  23. // Find minimum sales
  24. int min = sales[0];
  25. int minIndex = 0;
  26. for(int k=1; k < 7; k++){
  27. if(min > sales[k]){
  28. min = sales[k];
  29. minIndex = k;
  30. }
  31. }
  32. // Print popcorn name and sales
  33. for(int l=0; l < 7 ; l++){
  34. cout<<popcorn_name[l]<<"\\";
  35. cout<<"Sales: "<< sales[l]<<"\\\\";
  36. }
  37. // Print popcorn name with maximum and minimum sales
  38. cout<<"Highest selling: "<< popcorn_name[maxIndex]<<"\\";
  39. cout<<"Lowest selling: "<<popcorn_name[minIndex]<<"\\";
  40. return 0;
  41. }

Step-by-step explanation:

Create two arrays to hold the list of popcorn name and their sales (Line 5-8). Next prompt user to input the sales for each popcorn (Line 10-14). Get the maximum sales of the popcorn (Line 17-24) and minimum sales (Line 27-34). Print the popcorn name and sales (Line 37-40) and the popcorn name with highest and lowest selling (Line 43-44).

User Kartik Chugh
by
6.0k points