Question
in c++ #include #include #include #include using namespace std; void convertToLower(string& inputString); void countInstances(const string& searchWord, const string& sentence, int& uniqueInstanceCount, int& partInstanceCount); int main()
in c++
#include
void convertToLower(string& inputString); void countInstances(const string& searchWord, const string& sentence, int& uniqueInstanceCount, int& partInstanceCount);
int main() { ifstream input("text.txt"); string searchWord; cin >> searchWord; int uniqueInstanceCount = 0; // count of unique instances int partInstanceCount = 0; // count of part-of-word instances
while(!input.eof()){ string sentence; getline(input, sentence); // Your code starts here
// Your code ends here }
cout
void convertToLower(string& inputString) { // Your code starts here
// Your code ends here }
void countInstances(const string& searchWord, const string& sentence, int& uniqueInstanceCount, int& partInstanceCount) { // Your code starts here
// Your code ends here }
You are required to write a program which accepts a search word from the user console, and also reads lines of text from the file "text.txt". Bo the search word and the text must be converted to lower case letter before analyzing the text so as to make the search case insensitive. Your code must have two functions. The first function convertToLower handles the conversion to lowercase. The second function countInstances can be used to: o count how many times the search word has uniquely and exactly appeared in the text. count how many times the search word has appeared in the text as part of another word. The program must report the number of unique exact matches, and the partial matches on two separate lines. Your code must be able to skip any empty lines in the file Assume the text has no punctuation marks, only spaces and apostrophes (1) Sample Case o Suppose the content of the file "text.txt" is: The foragers were FORBIDDEN from going to the forest to look for food This was enforced by giving fines of 500$ per violation Input: for Autant Type here to search BI E Input: for Output 1 4 Explanation The search word for only appears once in the text. However, it appears four times as part of the words foragers, FORBIDDEN, forest, and enforced. 1 2 3 #includeStep 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