Question
Writing to and Reading from an External File You changed your mind about how to output the results of your transmogrifier monitoring system. Instead of
Writing to and Reading from an External File
You changed your mind about how to output the results of your transmogrifier monitoring system. Instead of printing out the output to the screen, which is rather useless, you have brilliantly decided to write the results out to a file on the hard drive. That way, the results can be made part of the permanent record and can be easily shared among interested parties. The latter was hard to do when it merely printed the results out to screen. However, your boss said that she wants to see the output on his screen, but she happens to be a techno-retard and doesnt know how to handle files. Imagine that! So, you will write a second program (not another function to the old program, but rather a completely separate program) that reads the results from the file and prints the output to screen. You can assume a known name for the file and hardcode it in the second program so the user doesnt have to enter the name of the file to be written to or read. You can call it output-data.txt.
So, take the program you wrote for HW #5 and modify it to do the following:
1) The printout function should now print out to output-data.txt . Take out all code that prints to screen, but save it because you are going to use it for step 2 below. Thats it for the HW#5 program nothing else.
2) Write a second program (i.e., NOT a function in the first program!) that reads the data from output-data.txt and prints it out to screen. You can do this in one of two ways a) print each row as it is read from the file; or preferably, b) populate an array in the printout function that holds the values read from the file and then print from this array to screen. The first is more efficient; the second is more elegant and organized.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started