Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ please! Introduction to programming in C++ CPS 171 - Machine Problem 7 - Strings/enums This assignment is to give you practice using enums, string
C++ please!
Introduction to programming in C++ CPS 171 - Machine Problem 7 - Strings/enums This assignment is to give you practice using enums, string variables and the functions of the string class, as well as more practice writing your own functions. In order to get full credit for the program you must use these topics. The Internet search engine Google has a spelling correction system so that if a user misspells a word, it will try to correct it to what it thinks the user is asking for. E.g. if the correct spelling is "Britney Spears" and the user enters "Brittany Spears", Google will search for the correct pages (after asking if you really mean "Britney"). Your next assignment is to write a simplified version of this spelling correction system. Your program has to detect only four types of errors and only one of them can occur in a given word. 1. Character substitution - one character in the correct word has been replaced by some other character. E.g. in the word "compuder" the letter ' t ' has been replaced by the letter ' d '. 2. Character transposition - two adjacent characters in the word have been switched. E.g. in the word "copmuter" the 'm' and the 'p' have been transposed. 3. Character deletion - one of the characters has been inadvertently deleted. E.g. in the word "compter" the ' u ' has been deleted. 4. Character insertion - one extra character has been accidentally inserted into the word. E.g. the word "computxer" contains the extra character ' x '. Note that for this assignment, words like "komputers", "komputed", "comput" and "tompucer" are NOT considered minor misspellings of the word "computer" because they have more than one error. E.g. "komputers" has both a replacement and an insertion. Each line of the input file will begin with the correct spelling of the word. Following this will be several user attempts at the word, possibly containing misspellings (as above) or correct. All of the words will be separated by at least one blank. For simplicity, you may assume that all words contain just uppercase letters. Your program should check each of the user words with the correct word for any of the four errors specified above. It should then print a message indicating which of the errors occurred (if any), if the word was correct, or if the word was too far off to be considered a minor misspelling. You should perform this for each line of the input file. In addition, the program must keep a count of how many times each of the errors occurred. This continues until the end of the file is reached, at which time the final counts are printed. The data file is mp7spelling.txt. Create this file using the following data: COMPUTER COMPUDER COPMUTER COMPTER COMPUTXER KOMPUTERS COMPUTER BRITNEY BRITTANY BRITNE BRITNYE BTITINEY BRITNEYS KOURNIKOVA KOURNIKOVO OURNIKOVA OKURNIKOVA SKOURNIKOVA COURNIKOVA KOURNAKOVA NAME SALE SALES NALE NAIL NALES NAMES NAMSE NAM NMAE You are REQUIRED to use functions, enums, string variables and string functions in the solution to this problem. As a suggestion, define an enum for the type of spelling error (with the values CORRECT, SUBSTITUTION, TRANSPOSITION, DELETION, INSERTION, ERROR) and have the function that checks the user word with the correct word return one of these values. Then you could have another function that takes this value, prints the appropriate message and increments the appropriate count variable. Also print the totals at the end, see example. A sample output is shown on the next page. Note: this is not the contents of the file you are to use. Spelling Correction by (your name) *****Starting a new line***** The word being checked is COMPUTER User word is COMPUDER The user word has one character substituted User word is COPMUTER The user word contains a transposition User word is COMPTER The user word has one character deleted User word is COMPUTXER The user word has one character inserted User word is KOMPUTERS The user word is too bad to be a misspelling User word is COMPUTER The user word is correct *****Starting a new line***** The word being checked is LOOPY User word is LOPY The user word has one character deleted User word is LOOPPY The user word has one character inserted User word is LOPOY The user word contains a transposition User word is OLPOY The user word is too bad to be a misspelling There were 1 correct words There were 1 words with a substitution There were 2 words with a transposition There were 2 words with a deletion There were 2 words with an insertion There were 2 words that were way offStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started