Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

12. 20 points) You are playing a game. Given an plete word like p_ck, the goal i

ID: 3902839 • Letter: 1

Question

12. 20 points) You are playing a game. Given an plete word like p_ck, the goal is to provide all [xesitle won ?s lik: Pack, peck pick, or puck that matches the spei itled lettns. You must only privide words fron a dictioary. (This is similar to the gane Hangman.) Write the function match wordshdes this for yau. Assume that the vector dictianary ontains natch vords is this vactor dictionary. The scod input of match ords is the inplete word tac match, an t upecified characters are denoted with the char '_'. The third input of atch vorda is a vector that will contain the matched words after match woras has been call Assume all letters are in lonvercase. So nowod in dictionary contains a capital letter #includ sing std: : string ; using std: vector; using std: cout; using std: enal; void natch worde (const vector ctring dictionary const string partial wd vectork matched-wds? { matched uda.laar; FILL IN HERE nt main) vector tring> dictianary; //laad all vords (but not their dafinitions) from a dictionary //onl t * the ector dictionary vectoratring natches match_worda (dietionary. etring("b i_.t", natches); cout

Explanation / Answer

If you have any doutbs, please give me comment...

void match_words(const vector<string>& dictionary, const string& partial_wd, vector<string>& matched_wds){

//clearing matche_words, bcz first we need empty vector to fill

matched_words.clear();

//iterating along sizeo of dictionary

for(size_t i=0; i<dictionary.size(); i++){

//geeting current word to temp variable

string curr_wd = dictionary[i];

//checking first temp word and searching words have equal length or not, if not equal skip the word for comparing original word

if(curr_wd_size()!=partial_wd.size())

continue;

//initiallly assigning match is true

bool match = true;

//iterating searching word character by character

for(size_t j=0; j<partial_wd.size(); j++){

// if seaching character is _ then skip that character

if(partial_wd[j]=='_')

continue;

//if not checking they are equal are not, if not equal assigning match to false, bcz at least one character doesn't match, entire word is doesn't match

if(partial_wd[j]!=curr_wd[j])

match = false;

}

//if match is true, then appending temp word into vector

if(match)

//push_back is method, which is appending value into vector

matched_wds.push_back(curr_wd);

}

}