Question
This is my code below. I have new requirements that when the code is ran using the sample.txt file it should output with the following
This is my code below. I have new requirements that when the code is ran using the sample.txt file it should output with the following ouptut supplied below.
But with my code I am having issue fixing one thing. When a word not in the file, my code simply just prompts the user for the next word
But now I need it to say whatever word I searched for example "test" as test was found 0 times. can someone help me the output highliget is the correct one where the other is mine
#include
#include
using namespace std;
void search(string arr[10000], int count, string lookupstr) { //initialze paramters for search string found[count]; int wordCount = 0; //initialize starting count of text file
for(int x = 0; x
if(str.length() == lookupstr.length()) { //check length of character found
int f = 0; while(f
bool matchMade = false;
for(int pos = 0; pos
matchMade = true; }}
if(!matchMade) { if(matchFound) {
int foundAmount = 0; //initialize variable for found character count
for(int z = 0; z
cout
found[wordCount++] = str; }}
return; }
int countAmount(string arr[10000], int amt) { //initialize the unique words in file string uniquearr[amt]; int cntr = 0; bool checkUnique = true;
for(int x = 0; x
checkUnique = true;
for(int f = 0; f
if(checkUnique) { uniquearr[cntr++] = arr[x]; //if unique found and matches, total with if statement }}
return cntr;}
string lowerCase(string str) { int x; for(x = 0; x
return str;}
int main(int argc, char** argv) { //initiliaztion of main statement ifstream infile; //initilization of opening given text file infile.open(argv[1]); //using arg[1] to set text file when prompted if(infile.fail()) return 0; //takes care of text file not found
string arr[10000]; string str; int count = 0; int distinctFound = 0;
while(infile >> str) { //searches through file till no characters left
bool caseCheck = false;
for(int pos = 0; pos
arr[count++] = lowerCase(str.substr(0, pos));
caseCheck = true;
if(str[pos+1] != '\0') { string split; for(int loc = pos+1; loc
if(!caseCheck) { arr[count] = lowerCase(str); count++; }}
distinctFound = countAmount(arr, count);
cout > lookupstr;
while(lookupstr.compare("END") != 0) { search(arr, count, lowerCase(lookupstr));
cout > lookupstr; }
infile.close(); //closing of file being read
return 0; }
The number of words found in the file was 64 The number of unique words found in the file was 52 Please enter a word: of The word of appears 2 times in the document Please enter a word: compiler The word compiler appears O times in the document Please enter a word: is The word is appears 2 times in the document Please enter a word: or The word or appears 2 times in the document Please enter a word: a?? The word and appears 4 times in the document Please enter a word: i? The word is appears 2 times in the document The word in appears 1 time in the document Please enter a word: ENDStep 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