Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C++ The following is the function you might need: int ReadCorrectWords( string filename, string correctWords[], int size, int startIndex) { // Edge case if

image text in transcribed

Use C++

The following is the function you might need:

int ReadCorrectWords( string filename, string correctWords[], int size, int startIndex) { // Edge case if ( startIndex >= size) return -1; int count = 0; string word ; // Here are opening file for reading words ifstream fin; fin.open( filename );

// Edge case if ( fin.fail() ) { return -1; } // Read a word and put it in index start with startIndex while ( getline(fin,word) ) { // if array is full then break if ( ( startIndex + count ) == size ) break; correctWords[ startIndex + count ]= word; count++; } fin.close(); // return total words in array return ( startIndex + count ); }

int ReadMisspelledWords(string filename, string misspelledWords[][2], int rows, int startIndex){ int totalWordPairs = 0; //keeps the count of total number of word pairs ifstream f; //input filestream variable f.open(filename); //open the file "filename". if(!f) { //if file does not exist return (-1); } if(startIndex >= rows) { //if the misspelledWords array is already full. return (-1); }

string str1; // holds the misspelled word string str2; // holds the correct spelling while(getline(f, str1, '\t')) { //read from file if (startIndex == rows) break; misspelledWords[startIndex][0] = str1; //store the incorrect spelling in the first column (0th index) getline(f, str2, ' '); misspelledWords[startIndex][1] = str2; //store the correct spelling in the second column(1st index) startIndex++; //it also serves as the index into the array } f.close(); //close the file totalWordPairs = startIndex; //after reading from file, startIndex will contain the total word pairs return totalWordPairs; }

string CheckWord(string word,string correctWords[],int correctWordSize,string misspelledWords[][2],int misWordRow) { int idx=0; //convert word to lower case while (word[idx]!='\0') { char ch=word[idx]; ch =tolower(ch); word[idx] = ch; idx++; } for(int i=0;i Write a function CheckPhrase to check spelling in a phrase. It should have the following parameters A string phrase string outpurFile (the name of the file) An array of strings correctWords Size of the array correctWords A2D array of strings misspelledWords 2 A The number of rows in the misspelledWoros array You should do the following with phrase: . Separate the phrose into words. Call CheckWord on each word to check the spelling of the word and construct a corrected phrase. Note: the resulting phrase will contain "unknown" if any words are not found in the arrays Open the outputFile in append mode. Append the corrected phrase to the outputfile. NOTE: Your outputfile should end with an extra line (A new line character). This is to ensure that each time you add lines to it, it starts from a new line. Edge Conditions Your program should print"Phrase is empty. Nothing to write in file." to the console if your phrase is empty. Note: Your program should not write anything to the output file in this case. Your program should print "Unable to create/ access output file." if you're not able to access your output file Example: If CheckPhrase is called with the phrase "chicken fish and bubbls", the arrays (correctWords, misspelledWords) specified in the previous examples, and this output file: Before function call outputFle.txt ocean bubbles unknown pear bubbles fish unknown unknown fish the output file should look like this after the function call. After function call outputFle.txt ocean bubbles unknown pear bubbles fish unknown unknown fish chicken fish unknown bubbles NOTE: Please copy your ReadCorrectWords and ReadMisspelledWords and CheckWord functions from Q1 and Q2 and Q3 into the answer box here

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

More Books

Students also viewed these Databases questions

Question

How is burnout distinct from depression and sport dropout?

Answered: 1 week ago

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago