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

O-So-Good Chocolate Company Report The O-So-Good Chocolate Company produces diff

ID: 3664229 • Letter: O

Question

O-So-Good Chocolate Company Report

The O-So-Good Chocolate Company produces different types of chocolates daily. They need a little summary report that shows how much of each chocolate type they produce for a given month. This way they can plan next month’s production schedule. They record each day’s production for each chocolate type in a file named chocolates.txt.

The data indicates the batches of chocolates made each day and is described as the type of chocolates produced and the number of pieces in each batch. The company makes several different chocolates each day so there will be several different entries for a given day. The input will be two numbers per line where the first number is the chocolate type and the second is the number of pieces made for that batch. Each input line is a batch. There are 25 chocolate types numbered 1 to 25.

         For example:

                                          3    30              chocolate type 3 there are 30 pieces

                                          21 45              chocolate type 21 there are 45 pieces

                                          6    28              chocolate type 6 there are 28 pieces

                                          etc..

The company can produce up to 25 different kinds of chocolates. The input file is one month of this data.

You are to count the number of chocolates pieces for each type of chocolate produced and the number of batches for the given month.

The report should have a title and headings. Output for each type of chocolate, the total pieces produced, the total batches produced, the average number of pieces produced in each batch. Label all output and make it a nice readable report, table format.

Also print out which candy type had the largest number candy pieces produce this month. (Print the candy type and the number of pieces)

You must use arrays, pass arrays, use functions, and put your data into a file.

Hints:

   The chocolates types are 1 to 25. You will need to have one array to keep up with the total pieces (accumulate) for each of the chocolates. Read in a chocolate type and its number of pieces and add to the appropriate location in the array:

infile >> chocolatetype >> pieces;

   chocoPieces[ chocolatetype-1] = chocoPieces[ chocolatetype -1 ] + piecies.    ‘Cool isn’t it?’

You will also have to count the batch:

    chocoBatches [ chocolatetype -1 ] = chocoBatches[ chocolatype – 1] + 1;

    or chocoBatches[ chocolatetype – 1 ] ++;

Explanation / Answer

Answer:

Here we are using

    chocoBatches [ chocolatetype -1 ] = chocoBatches[ chocolatype – 1] + 1;

    or chocoBatches[ chocolatetype – 1 ] ++;

we are subtracting 1 from the chocolatetype because in c++ the arrays starts from 0.

If the size of the array is 25 means, array indices ranges from 0 to 24.

Thus, If the chocolatetype is 18 means, it will get stored in array position 17 .

/*------------------------------------------------------------------------------------------------*/

// Program

#include <iostream> // input and output functionality
#include <fstream> //for input and output files
#include <iomanip> // std::setw
using namespace std;
void analysis(int chocoBatches[25],long chocoPieces[25]);
int main()
{
int chocoBatches[25];
long chocoPieces[25];
analysis(chocoBatches,chocoPieces);
return 0;
}
void analysis(int chocoBatches[25],long chocoPieces[25])
{
int pieces;
int chocolatetype;
ifstream infile; //input file stream variable
infile.open("chocholate.txt");
while(!infile.eof())
{
    infile >> chocolatetype >> pieces;
chocoPieces[ chocolatetype-1] = chocoPieces[ chocolatetype -1 ] + pieces;
chocoBatches [chocolatetype-1] = chocoBatches[chocolatetype-1] + 1;
}

cout<<"ChocoBatches"<<setw(5)<<"chocoPieces";
for(int i=0;i<25;i++)
{
    cout<<endl<<chocoBatches[i]<<setw(10)<<chocoPieces[i];
}
}