Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Will rate best possbile for solution to this problem! Also, it must be able to c

ID: 3763893 • Letter: W

Question

Will rate best possbile for solution to this problem! Also, it must be able to compile without any errors in visual studio as a console application.

Write a C++ program to solve the following problem.

Create a text file named first.txt and write your first name in the file. You will be reading the name of the file from the keyboard as a string, using the string class. Your program will also read your first name from the keyboard. The process of the file creation (name of the file, mode for opening the file, and testing the open success is done in a user-defined function. The function communicates the status of file open to the calling function).

Create a text file named last.txt and write your last name in the file. You will be reading the name of the file from the keyboard as a string, using the string class. Your program will also read your last name from the keyboard. The process of the file creation (name of the file, mode for opening the file and testing the open success is done in a user-defined function. The function communicates the status of file open to the calling function)

Create a text file named flast.txt and write your first name from the file first.txt, and your last name from the file last.txt. You will be reading the name of the file from the keyboard as a string, using the string class. The process of the file creation (name of the file, mode for opening the file and testing the open success is done in a user-defined function. The function communicates the status of file open to the calling function)

At this time, each file will have one line of text in it.

Prepare the files for reading.

Display the results of the three files in the order shown below:

first.txt                               your first name as written in the file

last.txt                                 your last name as written in the file

flast.txt                               yourfirstname yourlastname

Note that there is a single space between yourfirstname and yourlastname when you display the contents of the file flast.txt.

You will use a user-defined function to display all the files at once or one at a time.

Close all files. You will use a user-defined function that closes each file separately or all at once.

Run the program again and use your choice of the filenames, and different names, different than what you used above and repeat the process.

Explanation / Answer

I have the program which will merge two files and write into third file.

#include <stdio.h>
#include <stdlib.h>

int main()
{
   FILE *fs1, *fs2, *ft;

   char ch, file1[20], file2[20], file3[20];

   printf("Enter name of first file ");
   gets(file1);

   printf("Enter name of second file ");
   gets(file2);

   printf("Enter name of file which will store contents of two files ");
   gets(file3);

   fs1 = fopen(file1,"r");
   fs2 = fopen(file2,"r");

   if( fs1 == NULL || fs2 == NULL )
   {
      perror("Error ");
      printf("Press any key to exit... ");
      getch();
      exit(EXIT_FAILURE);
   }

   ft = fopen(file3,"w");

   if( ft == NULL )
   {
      perror("Error ");
      printf("Press any key to exit... ");
      exit(EXIT_FAILURE);
   }

   while( ( ch = fgetc(fs1) ) != EOF )
      fputc(ch,ft);

   while( ( ch = fgetc(fs2) ) != EOF )
      fputc(ch,ft);

   printf("Two files were merged into %s file successfully. ",file3);

   fclose(fs1);
   fclose(fs2);
   fclose(ft);

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote