I need to write inaccurate c++ fuzzy search. Given an arbitrary string and a text file, program should output how many occurrence if the string is contained in the file. If the string is not contained...

I need to write inaccurate c++ fuzzy search. Given an arbitrary string and a text file, program should output how many occurrence if the string is contained in the file. If the string is not contained in the file, program should output the most similar string contained in the file. helloworld.txt : This is an example text file. Hello World! Hello C++! Hello Everybody! Result: my code so far (need to implement 'similar' function which returns similar strings from the file): fuzzysearch.cpp #include #include #include using namespace std; string similar(string c, string filename){ string m; ifstream fin(filename); // open file // while loop to search the string in a file while(!fin.eof()){ for(int i = 0; i cout cout } } fin.close(); //close file return m; } int main(int argc, char **argv){ int count = 0; // contains string/character occurences count string c; // contains input string string line; // contains each line, read from the file string filename; // Check for application usage if(argc != 2){ cout cout return -1; // exit } filename = argv[1]; // Infinite loop to search any word for any number of times do{ ifstream fin(filename); // open file // validating the file if (!fin.is_open()){ cout return -1; // exit } cout getline(cin, c); // takes input string if (c.empty()) // exit if empty search string return -1; // exit // while loop to search the string in a file while(!fin.eof()){ getline(fin, line); // read each line of the file size_t found = line.find(c); // finding occurrences of search string // if found then increease count while ((line.find(c,found)) != string::npos){ count++; // continue to look for occurrences on the same line found = line.find(c,found+c.length()); } } // print number of occurrences of search string cout fin.close(); //close file if(count == 0){ cout } count = 0; // initializing count to zero in each search iteration }while(1); return 0; }
May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here