Write a program that reads 10,000 words into an array of strings; the "List of 10,000 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. THIS IS AN ALL OR NOTHING QUIZ I ONLY HAVE TWO ATTEMPTS LEFT PLEASE HELP. THE ANSWER IS NOT 347!! I will insert the text files as a google drive link for you to view: list of 10,000 random words - https://drive.google.com/file/d/1WSrOEBnrwaUh3HYxvz9cto0SVKVqe4MI/view?usp=sharing search words - https://drive.google.com/file/d/1qtAlDV5ec_3g8S7NLYf3DlTXrQLE24ME/view?usp=sharing Here is the code : #include #include #include using namespace std; const int NUM_WORDS = 10000; // number of words in the first array int main() { // declare and initialize the first array with the 10,000 words string words[NUM_WORDS]; ifstream infile("1000RandomWords.txt"); for (int i = 0; i < NUM_WORDS; i++) { infile >> words[i]; } infile.close(); // open the second file and read the words one by one ifstream searchfile("Search Words.txt"); string searchword; int count = 0; // counter for the number of words found while (searchfile >> searchword) { // search the first array for the current search word for (int i = 0; i < NUM_WORDS; i++) { if (words[i] == searchword) { // 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 0; }
Write a program that reads 10,000 words into an array of strings; the "List of 10,000 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.
THIS IS AN ALL OR NOTHING QUIZ I ONLY HAVE TWO ATTEMPTS LEFT PLEASE HELP. THE ANSWER IS NOT 347!!
I will insert the text files as a google drive link for you to view:
list of 10,000 random words - https://drive.google.com/file/d/1WSrOEBnrwaUh3HYxvz9cto0SVKVqe4MI/view?usp=sharing
search words - https://drive.google.com/file/d/1qtAlDV5ec_3g8S7NLYf3DlTXrQLE24ME/view?usp=sharing
Here is the code :
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int NUM_WORDS = 10000; // number of words in the first array
int main() {
// declare and initialize the first array with the 10,000 words
string words[NUM_WORDS];
ifstream infile("1000RandomWords.txt");
for (int i = 0; i < NUM_WORDS; i++) {
infile >> words[i];
}
infile.close();
// open the second file and read the words one by one
ifstream searchfile("Search Words.txt");
string searchword;
int count = 0; // counter for the number of words found
while (searchfile >> searchword) {
// search the first array for the current search word
for (int i = 0; i < NUM_WORDS; i++) {
if (words[i] == searchword) {
// 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 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images