Ask Question
2 March, 07:17

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.

+4
Answers (1)
  1. 2 March, 07:46
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers