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

1. Write a program which reads a text file and counts the numberof words and lin

ID: 3614021 • Letter: 1

Question

1. Write a program which reads a text file and counts the numberof words and lines in the file.

2. Your program should be able to get the file name from eitherthe command line (if run from DOS), or prompt the user for the filename if it is not supplied on the command line.

3. Use proper procedures for opening a file and checking forerrors.

4. Read the file a character at a time. Use whitespacecharacters to identify the end of a word, and the new-linecharacter to identify lines.

5. Print a summary of the number of words and lines in thefile.

6. Document your program with comments.

7. Provide a written description in English of how the programworks.

Explanation / Answer

please rate - thanks #include #include using namespace std; int main(int argc, char * argv[]) {int words=0,lines=0; char c; char filename[20]; ifstream in; if (argc==1)         {coutfilename;        in.open(filename);         //open file         } else        in.open(argv[1]);   if(in.fail())            //is it ok?        { cout