Write a C++ program to read the employee.txt file created in (a) and produce a d
ID: 3642128 • Letter: W
Question
Write a C++ program to read the employee.txt file created in (a) and produce a duplicate copyof the file. Your program should accept the name of the original file and the name of the duplicate file
to be created as input from the user, and perform all the necessary checks to ensure that it program will
exit smoothly in case a problem is encountered.
Declare variables
Declare input and output stream objects
Print "Please enter the name of the file you wish to copy: "
Read filename
Open input stream
If input stream fails to open then
Print "The file was not successfully opened.
Please check that the file currently exists."
exit program
endIf
Print "Please enter the name of the duplicate file you wish to create: "
Read filename
Open input stream
If input stream does not fail to open then
Print "A file by the given name exists.
"Do you want to continue and overwrite it with the new data (y or n): "
Read response
If response is n
Print "The existing file will not be overwritten."
exit program
endIf
endIf
Open output stream
If output stream fails to open then
Print "The output file was not successfully opened"
exit program
endIf
Read a line from the input stream
while the end of file (EOF) has not yet been reached
Write the line to the output stream
Read a line from the input stream
endWhile
close input stream
close output stream
Explanation / Answer
#include #include #include using namespace std; int main() { FILE * input; FILE * output; FILE * input2; char response; char c; int n = 0; string in; string out; coutin; input = fopen (in.c_str(),"r"); if (input==NULL) { perror ("The file was not successfully opened. Please check that the file currently exists."); return 1; } else { //coutRelated 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.