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

Write a console program to read in a text file of first and last names, print th

ID: 3764011 • Letter: W

Question

Write a console program to read in a text file of first and last names, print them on the screen, and write them (one first/last name per line) to another file. On the screen, the first name should be written to the file in a column 10 chars wide, and the 2nd should be written in a column next to it 10 chars wide. The user should be prompted for both filenames, and the program should verify that the files can be opened, printing an error message if not. Both files should be closed at the end of the program Output from your program should look like the following, on the screen and in the file your program creates (assuming the file "names.txt" contains Trey Anastasio Maynard Keenan Candy Cane Davey Jones) Enter the name of the input file: names.txt Enter the name of the output file: output Names: Trey Anastasio Maynard Keenan Candy Cane Davey Jones

Explanation / Answer

Answer :

#include<iostream.h>

#include<iomanip.h>
#include<stdlib.h>
#include<ctype.h>
#include<fstream.h>

void main( )
{
   ofstream outfile;
   ifstream infile;
   char filename1[100],filename2[200];
   char ch,uch;
  
   cout<<"Enter the name of the input file";
   cin>> filename1;
   cout<<"Enter the name of the output file";
   cin>>filename2;
   infile.open(filename1);

if( infile.fail( ) )
   {
       cerr<< " No such a file Exit";
  
       exit(1);
   }
   outfile.open( filename2);
       if(outfile.fail( ))
       {
           cerr<<"Unable to create a file";
  
           exit(1);
       }
   while( !infile.eof( ) )
   {
       ch = (char) infile.get( );
       uch = toupper(ch);
       outfile.put(uch);
       infile.get(ch);
       //filename1.get(ch);
       cout.put(ch);
   }
   infile.close( );
   outfile.close( );

}

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