// IO In-Class Review Solution #include // For filestreams #include // For setw(), setprecision () // This is a required line since we are using the new style of headers. using namespace std; int main() { ifstream inFile; // Input filestream ofstream outFile; // Output filestream int Airspeed = 0; // Airplane's airspeed read in from the input file int Altitude = 0; // Airplane's altitude read in from the input file int Heading = 0; // Airplane's heading read in from the input file float Fuel = 0.0; // Airplane's fuel read in from the input file // This allows us to format the output outFile.setf(ios::fixed, ios::floatfield); outFile.setf(ios::showpoint); // Open the input and output filestream inFile.open("infile.dat"); outFile.open("outfile.dat"); // The first line of the input file gives the airplabne's N-number, and can be ignored inFile.ignore(200, '\n'); // Read in the airspeed and ignore the rest of the line inFile >> Airspeed; inFile.ignore(200, '\n'); // Read in the altitude and ignore the rest of the line inFile >> Altitude; inFile.ignore(200, '\n'); // Read in the heading inFile >> Heading; // Read in the fuel. Since this is the last thing we need to read, there is no need // to ignore the rest of the line inFile >> Fuel; // Begin printing the output file // Print the airspeed outFile.setf(ios::left); // Left justify outFile << setw(10) << "Airspeed:"; // Print out heading outFile.unsetf(ios::left); // Right justify outFile << setw(7) << Airspeed << endl; // Print out value and a newline // Print the altitude outFile.setf(ios::left); // Left justify outFile << setw(10) << "Altitude:"; // Print out heading outFile.unsetf(ios::left); // Right justify outFile << setw(7) << Altitude << endl; // Print out value and a newline // Print the heading outFile.setf(ios::left); // Left justify outFile << setw(10) << "Heading:"; // Print out heading outFile.unsetf(ios::left); // Right justify outFile << setw(7) << Heading << endl; // Print out value and a newline // Print the fuel outFile.setf(ios::left); // Left justify outFile << setw(10) << "Fuel:"; // Print out heading outFile.unsetf(ios::left); // Right justify outFile << setw(7) << setprecision(1) << Fuel << endl; // Print out value // with one decimal place // Close the filestream inFile.close(); outFile.close(); // Program terminated normally return (0); }