1 00:00:05,250 --> 00:00:09,550 Welcome to the third challenge of the section 19 part of the course. 2 00:00:10,650 --> 00:00:15,150 I'm in the section 19 workspace in the challenge_3 project. 3 00:00:15,150 --> 00:00:17,650 And this is the project that I'm supplying to you. 4 00:00:17,900 --> 00:00:21,500 The challenge_3_solution project will have my solution, 5 00:00:21,500 --> 00:00:23,000 which I go over the next video. 6 00:00:23,800 --> 00:00:26,800 This challenge is all about finding words in files. 7 00:00:27,300 --> 00:00:31,290 So the idea here is for you to ask the user to enter a word. 8 00:00:31,290 --> 00:00:36,190 And then you're going to search the text of the Romeo and Juliet play by Shakespeare 9 00:00:36,190 --> 00:00:39,390 to see how many times is that word is found in the text. 10 00:00:39,390 --> 00:00:42,590 Okay. I'm supplying the Romeo and Juliet text. 11 00:00:42,590 --> 00:00:44,590 You can see it right here. You can get this from 12 00:00:44,590 --> 00:00:47,250 Shakespeare.mit.edu. 13 00:00:47,250 --> 00:00:50,850 And there's the entire play that it's a very long play. 14 00:00:51,150 --> 00:00:54,150 But you can see that there's all kinds of words in here. 15 00:00:54,150 --> 00:00:58,150 And what we want to do is we want to ask the user 16 00:00:58,150 --> 00:01:00,150 to enter a word. 17 00:01:00,150 --> 00:01:03,450 Suppose, we ask the user to enter the word, and the user enters love. 18 00:01:03,950 --> 00:01:07,850 So in this case, I want to match any word that has love in it 19 00:01:07,850 --> 00:01:09,100 as a substring. 20 00:01:09,100 --> 00:01:13,000 So love will match, lovely will match, beloved will match and so forth. 21 00:01:14,100 --> 00:01:16,700 Now you decide whether you want to be case-sensitive or not. 22 00:01:16,700 --> 00:01:21,600 My solution is case-sensitive. If you were going to do a case insensitive-solution, 23 00:01:21,600 --> 00:01:25,260 you have to write a little extra code. But here is a few sample runs. 24 00:01:25,260 --> 00:01:29,160 Into the reception to search for, the user enters love and the results are 25 00:01:29,160 --> 00:01:32,060 25919 words were searched, 26 00:01:32,060 --> 00:01:34,940 and the substring love was found 171 times. 27 00:01:34,940 --> 00:01:39,740 Now you'll get a different result if the user typed in love with a capital l, of course, 28 00:01:39,740 --> 00:01:42,240 because my results are case-sensitive. 29 00:01:43,040 --> 00:01:45,400 If the user enters Romeo with a capital R, 30 00:01:45,400 --> 00:01:49,900 we'll find it 132 times.Obviously, were searching the same number of words every time. 31 00:01:50,500 --> 00:01:54,600 If they typed in Juliet with a capital J, it's going to find it 49 times. 32 00:01:54,600 --> 00:01:56,850 And unfortunately, my name's not in this place. 33 00:01:56,850 --> 00:02:00,150 So if you type in Frank with a capital f, it's found 0 times. 34 00:02:00,150 --> 00:02:03,510 Okay. So that's it, sample run of this. 35 00:02:05,010 --> 00:02:07,210 So what's the steps you want to search for. 36 00:02:07,210 --> 00:02:10,110 Well, let's search for Romeo lowercase. 37 00:02:10,660 --> 00:02:11,860 That shouldn't be in there. 38 00:02:12,660 --> 00:02:16,660 And you can see we found a 0 times. You could also see how quick this is. 39 00:02:16,860 --> 00:02:18,360 Let's run it one more time. 40 00:02:18,910 --> 00:02:22,910 And let's say I want to search for Romeo uppercase. 41 00:02:22,910 --> 00:02:26,210 In this case, it will be there. It's on a couple of the captions. 42 00:02:26,210 --> 00:02:29,210 Actually, a lot of times, we found a 208 times. 43 00:02:30,710 --> 00:02:33,510 So that's it. It's pretty straightforward challenge. 44 00:02:33,510 --> 00:02:35,510 I'm giving you no hints here. You decide 45 00:02:35,510 --> 00:02:39,870 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 46 00:02:39,870 --> 00:02:43,770 and it's up to you and also how you going to figure out that substring. 47 00:02:43,770 --> 00:02:47,070 Remember, from -- at this point, we should be using modern c++. 48 00:02:47,070 --> 00:02:50,970 We shouldn't be using character arrays or character pointers. 49 00:02:50,970 --> 00:02:53,730 We should be using std string objects, 50 00:02:53,730 --> 00:02:57,390 right, c++ string object. So make sure you use those. 51 00:02:57,390 --> 00:03:01,490 That's it. Have fun. Post your solution if you like. It's actually 52 00:03:01,490 --> 00:03:05,390 pretty straightforward. The only chicken piece is finding that substring in the string. 53 00:03:05,940 --> 00:03:07,940 All right. So I'll see you on the other side with the solution.