Question: Create Lab2B.cpp While Loops Lab2B.cpp (also shown below) has the beginnings of a program designed to take input from the keyboard or text files in
Create Lab2B.cpp While Loops Lab2B.cpp (also shown below) has the beginnings of a program designed to take input from the keyboard or text files in degrees Celsius, and then convert them to degrees Fahrenheit, and write out the results to a table. Start with the program Lab2B.cpp. Then, build the program by adding the loop in the indicated space, and also add any code where it says [Add code here]. // Lab2B.cpp // // // // This program will read in from a file a series of numbers in degrees // Celsius, convert them to degree Fahrenheit and print out a table of // those values. #include #include //for file open #include // for format number numbers using namespace std; int main ( ) { // Declare variables ifstream OpenFile("Lab2data.txt"); double degreeCelsius; double degreeFahrenheit; double aNumber; string aType; // Print to the screen the header of the output table // as seen in the sample run below. // There are two lines in the header.
Page 4 of 5
// Make sure it has the right spacing to line up with the table. //1. [Add code here] //Exception Handling for File not found //Write try ... throw .. catch statement to check input file try { //2. [Add code here]
} catch ( int e ) { cout << "File Not Found " << e << endl; return 0; } // Write your loop here // We want to loop until there are no more inputs to be read. while( /* 3. [Add code here]*/ ) //Until file OpenFile.eof { // Read one degreeCelsius from the data file // named Lab2Bdata.txt. // Convert input degrees Celsius to degrees Fahrenheit // and store in degreeFahrenheit. // f = c * (9.0/5.0) + 32.0 // [Add code here] // Display to the screen the output as shown in the // sample run below. Use cout Make sure // that everything lines up properly. cout ( /* [Add code here */ ); } // End of while cin >> aNumber; return 0;
} //End of main
2.4 A Sample run with the given input can be seen below. Celsius | Fahrenheit -----------+------------ 5.50| 41.90 15.20| 59.36 35.80| 96.44 45.10| 113.18 55.90| 132.62 65.30| 149.54 85.60| 186.08 95.00| 203.00
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
