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 »
Dummy Assignment


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 19 days AfterFeb 10, 2021

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

Bhagyesh answered on Mar 01 2021
132 Votes
#include
#include
#include
using namespace std;
int minDistance(st
ring word1, string word2) {

if( word1 == word2 ) return 0;

int M = word1.size(), N = word2.size(), i, j;
int dp[M+1][N+1], cost;

for (i = 0;i <= M;i++) {
dp[i][0] = i;
}
for(j = 0; j<= N; j++) {
dp[0][j] = j;
}
for( i = 1; i <= M; i++)
for( j = 1; j <= N; j++ )
{
if( word1[ i - 1 ] == word2[ j - 1 ] )
cost = 0;
else
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here