Creat a void fuction void myUpdate(string dictionary[], int wordCount, string oldWord, string newWord); Where it will replace the oldWord with the newWord, if the search is successful
Creat a void fuction
void myUpdate(string dictionary[], int wordCount, string oldWord, string newWord);
Where it will replace the oldWord with the newWord, if the search is successful
I have provided the working code, and output. Since no language was mentioned in question, I have done it in C++.
*****************************************
#include <iostream>
using namespace std;
void myUpdate(string dictionary[], int wordCount, string oldWord, string newWord);
int main()
{
int wordCount = 5;
string dictionary[] = {"abc", "bcd", "cde", "def", "efg"};
myUpdate(dictionary,5,"bcd","kgf");
for(int i=0;i<wordCount;i++){
cout<<dictionary[i]<<" ";
}
return 0;
}
void myUpdate(string dictionary[], int wordCount, string oldWord, string newWord)
{
for(int i=0;i<wordCount;i++){
if(dictionary[i] == oldWord){
dictionary[i] = newWord;
}
}
}
Step by step
Solved in 2 steps with 1 images