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

Using this link http://www.gutenberg.org/cache/epub/18209/pg18209.txt Click on p

ID: 3686267 • Letter: U

Question

Using this link http://www.gutenberg.org/cache/epub/18209/pg18209.txt

Click on plain txt UTF-8

write a C++ program that finds out:

1. The number of lines in the text

2. The total number of characters (including, number, letters, symbols, etc.) in the text.

3. The total number of letters in the text

4. The total number of capital letters in the text

5. The number of characters of the longest line in the file of the text

6. The largest word in the file of the text.

Use the “getline()” function. (C++ programming)

Explanation / Answer

working c++ code for the same:

#include <iostream>
#include <fstream>
using namespace std;

int main() {
ifstream f1;
char c;
int numchars, numlines,capital,letters;

f1.open("input.txt");

numchars = 0;
numlines = 0;
capital = 0;
letters = 0;
f1.get(c);
while (f1) {
while (f1 && c != ' ') {
       if((c>='A' && c<='Z') || (c>='a' && c<='z'))
           letters++;
   if(c>='A' && c<='Z')
       capital++;
numchars = numchars + 1;
f1.get(c);
}
numlines = numlines + 1;
f1.get(c);
}
cout << "number of lines is " << numlines <<endl;
cout << "number of characters is "<< numchars<< endl;
cout << "number of letters is "<< letters<< endl;
cout << "number of capital letters is "<< capital<< endl;
return(0);
}