Question

Write a C++ program that lets a maker of chips and salsa keep track of their...

Write a C++ program that lets a maker of chips and salsa keep track of their sales for five

different types of salsa they produce: mild, medium, sweet, hot, and zesty. It should use

two parallel five-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 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.

Note: Separate the files into three : Header.h , Functions.cpp, and Main.cpp

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

//Header.h

#ifndef HEADER_H

#define HEADER_H

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

class Salsa

{

private:

    string* salsaFlavours;

    int numOfFlavoursSold;

    int* soldCount;

public:

    Salsa(string* sf, int nsf);

    ~Salsa();

    void getSalesReport();

    void getTotalSales();

    void getHighestSelling();

    void getLowestSelling();

};

#endif

//Functions.cpp

#include "Header.h"

Salsa::Salsa(string* sf, int nsf)

{

    numOfFlavoursSold = nsf;

    salsaFlavours = new string[nsf];

    soldCount = new int[nsf];

    int i;

    for(i = 0; i < numOfFlavoursSold; i++)

    {

        salsaFlavours[i] = sf[i];

    }

}

Salsa::~Salsa()

{

    delete[] salsaFlavours;

    delete[] soldCount;

}

void Salsa::getSalesReport()

{

    int count;

    int num;

    for (count = 0; count < numOfFlavoursSold; count++)

    {

        cout << "Jar sold last month of " << salsaFlavours[count] << ": ";

        cin >> num;

        while(num <= 0)

        {

            cout << "Jars sold must be greater than or equal to 0." << endl;

            cout << "Re-enter jars sold for last month " << endl;

            cin >> num;

        }

        soldCount[count] = num;

    }

    cout << endl << endl;

    cout << "================================================================================" << endl;

               cout << "=====================================REPORT=====================================" << endl;

               cout << "================================================================================" << endl;

               cout << endl;

    cout << left << setw(40) << "Salsa" << right << setw(40) << "# sold" << endl;

    cout << "--------------------------------------------------------------------------------" << endl;

    for (count = 0; count < numOfFlavoursSold; count++)

        cout << left << setw(40) << salsaFlavours[count] << right << setw(40) << soldCount[count] << endl;

    getTotalSales();

    getHighestSelling();

    getLowestSelling();

    cout << endl << endl;

}

void Salsa::getTotalSales()

{

    int count;

    int total = 0;

    for (count = 0; count < numOfFlavoursSold; count++)

        total += soldCount[count];

    cout << endl << left << setw(40) << "Total Sales:" << right << setw(40) << total;

}

void Salsa::getHighestSelling()

{

    int count;

    int highest = soldCount[0];

    int index = 0;

    for (count = 0; count < numOfFlavoursSold; count++)

    {

        if (soldCount[count] > highest)

        {

            highest = soldCount[count];

            index = count;

        }

    }

    cout << endl << left << setw(40) << "Highest selling product:" << right << setw(40) << salsaFlavours[index];

}

void Salsa::getLowestSelling()

{

    int count;

    int lowest = soldCount[0];

    int index = 0;

    for (count = 0; count < numOfFlavoursSold; count++)

    {

        if (soldCount[count] < lowest)

        {

            lowest = soldCount[count];

            index = count;

        }

    }

    cout << endl << left << setw(40) << "Lowest selling product:" << right << setw(40) << salsaFlavours[index];

}

//Main.cpp

#include <iostream>

#include <string>

#include <iomanip>

#include "Header.h"

using namespace std;

int main()

{

    const int NUM_FLAV = 5;

    string flavor[NUM_FLAV] = { "mild", "medium", "sweet", "hot", "zesty" };

    Salsa sold(flavor, NUM_FLAV);

    sold.getSalesReport();

    return 0;

}

Output:


Add a comment
Know the answer?
Add Answer to:
Write a C++ program that lets a maker of chips and salsa keep track of their...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program 2 <100 points>: Chips and Salsa (chipsSalsa.cpp) Write a program that lets a maker of...

    Program 2 <100 points>: Chips and Salsa (chipsSalsa.cpp) 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...

  • In C++ write a program: Your goal is to ask record the sales for 5 different...

    In C++ write a program: Your goal is to ask record the sales for 5 different types of salsa, the total sales, and the names of the highest and lowest selling products. Your program should have the following:  The name of the program should be Assignment7.  3 comment lines (description of the program, author, and date).  Create a string array that stores five different types of salsas: mild, medium, sweet, hot, and zesty. The salsa names should...

  • In this module, you learned about Arrays in C++ and how to implement arrays within your...

    In this module, you learned about Arrays in C++ and how to implement arrays within your C++ programs. For this assignment, you will implement your knowledge of arrays for Michigan Popcorn Company’s sales management system. 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...

  • Need to revise the following code to use an array of product objects instead of two...

    Need to revise the following code to use an array of product objects instead of two parallel arrays. The product class will need member variables to hold a product name and a quantity. #include<iostream> #include<string> using namespace std; int main() { //Declare variables const int salsaTypes = 5; const int jarsSold = 5; string salsa[salsaTypes] = { "Mild", "Medium", "Sweet", "Hot", "Zesty" }; int jars[jarsSold]; int totalSales, highestSales, lowestSales; string highestSoldProduct; string lowesetSoldProduct; //Repeat loop for all salsas for (int...

  • In Java with comments. Write a program that computes the cost of flowers sold at a...

    In Java with comments. Write a program that computes the cost of flowers sold at a flower stand. Five kinds of flowers—petunia, pansy, rose, violet, and carnation— are stocked and cost, respectively, 50¢, 75¢, $1.50, 50¢, and 80¢ per flower. Create an array of strings that holds the names of these flowers. Create another array that holds the cost of each corresponding flower. Your program should read the name of a flower and the quantity desired by a customer. Locate...

  • Write a complete C++ program that analyzes the following sorts by keeping track of how long...

    Write a complete C++ program that analyzes the following sorts by keeping track of how long they take to sort arrays of longS of size 5000, 10000, and 100000, as well as the number of swaps and comparisons they take in doing so: Insertion sort Selection sort Quick sort shell sort(using gaps of n/2, n/4, n/8, ..., 1) for 20, the gaps would be 10, 5, 2, and 1 shell sort(using gaps based on 2^k + 1, but starting at...

  • c++ cout and cin 2. Write a program that uses parallel arrays to keep track of...

    c++ cout and cin 2. Write a program that uses parallel arrays to keep track of 5 courses. Each course will have a discipline code (like MTH or CS), a course number (use only integers), and a course title (like "Computer Science I"). There should be 5 functions: 1. intro () - instructions about what is coming up 2. void fill Courses ..... with parameters for the 3 arrays ....) 3. int courseSearch.... with parameter for the courses array and...

  • C# Write a program that takes a list of information and grades of the students of...

    C# Write a program that takes a list of information and grades of the students of a class and perform some processing. Take the following steps to write the program. The program must give the user two options such as a menu. At the beginning of the program must ask the following from the user: Which task you want to do (choose an option between 1-2), 1- Entering new information 2- Searching a student If the user types something rather...

  • Need help with this programming please this is the instruction my teacher provided Write a C++...

    Need help with this programming please this is the instruction my teacher provided Write a C++ class called "Sales" and a main( ) function that uses the class. Also, write documentation of your project. Below is a specification of the class. . INTRODUCTION A company has four salespeople (1 to 4) who sell five different products ( to 5)1. Once a day each salesperson passes in a slip for each different type of product sold. Each slip contains: The salesperson...

  • Please Write the following program in c# You are to write an application which will create...

    Please Write the following program in c# You are to write an application which will create a company, add agents (their name, ID, and weekly sales) to that company, and printout the details of all agents in the company. The application will contain three classes: Agent.cs, Company.cs, and CompanyTest.cs (this class is already provided). Flow of the application: The CompanyTest class creates an object of the Company class and reserves space for five agents. At this point if you call...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT