// Program IODemo demonstrates how to use files #include #include using namespace std; int main() { cout << fixed << showpoint; float val1, val2, val3, val4; // declares 4 variables ifstream inData; // declares input stream ofstream outData; // declares output stream cout << "Program iodemo.cpp reads four floating point values " << endl; cout << "from the input file inputfile.txt and writes those values " << endl; cout << "to the output file outputfile.txt in the reversed order." << endl; inData.open("inputfile.txt"); // binds program variable inData to file "inputfile.dat" outData.open("outputfile.txt"); // binds program variable outData to file "outputfile.dat" //CS110 students will add code here to check the input file status. if (!outData) { cout << "** Problem: cannot open output file outputfile.dat, ending program." << endl; return 1; } else cout << "Program successfully opened output file outputfile.dat" << endl; inData >> val1 >> val2 >> val3 >> val4; // inputs 4 values outData << val4 << endl; outData << val3 << endl; outData << val2 << endl; outData << val1 << endl; // outputs 4 values return 0; }