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

A machine is manufacturing ball bearings and, at equal time intervals during a p

ID: 3623962 • Letter: A

Question

A machine is manufacturing ball bearings and, at equal time intervals during a production run, a ball bearing is sampled and its diameter is measured. Each ball bearing should have a diameter of 2.0 mm.

Your program will keep track of how many ball bearings were sampled that were NOT excessively large (> 2.05) or excessively small (<1.95). The program should not waste time reading further from the file once a bearing is found out of this range.

The program must report the following:
1. The size of the each ball bearing read from the data file.
2. A running total of how many ball bearing sizes have been read.
3. At the end of the program, both of the following must be reported:
a) Why the program stopped reading in data (e.g. last ball bearing size too big, last ball bearing size too small, or end of file found because all good bearings).
b) Final count for how many good ball bearing sizes were read in.

Explanation / Answer

#include #include #include using namespace std; int main () { string line = ""; //line from input file int counted = 0; //# of counted bearings double diameter = 0.0; //diameter of bearing read bool tooSmall = false; //bool to track if a bearing is too small bool tooLarge = false; // too large ifstream myFile("example.txt"); //input file stream (replace your text file name here) if(myFile.is_open()) //if the file is open { while(myFile.good()) //able to be read i.e. not EOF { getline(myFile, line); //takes in a line from the file, inserts it into line stringstream ss(line); //creates a string stream ss >> diameter; // sets the diameter to the value in the stringstream if(diameter < 1.95) //check if too small { tooSmall = true; break; } else if (diameter > 2.05) //check to see if too large { tooLarge = true; break; } else counted++; //counted a normal ball bearing } } cout
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