You are a quality engineer working for MARS Inc. and responsible to ensure that
ID: 3709977 • Letter: Y
Question
You are a quality engineer working for MARS Inc. and responsible to ensure that the color combination is correct for each package of MM's. Here is some data to help you determine if the correct amount of brown mm's are in each package. Flag the packages that are incorrect. Data Filename: mm testlot56.txt The data in the file has the following format: 12 58 10 18 57 13 3 57 15 42 56 16 29 59 14 The first column is the package number (selected at random). The second column is the number of mm's in the package. The third column is the number of brown mm's in the package. Your Assignment: Write a c++ program that will read in the package number, number of mm's and the number of brown mm's in the package. Outpat to the console any package that is over 25% brown mm's and requested summary data. For example, from the sample data listed above, the console would display: Package #3 is out of specification. The % of brown mm's is: 26% package #42 is out of specification. The % of brown mm's is 29% There were 5 packages sampled The average % of brown mm's in each package is xxx%Explanation / Answer
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<string.h>
void main(){
int packageNumber, mm, brownMm, per;
int count = 0;
int totalPer = 0;
ifstream inputFile;
inputFile.open("mm_testlot56.txt");
if(!inputFile)
cout<<"file does not exist";
string line;
while(getline(inputFile, line))
{
istringstream iss(line);
if(!(iss>>packageNumber>>mm>>brownMm)) break;
count++; //increment the number of package read
per = (brownMm / mm) * 100; // calculate percentage of brown mm in current package
totalPer = totalper + per; //update total percentage of brown mm in all the packages
if(per > 25)
cout<<" Package #"<<packageNumber<<" is out of specification. The % of brown mm's is: "<<per<<"%";
}
inputFile.close();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.