Ask Question
29 July, 03:35

Define a C function with the name evaluateBook. The function receives as one argument the name of the file to be processed (i. e., the book's file). So that if you pass the English version, we will see the results only for that language.

+3
Answers (1)
  1. 29 July, 07:20
    0
    See explaination for the program function code.

    Explanation:

    Code.

    /*

    Program to read a text book and count

    charcters visible, letters and punctuations using functions

    */

    #include

    #include

    #include

    using namespace std;

    //Function prototypes

    void evaluateBook (string filename);

    int countCharacters (string line);

    int countLetters (string line);

    int countPunctuations (string line);

    int main ()

    {

    //Call function

    evaluateBook ("Text. txt");

    return 0;

    }

    //Function take a string and count visible charcter count

    int countCharacters (string line) {

    return line. length ();

    }

    //Function take a string and count letters count

    int countLetters (string line) {

    int cnt = 0;

    for (int i = 0; i < line. length (); i++) {

    if ((line[i] > = 'a' && line[i] = 'A' && line[i] < = 'Z')) {

    cnt++;

    }

    }

    return cnt;

    }

    //Function take a string and count punctuations count

    int countPunctuations (string line) {

    int cnt = 0;

    for (int i = 0; i < line. length (); i++) {

    if (line[i]=='/.' || line[i]=='/,' || line[i]=='/"' || line[i]=='/'') {

    cnt++;

    }

    }

    return cnt;

    }

    //Read file line by line and count details

    void evaluateBook (string filename) {

    //File path

    ifstream in (filename);

    //Varaibles

    int visibleCharacters = 0, numOfLetters=0, numOfPunctuations=0;

    //File found error check

    if (! in) {

    cout << "File not found!/n";

    exit (0);

    }

    string line;

    //Read line by line

    while (getline (in, line)) {

    //Count details

    visibleCharacters + = countCharacters (line);

    numOfLetters + = countLetters (line);

    numOfPunctuations + = countPunctuations (line);

    }

    //isplay result

    cout << "Visible charcters' count = "<
    cout << "Number of letters' count = " << numOfLetters << endl;

    cout << "Number of punctuations' count = " << numOfPunctuations<< endl;

    }

    This will produce an output of;

    Visible charcters' count = 252

    Number of letters' count = 203

    Number of punctuations' count = 10
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Define a C function with the name evaluateBook. The function receives as one argument the name of the file to be processed (i. e., the ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers