Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program that reads 1 0 , 0 0 0 words into an array of strings; the List of 1 0 , 0 0
Write a program that reads words into an array of strings; the "List of Random Words" file is on Moodle. The program will then read a second file the list of "Search Words" is also on Moodle that contains an undetermined number of words and search the first array for each word. The program will then report the number of words in the second list that were found on the first list. Do not use an array for the second file, process the words as they are read. Note that some of these "words" might have spaces; handle your input accordingly.
I keep getting words, but that is not right. What part of my code is incorrect? The Int main is underlined in green sayingthe bytes of stake exceeds the limit How do I make it bigger?
Here is my code:
#include
#include
#include
using namespace std;
const int NUMWORDS ; number of words in the first array
int main
declare and initialize the first array with the words
string wordsNUMWORDS;
ifstream infileRandomWords.txt;
if infile.isopen
cout "Error: could not open RandomWords.txt endl;
return ;
for int i ; i NUMWORDS; i
infile wordsi;
infile.close;
open the second file and read the words one by one
ifstream searchfileSearch Word.txt;
if searchfile.isopen
cout "Error: could not open SearchWords.txt endl;
return ;
string searchword;
int count ; counter for the number of words found
while searchfile searchword
remove leading and trailing white space characters from searchword
searchword.erase searchword.findfirstnotoft;
searchword.erasesearchwordfindlastnotoft;
search the first array for the current search word
for int i ; i NUMWORDS; i
if searchword wordsi
if the search word is found, increment the counter
count;
break; exit the loop
searchfile.close;
print the number of words found
cout "Number of words found: count endl;
return ;
Step 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