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

At a cereal packaging plant, the target is to put 1 Kg of cereal in each box, bu

ID: 3697858 • Letter: A

Question

At a cereal packaging plant, the target is to put 1 Kg of cereal in each box, but in practice some get a little more or some get less The boxes are weighed before and after filling so that the weight of the contents can be determined. Data for a sample of 20 boxes is shown in the file Data Exam. Write a program that gets as input parameters two vectors, containing before filling and after filling weights respectively. Then, inside your program: Count the number of boxes with mass of contents less than 980 g. Count the number of boxes with mass of contents larger than 1060 g. If more than 15% of the boxes are out of range, then display the message "Recalibrate", since the machine must be shut down and recalibrated. Include in your output: number of boxes with low weight, number of boxes with high weight, percent of boxes out of range, and the action that must be taken.

Explanation / Answer

//program to take weights of boxes(user decides the number) and find out the weight which is out of range and print it
// using vectors
#include <iostream>
#include <vector>
using namespace std;
int check(vector<int> emptyBox,vector<int> filledBox )//checking for the boxes which are out of range
{
   int i,outofRange=0;
   float weight=0.0;
   vector<int>::iterator v = emptyBox.begin();//predefined function of vector class,
//which is used to iterate over the values of the given vector
   vector<int>::iterator v1= filledBox.begin();
while( v != emptyBox.end() || v1 != filledBox.end()) //traverse till the end of vector using predefined functions end()
{
weight=(*v1)-(*v);

if((weight<=980)||(weight>=1060))
{
   ++outofRange;
   }

   ++v1;

++v;
}
float percentage= outofRange/emptyBox.size();// comparing 15% of the number of boxes
if(percentage>0.15)
{
    return 0;
}
else
{
    return 1;
}
}
int main()
{
   vector<int> emptyBox; // declaring vectors
   vector<int> filledBox;
   int input=0,i=1;
   cout<<"Start entering the data in grams.Enter -1 to stop "; //input for as many boxes as user wants to enter
   while(input!=-1)
   {
       cout<<" Please enter the weight before Filling weight for box number "<<i<<":";
       cin>>input;
       if(input==-1)break;
       emptyBox.push_back(input);
       cout<<" Please enter the weight of the box after filling for box number "<<i<<":";
       cin>>input;
       filledBox.push_back(input);
       ++i;
   }
   int result=check(emptyBox,filledBox); //calling the function
   if(result==0)
   {
       cout<<" Please recalibrate the machine ";
   }
   else
   {
   cout<<" You do not need to recalibrate the Machine.";
   }
   return 0;
}

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