Write a fragment of code that opens a file named numbers.txt, reads in pairs of
ID: 3660914 • Letter: W
Question
Write a fragment of code that opens a file named numbers.txt, reads in pairs of number until end of file and sends the smaller of the two to a file named min.txt and the larger of the two to a file named max.txt (one number per line). You can assume there are no ties. (basic file input/output) What is wrong? int x, y; ifstream numbers; numbers.open ("numbers.txt"); ofstream min; min.open ("min.txt"); ofstream max; max.open ("max.txt"); numbers>>x>>y; while(numbers){ if(x<<x<<endl; max<<y<<endl; } else{ max<<x<<endl; min<<y<<endl; } } numbers.close; min.close; max.close;Explanation / Answer
int x, y; ifstream numbers; numbers.open ("numbers.txt"); ofstream min; min.open ("min.txt"); ofstream max; max.open ("max.txt"); while(numbers>>x>>y ) { if(x>y) { maxRelated 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.