Welcome to the third challenge of the section 19 part of the course.
I'm in the section 19 workspace in the challenge_3 project.
And this is the project that I'm supplying to you.
The challenge_3_solution project will have my solution,
which I go over the next video.
This challenge is all about finding words in files.
So the idea here is for you to ask the user to enter a word.
And then you're going to search the text of the Romeo and Juliet play by Shakespeare
to see how many times is that word is found in the text.
Okay. I'm supplying the Romeo and Juliet text.
You can see it right here. You can get this from
Shakespeare.mit.edu.
And there's the entire play that it's a very long play.
But you can see that there's all kinds of words in here.
And what we want to do is we want to ask the user
to enter a word.
Suppose, we ask the user to enter the word, and the user enters love.
So in this case, I want to match any word that has love in it
as a substring.
So love will match, lovely will match, beloved will match and so forth.
Now you decide whether you want to be case-sensitive or not.
My solution is case-sensitive. If you were going to do a case insensitive-solution,
you have to write a little extra code. But here is a few sample runs.
Into the reception to search for, the user enters love and the results are
25919 words were searched,
and the substring love was found 171 times.
Now you'll get a different result if the user typed in love with a capital l, of course,
because my results are case-sensitive.
If the user enters Romeo with a capital R,
we'll find it 132 times.Obviously, were searching the same number of words every time.
If they typed in Juliet with a capital J, it's going to find it 49 times.
And unfortunately, my name's not in this place.
So if you type in Frank with a capital f, it's found 0 times.
Okay. So that's it, sample run of this.
So what's the steps you want to search for.
Well, let's search for Romeo lowercase.
That shouldn't be in there.
And you can see we found a 0 times. You could also see how quick this is.
Let's run it one more time.
And let's say I want to search for Romeo uppercase.
In this case, it will be there. It's on a couple of the captions.
Actually, a lot of times, we found a 208 times.
So that's it. It's pretty straightforward challenge.
I'm giving you no hints here. You decide
how to read this file, whether you want to redo a line at a time, a word at a time, a character at a time
and it's up to you and also how you going to figure out that substring.
Remember, from -- at this point, we should be using modern c++.
We shouldn't be using character arrays or character pointers.
We should be using std string objects,
right, c++ string object. So make sure you use those.
That's it. Have fun. Post your solution if you like. It's actually
pretty straightforward. The only chicken piece is finding that substring in the string.
All right. So I'll see you on the other side with the solution.