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

Please write comments in the function explainng what they do! thanks again! Impl

ID: 3669786 • Letter: P

Question

Please write comments in the function explainng what they do! thanks again!

Implement a C++ program that has the following functions: Reads in a paragraph of English text up to 100 words from the keyboard and stores this paragraph in a string object. Feel free to include this task in the main() function. Identifies the least frequent letter (case insensitive) in the above paragraph.

Implement a separate function getLeastFreqLetter() for this task. The main() function then calls this function to find out the least frequent letter and its frequency. Calculate the frequency of each unique word (case insensitive).

Implement another function countWordFreq() for this task. Use white spaces and punctuation marks such as comma, period, semicolon and question mark as word delimiters. Please define a global struct that contains two fields, word and its count for this task. You can then define an array of this struct to store all the unique words and its counts. The main() function will call this function to print out each word and its corresponding frequency. Identify the most frequently occurring word in the paragraph.

Implement another stand-alone function getMostFreqWord() for this purpose. This function will be called in main() to identify the most frequent word and its respective frequency.

Explanation / Answer

Hi, You can take help from my program. I have implemented for counting frequency of words. So you can easily implement use my program you can easily add functionality, like taking 100 words from keyboard, counting characters frequecny, as these are easy if you go through my code.

#include <stdio.h>

#include <string.h>

struct word {

char str[20]; /* word string: assume max 19 characters */

int count; /* word count */

} ;

int word_freq(const char *str, struct word words[]);

int main ()

{
   int charCount[26]={0}; // 26 english aplhabet

char str[] = "Alexander said, "I came, I saw, I conquered!"";

struct word words[100]; /* assume max. 100 distinct words */

int i;
  
printf("Given string: %s ", str);

nword = word_freq(str, words);

puts(" Word frequency:");

for(i = 0; i < nword; i++)

printf(" %s: %d ", words[i].str, words[i] .count);

return 0;

}

/* calculate frequency of words in a given string */

int word_freq(const char *str, struct word words[])
{

char punct_str [] =" .,;:!?'""; /* punctuator list*/

char *tmp_str; /* pointer to a copy of given string */

char *wptr; /* pointer to a word */

int nword; /* number of distinct words */

int i;

nword = 0;

tmp_str = strdup(str); /* copy of given string */

wptr = strtok(tmp_str, punct_str); /* get ptr to first word */

while (wptr != NULL)

{

/* search current word in 'words' array */

for(i = 0; i < nword; i++)

{

if (strcmp(wptr, words[i].str) == 0)

break; /* current word found, stop search */

}

/* if current word is not in words array, add it at loc nword */

if (i < nword) /* current word already in 'words' array */

words[i] .count++; /* increment its count */

else { /* current word not in 'words' array */

strcpy(words[nword].str, wptr); /*add word at pos. nword */

words[nword].count= 1; /* set freq count to 1 */

++nword; /*increment words count*/

}

wptr = strtok(NULL, punct_str); /* get ptr to next word */

}

delete tmp_str; /* release memory allocated to tmp_str */

return nword;

}