A text file named foo.in contains three real numbers, one on each line, e.g., fo
ID: 3652649 • Letter: A
Question
A text file named foo.in contains three real numbers, one on eachline, e.g.,
foo.in
11.1
22.2
33.3
Write a complete C++ program which shall: (1) open foo.in for reading; (2) read the three numbers from the file into defined
double variables named a, b, and c; (3) open a text file named foo.out for writing; (4) write the numbers to foo.out, one per
line, in the reverse order; and (5) close both files. If foo.in contains the values shown above, then the contents of foo.out
would be,
foo.out
33.3
22.2
11.1
Explanation / Answer
#include #include using namespace std; int main() { ifstream inFile; ofstream outFile; inFile.open("foo.in", ios::in); double val1,val2,val3; for(int i=0;i>val1>>val2>>val3; inFile.close(); outFile.open("foo.out",ios::out); outFileRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.