Problem 2 \"Sutures: Sutures are strands or fibers used to sew living tissue tog
ID: 3802622 • Letter: P
Question
Problem 2 "Sutures: Sutures are strands or fibers used to sew living tissue together after an injury or an operation. Packages of sutures must be sealed carefully before they are shipped to hospitals to prevent contamination. The packages are sealed on a machine with a sealing die. For the sealing to be a success, the die must be maintained at an established temperature, and contact the package with a predetermined pressure for an established time period. This time period is called the dwell time. The acceptable ranges for these three conditions are as follows: Temperature: 150-170 60-70 psi Pressure: Dwell Time: 2-2.5 sec Write a C++ program that reads a data file (from disk) containing data on batches of rejected sutures the data is shown below. Each line of the file contains a batch number, temperature, pressure and dwell time for a batch. As the Quality Control Engineer, you need to analyze the data and compute the percent of batches rejected due to temperature, percent rejected due to pressure and percent rejected due to dwell time. If a specific batch was rejected in more than one category, it should be counted in all of the applicable totals. Write the output to a file. This output file will have your team name or names, and the results in terms of percent of failures in each category, the total numbers in each category and the total number of batches rejected.Explanation / Answer
c++ code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
ofstream myfileout;
cout << "Please enter filename" << endl;
string filename;
cin >> filename;
int n = 0;
int f1 = 0;
int f2 = 0;
int f3 = 0;
string line;
myfileout.open("output.txt");
ifstream myfile (filename.c_str());
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
string buf; // Have a buffer string
stringstream ss(line); // Insert the string into a stream
vector<string> tokens; // Create vector to hold our words
while (ss >> buf)
tokens.push_back(buf);
float c1 = atof(tokens[1].c_str() ) ;
float c2 = atof(tokens[2].c_str() ) ;
float c3 = atof(tokens[3].c_str() ) ;
bool flag = true;
if(c1 > 170 or c1 < 150)
{
f1 = f1 + 1;
flag = false;
}
if(c2 > 70 or c2 < 60)
{
f2 = f2 + 1;
flag = false;
}
if(c3 > 2.5 or c3 < 2)
{
f3 = f3 + 1;
flag = false;
}
if(flag == false)
{
n = n +1;
}
}
myfileout << "Total number of batches rejected " << n << endl;
myfileout << "Total number of batches rejected due to temperature = " << f1 << endl;
myfileout << "Percentage of number of batches rejected due to temperature = " << float(f1)/float(n)*100.0 << endl;
myfileout << "Total number of batches rejected due to pressure = " << f2 << endl;
myfileout << "Percentage of number of batches rejected due to pressure = " << float(f2)/float(n)*100.0 << endl;
myfileout << "Total number of batches rejected due to dwell time = " << f3 << endl;
myfileout << "Percentage of number of batches rejected due to dwell time = " << float(f3)/float(n)*100.0 << endl;
myfile.close();
}
else
{
cout << "Unable to open file" << endl;
exit(1);
}
return 0;
}
Sample input.txt:
#include <bits/stdc++.h>
using namespace std;
int main()
{
ofstream myfileout;
cout << "Please enter filename" << endl;
string filename;
cin >> filename;
int n = 0;
int f1 = 0;
int f2 = 0;
int f3 = 0;
string line;
myfileout.open("output.txt");
ifstream myfile (filename.c_str());
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
string buf; // Have a buffer string
stringstream ss(line); // Insert the string into a stream
vector<string> tokens; // Create vector to hold our words
while (ss >> buf)
tokens.push_back(buf);
float c1 = atof(tokens[1].c_str() ) ;
float c2 = atof(tokens[2].c_str() ) ;
float c3 = atof(tokens[3].c_str() ) ;
bool flag = true;
if(c1 > 170 or c1 < 150)
{
f1 = f1 + 1;
flag = false;
}
if(c2 > 70 or c2 < 60)
{
f2 = f2 + 1;
flag = false;
}
if(c3 > 2.5 or c3 < 2)
{
f3 = f3 + 1;
flag = false;
}
if(flag == false)
{
n = n +1;
}
}
myfileout << "Total number of batches rejected " << n << endl;
myfileout << "Total number of batches rejected due to temperature = " << f1 << endl;
myfileout << "Percentage of number of batches rejected due to temperature = " << float(f1)/float(n)*100.0 << endl;
myfileout << "Total number of batches rejected due to pressure = " << f2 << endl;
myfileout << "Percentage of number of batches rejected due to pressure = " << float(f2)/float(n)*100.0 << endl;
myfileout << "Total number of batches rejected due to dwell time = " << f3 << endl;
myfileout << "Percentage of number of batches rejected due to dwell time = " << float(f3)/float(n)*100.0 << endl;
myfile.close();
}
else
{
cout << "Unable to open file" << endl;
exit(1);
}
return 0;
}
Sample Output.txt
Total number of batches rejected 5
Total number of batches rejected due to temperature = 1
Percentage of number of batches rejected due to temperature = 20
Total number of batches rejected due to pressure = 3
Percentage of number of batches rejected due to pressure = 60
Total number of batches rejected due to dwell time = 3
Percentage of number of batches rejected due to dwell time = 60
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.