Question: need help on computer science. to write c++ program(visual studio) please!!! Procedure Your task is to create a simple program that prompts the user for
need help on computer science. to write c++ program(visual studio) please!!!
Procedure
Your task is to create a simple program that prompts the user for two le names, opens both les, reads the data from one le and copies that data to the other le. After this is done, the les are both closed and the program ends.
1. You are going to create a pseudocode document for this lab. It WILL help you write the program. Make sure that do this FIRST. It should NOT contain any C++ code. Name it Lab06Pcode.txt.
2. Your program, Lab06.cpp, needs to use both an ifstream object and an ofstream object. You can refer to the Lecture 10 slides and the FileRead.cpp program for a starting place.
3. You only need to use #include
4. You will use string objects to get the lenames from the user. That should make it a lot easier .
5. If one or both of the les cannot be opened, you need to provide the user with an error message about that fact, including the oending name(s). It then needs to prompt the user for two more names and continue until the program can open both the input and output les.
6. If the program can only open one le, it needs to close() the other le before trying to open any new ones. You may also need to clear() the stream that failed to open, as in
myInputFile.clear()
7. The program should use the getline() function to read data from the input le a line at a time (see FileRead.cpp) and you can write it to the output le with the stream insertion (
The getline() function reads until it encounters a newline character. It takes the newline out of the stream and discards it. That means that you have to put the newlines back in to duplicate the original. This turns out to be easy. Lets say that the string that you are reading data into is called big buer and that your ofstream object is named output le. Then you can do something as simple as this
output_file
9. During the lecture last week I talked about dierent ways to test for end of le, and that the method in the FileRead.cpp program could result in some errors because end-of-le is not really true until the program attempts to read beyond the end. To x this, you should probably read once before the while-loop and then again as the last statement in the while-loop.
10. Make sure that the program closes all open les before main executes the return statement.

Example interaction An example of how this might look. of course, you now have to open the new file and make sure that it is the same as the old file to ensure your program worked correctly. buckner lab06/solution Lab06 Please give me two filenames I'll copy the first to the second My infile The0uput ****Done copying buckner T. lab06/solution Do not forget that if I give non-existent files (bad names) the program should print an error message. Something like Please give me two filenames I'll copy the first to the second The infile TheOuput Cannot open input: Theinfile Please give me two filenames I'll copy the first to the second
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
