Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include using namespace std; //structure definition struct WordCount { //two data members char word[31]; int count; }; //Function to convert string upper case

#include #include #include using namespace std;

//structure definition

struct WordCount

{ //two data members char word[31]; int count; };

//Function to convert string upper case void stringToUpper(char*s) { for(int i=0;s[i]!='\0';i++) //repeat until end of string char null { if(*(s+i)>=97 && *(s+i)<=122) // when lower case letter *(s+i)=*(s+i)-32; //convert to upper case by subtraction of ascii with 32 } }

//Function striping punctuation characters void stripPunctuation(char*s) { int pos=0; for (char *p=s; *p; ++p) //repeat all characters if (isalpha(*p)) //when alphabet s[pos++] = *p; //then concate to s s[pos] = '\0'; //end with null } //function search word int searchForWord(const char* word, const WordCount wordArray[],int numWords) { for(int i=0;i

//Function for counting word int countWords(const char* fileName,WordCount wordArray[]) { ifstream infile (fileName); //open file for reading int count=0; //initially count is 0 char word [31]; //take max length word infile>>word; //read the word while(!infile.eof()) //repeat until end of file { stringToUpper(word); //convert to upper case stripPunctuation(word); //remove punctuation character int found=searchForWord(word,wordArray,count); //search word if(found==-1) //when not found { strcpy(wordArray[count].word,word); //store as new word wordArray[count].count=1; //first count is 1 count++; //increment count } else //when found wordArray[found].count+=1; //increment existing count infile>>word; //read the next words } infile.close(); //close the file return count; //finally return count }

//Function to sort words void sortWords(WordCount wordArray[],int numWords) { for(int i=0; i

//Function prints all words and their frequency void printWords(const WordCount wordArray [],int numWords) { cout <<"Word\tFrequency"<

SHOW THE CORRECT OUTPUT AND SOLVE FOR THE ERROR IN LINE 15: padding struct 'WordCount' with 1 byte to align "count'

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions