Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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++image text in transcribedimage text in transcribedimage text in transcribed

#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() { 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 #include #include #include #include using namespace std; 4 5 6 7 8 void convertToLower(string& inputString); void countInstances (const string& searchWord, const string& sentence, int& uniqueInstanceCount, int& partInstanceCount); 9 10 11 12 int main() { ifstream input("text.txt"); string searchWord; cin > > searchWord; int uniqueInstanceCount = 0; int partInstanceCount = 0; 13 14 // count of unique instances // count of part-of-word instances 15 16 17 while(!input.eof()) { Type here to search 1 DI 17 18 while (!input.eof()) { string sentence; getline (input, sentence); // Your code starts here 19 20 21 22 23 // Your code ends here 24 } 25 26 cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions