Ask 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 book's file). So that if you pass the English version, we will see the results only for that language.

+2
Answers (1)
  1. 7 June, 18:25
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers