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

write a program(visual C++) that reads two file names from user - one for input

ID: 3620301 • Letter: W

Question

write a program(visual C++) that reads two file names from user - one for input and one for output; opens the input file, reads its contents and counts the number of symbols, upper case letters, lower case letters, punctuation, spaces, and lines in the file; opens the output file and writes the statistics -input file name, number of symbols,number of upper and lower case letters, number of punctuation characters, number of spaces and number of lines - to the output file.
The program should test that the lengths of the file names are greater than 0 and that the files actually exist. If a file name's length is 0 or a file oes not exist then the program should display a message and stop.

Thanks for your help

Explanation / Answer

please rate - thanks #include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{char filename1[30],filename[30];
ifstream in;
ofstream out;
char c;
int size, symbols=0,up=0,low=0,punct=0,space=0,line=0;
cout<<"what is the name of the input file you are using? ";
cin>>filename;
if(strlen(filename)<1)
   { cout<<"file name has zero length program aborting ";
   system("pause");
   return 1;
    }
in.open(filename);           //open file
if(in.fail())             //is it ok?
{ cout<<"file did not open please check for it's existance program aborting ";
   system("pause");
   return 1;
    }
c=in.get();
while(in)
{      
if(c==' ')
     line++;
else if(c==' ')
     space++;
else if(islower(c))
      low++;
else if(isupper(c))
      up++;
else if(ispunct(c))
      punct++;
else if(!isdigit(c))
      symbols++;

c=in.get();
}
cout<<"what is the name of the output file you are using? ";
cin>>filename1;
if(strlen(filename1)<1)
   {cout<<"file name has zero length program aborting ";
   system("pause");
   return 1;
    }
out.open(filename1);           //open file
if(out.fail())             //is it ok?
{ cout<<"file did not open please check for it's existance program aborting ";
   system("pause");
   return 1;
    }
out<<"file statistics ";  
out<<"file name: "<<filename <<endl;
out<<"symbols: "<<symbols <<" ";
out<<"upper case letters: "<< up<<" ";
out<<"lower case letters: "<<low <<" ";
out<<"punctuation: "<<punct <<" ";
out<<"spaces: "<< space<<" ";
out<<"lines: "<<line <<" ";
in.close();
out.close();
system("pause");                    
return(0);
}