Implement the scoreTypo function in the following program: #include #include #include using namespace std; int scoreTypo(const string dictionary[], int n, string word) { Replace this line with your...

1 answer below »
Specs in the word file.


Implement the scoreTypo function in the following program: #include #include #include using namespace std; int scoreTypo(const string dictionary[], int n, string word) { Replace this line with your implementation } int main() { // Here are some tests. You may add more if you wish. string dict1[6] = { "february", "pointer", "country", "forty", "conversation", "minuscule" }; assert(scoreTypo(dict1, 0, "forty") == -1); assert(scoreTypo(dict1, 6, "forty") == 0); assert(scoreTypo(dict1, 6, "fourty") == 1); assert(scoreTypo(dict1, 6, "febuary") == 1); assert(scoreTypo(dict1, 6, "miniscule") == 1); assert(scoreTypo(dict1, 6, "poitner") == 1); assert(scoreTypo(dict1, 6, "conservation") == 2); cout < "all="" tests="" succeeded"="">< endl; } the scoretypo function considers only the first n elements of the array passed to dictionary. you may assume that word and that every string in dictionary consists of at least one lower case letter and contains no character that is not a lower case letter. (so we promise that we will not pass strings like "", "ebay", "half-wit", "be at", or "hen3ry" to this function.) if n is not positive, scoretypo returns −1; otherwise, it returns the smallest typo score among all the typo scores between word and each string in dictionary. let's define a simple typo of a string as one of the following: · adding exactly one character to the string (e.g., adding one character to forty to produce fourty) · removing exactly one character from the string (e.g., removing a character from february to produce febuary) · replacing exactly one character in the string (e.g., replacing a character in minuscule to produce miniscule) · swapping two adjacent characters in the string (e.g., swapping two adjacent characters of pointer to produce poitner) the typo score between two strings is defined to be · 0 if the strings are identical · 1 if exactly one simple typo would transform one string to the other · 2 if neither of the above two conditions hold for example, the typo score between country and fourty is 2, while the typo score between forty and fourty is 1. in the example program above, 1 is the smallest typo score among all the typo scores between fourty and each word in dict1. the source file named typo.cpp that you turn in will contain the entire program above. you can actually have the main routine do whatever you want, because we will rename it to something harmless, never call it, and append our own main routine to your file. our main routine will thoroughly test your function. you'll probably want your main routine to do the same. if you wish, you may add helper functions that your implementation of scoretypo calls. the program you turn in must build successfully, and during execution, no function (other than main) may read anything from cin or write anything to cout. if you want to print things out for debugging purposes, write to cerr instead of cout. when we test your program, we will cause everything written to cerr to be discarded instead — we will never see that output, so you may leave those debugging output statements in your program if you wish. although our test routine will call your function passing values for n that are less than or equal to the number of elements in the array passed as dictionary, we will never pass a value for n than is greater than the number of elements in the array passed as dictionary. endl;="" }="" the scoretypo function="" considers="" only="" the="" first n elements="" of="" the="" array="" passed="" to dictionary.="" you="" may="" assume="" that word and="" that="" every="" string="" in dictionary consists="" of="" at="" least="" one="" lower="" case="" letter="" and="" contains="" no="" character="" that="" is="" not="" a="" lower="" case="" letter.="" (so="" we="" promise="" that="" we="" will="" not="" pass="" strings="" like "", "ebay", "half-wit", "be="" at",="" or "hen3ry" to="" this="" function.)="" if n is="" not="" positive, scoretypo returns="" −1;="" otherwise,="" it="" returns="" the="" smallest typo="" score among="" all="" the="" typo="" scores="" between word and="" each="" string="" in dictionary.="" let's="" define="" a simple="" typo of="" a="" string="" as="" one="" of="" the="" following:="" ·="" adding="" exactly="" one="" character="" to="" the="" string="" (e.g.,="" adding="" one="" character="" to forty to="" produce fourty)="" ·="" removing="" exactly="" one="" character="" from="" the="" string="" (e.g.,="" removing="" a="" character="" from february to="" produce febuary)="" ·="" replacing="" exactly="" one="" character="" in="" the="" string="" (e.g.,="" replacing="" a="" character="" in minuscule to="" produce miniscule)="" ·="" swapping="" two="" adjacent="" characters="" in="" the="" string="" (e.g.,="" swapping="" two="" adjacent="" characters="" of pointer to="" produce poitner)="" the typo="" score between="" two="" strings="" is="" defined="" to="" be="" ·="" 0="" if="" the="" strings="" are="" identical="" ·="" 1="" if="" exactly="" one="" simple="" typo="" would="" transform="" one="" string="" to="" the="" other="" ·="" 2="" if="" neither="" of="" the="" above="" two="" conditions="" hold="" for="" example,="" the="" typo="" score="" between country and fourty is="" 2,="" while="" the="" typo="" score="" between forty and fourty is="" 1.="" in="" the="" example="" program="" above,="" 1="" is="" the="" smallest="" typo="" score="" among="" all="" the="" typo="" scores="" between fourty and="" each="" word="" in dict1.="" the="" source="" file="" named typo.cpp that="" you="" turn="" in="" will="" contain="" the="" entire="" program="" above.="" you="" can="" actually="" have="" the="" main="" routine="" do="" whatever="" you="" want,="" because="" we="" will="" rename="" it="" to="" something="" harmless,="" never="" call="" it,="" and="" append="" our="" own="" main="" routine="" to="" your="" file.="" our="" main="" routine="" will="" thoroughly="" test="" your="" function.="" you'll="" probably="" want="" your="" main="" routine="" to="" do="" the="" same.="" if="" you="" wish,="" you="" may="" add="" helper="" functions="" that="" your="" implementation="" of scoretypo calls.="" the="" program="" you="" turn="" in="" must="" build="" successfully,="" and="" during="" execution,="" no="" function="" (other="" than="" main)="" may="" read="" anything="" from cin or="" write="" anything="" to cout.="" if="" you="" want="" to="" print="" things="" out="" for="" debugging="" purposes,="" write="" to cerr instead="" of cout.="" when="" we="" test="" your="" program,="" we="" will="" cause="" everything="" written="" to cerr to="" be="" discarded="" instead="" —="" we="" will="" never="" see="" that="" output,="" so="" you="" may="" leave="" those="" debugging="" output="" statements="" in="" your="" program="" if="" you="" wish.="" although="" our="" test="" routine="" will="" call="" your="" function="" passing="" values="" for n that="" are="" less="" than="" or="" equal="" to="" the="" number="" of="" elements="" in="" the="" array="" passed="" as dictionary,="" we="" will="" never="" pass="" a="" value="" for n than="" is greater than="" the="" number="" of="" elements="" in="" the="" array="" passed="">
Answered Same DayDec 17, 2021

Answer To: Implement the scoreTypo function in the following program: #include #include #include using...

Swapnil answered on Dec 19 2021
152 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here