All language subtitles for 24. Exercise 6 - lowerFrequencyAppearances Program for Lowercase Letters - Solution

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,710 --> 00:00:06,200 All right, so let us start with this simple template that I'm giving to you. 2 00:00:06,290 --> 00:00:11,960 OK, that's just some standard template that you already know most of its parts, OK? 3 00:00:11,990 --> 00:00:16,160 And you know that this program will read a file name from the user. 4 00:00:16,160 --> 00:00:22,640 So we will create an array of characters just to store the actual file name that we are expected to 5 00:00:22,640 --> 00:00:23,690 read from the user. 6 00:00:24,680 --> 00:00:31,700 We're also probably going to create write a pointer to file FP since we are going to work with files 7 00:00:32,660 --> 00:00:37,670 and then we are going to read the file name from the user and store it inside file name. 8 00:00:38,060 --> 00:00:39,260 So far, so good. 9 00:00:40,340 --> 00:00:47,600 Then we are going to make sure that we have opened the file correctly and we are going to iterate over 10 00:00:47,600 --> 00:00:50,210 all the elements of the file itself. 11 00:00:50,240 --> 00:00:54,500 Basically taking in reading each character one at a time. 12 00:00:55,430 --> 00:00:58,040 So one of the question is how can you know, OK? 13 00:00:58,040 --> 00:01:03,800 Because we are interested just in the lowercase letters we are interested in knowing how many times 14 00:01:03,800 --> 00:01:10,130 the lowercase a will appear, how many times the lowercase B, how many times C and so on up until Z. 15 00:01:10,490 --> 00:01:10,880 Right. 16 00:01:11,660 --> 00:01:13,400 So that's what we are interested in. 17 00:01:13,550 --> 00:01:19,400 And one of the options that basically, I think the most trivial in the first option that may come to 18 00:01:19,400 --> 00:01:28,070 mind is like to neglect and not work with this frequency appearance's array and simply to create variables 19 00:01:28,070 --> 00:01:28,530 like this. 20 00:01:28,560 --> 00:01:33,650 OK, so in a b, c, d, e f g and so on and so forth. 21 00:01:34,040 --> 00:01:40,670 And each of these variables is going to represent the total number of appearances of character, a character 22 00:01:40,670 --> 00:01:41,570 B and so on. 23 00:01:41,790 --> 00:01:44,600 OK, but that's not the best way to go about it. 24 00:01:44,600 --> 00:01:51,890 And I think that you can see why, because we have 26 variables this way and every time we will need 25 00:01:51,890 --> 00:01:59,780 to increment them, and the program is going to be probably really, really huge and not so optimized 26 00:01:59,780 --> 00:02:01,700 and not so extensible. 27 00:02:02,210 --> 00:02:06,740 Well, and also not so easy to read, in my opinion, at least. 28 00:02:07,040 --> 00:02:07,340 OK. 29 00:02:07,370 --> 00:02:12,770 So we are going to go with a simple way, which is going to be pretty much the same. 30 00:02:12,830 --> 00:02:18,150 OK, we are going to create a frequency appearances array, which is going to look like this. 31 00:02:18,170 --> 00:02:21,020 OK, it's going to be of these format. 32 00:02:21,020 --> 00:02:22,150 OK, let me draw it. 33 00:02:22,160 --> 00:02:23,990 OK, let me get this part. 34 00:02:26,930 --> 00:02:31,190 We are going to create these frequency appearances and raise so frequency. 35 00:02:32,230 --> 00:02:33,940 Frequency appearances are ringing. 36 00:02:35,560 --> 00:02:41,040 And this array is going to be of what size, what size do you think these areas should be? 37 00:02:41,080 --> 00:02:43,750 We are talking about lower case letters. 38 00:02:44,530 --> 00:02:53,080 Well, we know that in English we have 26 lowercase letters, so the size of the array is going to be 39 00:02:53,080 --> 00:02:54,640 26, right? 40 00:02:55,060 --> 00:03:04,580 So that means that if we start from index zero, then we are going to have one two three up until 25. 41 00:03:04,600 --> 00:03:04,990 Right. 42 00:03:05,230 --> 00:03:07,840 A total of 26 elements. 43 00:03:08,650 --> 00:03:09,640 So far, so good. 44 00:03:10,480 --> 00:03:10,930 Awesome. 45 00:03:11,560 --> 00:03:13,650 And each of these elements, right? 46 00:03:13,690 --> 00:03:18,460 Each of these elements is going to represent the number of appearances. 47 00:03:18,490 --> 00:03:22,270 OK, so each element, let's say it right here. 48 00:03:22,570 --> 00:03:23,680 Each element. 49 00:03:25,540 --> 00:03:26,500 Is going. 50 00:03:29,540 --> 00:03:34,430 He's going to represent to represent. 51 00:03:35,950 --> 00:03:36,850 The total. 52 00:03:38,980 --> 00:03:39,970 Appearances. 53 00:03:42,180 --> 00:03:43,950 Total appearances. 54 00:03:45,070 --> 00:03:45,670 Come on. 55 00:03:46,060 --> 00:03:47,560 Total appearances. 56 00:03:49,700 --> 00:03:50,220 Of. 57 00:03:51,130 --> 00:03:51,970 A certain. 58 00:03:53,750 --> 00:03:54,440 Character. 59 00:03:55,320 --> 00:03:56,700 OK of a certain letter. 60 00:03:58,200 --> 00:03:59,910 And this means that. 61 00:04:00,890 --> 00:04:02,180 We will say that. 62 00:04:03,140 --> 00:04:11,050 Frequency appearances are rate index zero will represent the total number of times that a character 63 00:04:11,060 --> 00:04:19,580 A appears in the file frequency appearances at Index one will represent the total number of appearances 64 00:04:19,700 --> 00:04:22,130 a character B appears in the file. 65 00:04:22,820 --> 00:04:27,860 Also, we will go for a C, for a D, so on and so forth up until Z. 66 00:04:28,850 --> 00:04:33,630 All right, is it clear, so that's what we are going to do inside of this array. 67 00:04:33,650 --> 00:04:37,790 That's why we are going to use it and how we are going to do it. 68 00:04:37,820 --> 00:04:40,060 That's exactly what we are going to see right now. 69 00:04:40,070 --> 00:04:45,980 But first of all, it's very important that you will understand what each and every one of these elements 70 00:04:45,980 --> 00:04:50,120 that you are using this array, what it's used to represent. 71 00:04:50,630 --> 00:04:51,110 All right. 72 00:04:51,740 --> 00:04:53,900 So we are going to create. 73 00:04:54,170 --> 00:04:55,190 Let's see how we can do it. 74 00:04:55,220 --> 00:04:59,950 We are going to create a frequency array, OK, and frequency array. 75 00:04:59,960 --> 00:05:08,870 Let's use it int into frequency frequency array of what size of size 26. 76 00:05:09,290 --> 00:05:16,010 And we are going to initialize each of these values to zero and not to stay with the garbage values 77 00:05:16,190 --> 00:05:19,580 that we cannot basically use a lot of things with them. 78 00:05:20,000 --> 00:05:25,700 And we are going to say that all of the elements are going to be zero representing that before we started 79 00:05:25,700 --> 00:05:26,930 to read the file itself. 80 00:05:27,350 --> 00:05:34,130 We say that each letter appears zero times right because we didn't read any character so far. 81 00:05:34,760 --> 00:05:35,080 OK. 82 00:05:36,350 --> 00:05:40,760 We're also going to create some additional variables for our assistance. 83 00:05:40,760 --> 00:05:47,050 We will call it current director, and this variable is going to store inside of it. 84 00:05:47,070 --> 00:05:53,780 Just for simplicity is going to store every character that we will read on every iteration inside of 85 00:05:53,780 --> 00:05:54,830 the while loop. 86 00:05:55,460 --> 00:05:55,820 OK. 87 00:05:56,480 --> 00:05:57,440 So far, so good. 88 00:05:57,740 --> 00:05:59,600 So we have these array of characters. 89 00:05:59,630 --> 00:06:02,690 Each value inside of this array equals to you. 90 00:06:02,720 --> 00:06:03,830 Let's get let's get. 91 00:06:03,830 --> 00:06:11,600 These color equals two zero zero zero zero at that time, up until the last element. 92 00:06:13,090 --> 00:06:18,460 Now what we are going to do is to ask, while we did not reach the end of the final. 93 00:06:19,500 --> 00:06:26,070 Let's read character by character from the file itself and store these characters inside of current 94 00:06:26,070 --> 00:06:31,380 character equals to f get C and store it right here. 95 00:06:31,770 --> 00:06:37,860 OK, so on every duration, we will read one after the other, a character after a character from the 96 00:06:37,860 --> 00:06:38,250 file. 97 00:06:39,600 --> 00:06:45,840 And now we would need to think about what should be the condition to make sure that we have read a lowercase 98 00:06:45,840 --> 00:06:46,350 letter. 99 00:06:47,070 --> 00:06:54,630 So one of the options to use here is if current character is greater or equal to lower case. 100 00:06:55,140 --> 00:07:03,690 And also, if it is, if it's basically low no less than or equal to lowercase that z. 101 00:07:04,260 --> 00:07:09,900 If that's the case, then it means that the current character are based on the YASSKY table is in the 102 00:07:09,900 --> 00:07:12,990 range between lowercase a two lowercase z. 103 00:07:13,530 --> 00:07:13,950 OK. 104 00:07:14,100 --> 00:07:17,110 If not, then it's probably a different character. 105 00:07:17,130 --> 00:07:18,360 It may be an uppercase. 106 00:07:18,360 --> 00:07:20,130 It may be some digit. 107 00:07:20,130 --> 00:07:20,580 I don't know. 108 00:07:20,580 --> 00:07:25,410 It also may be some special characters like different signs and so on. 109 00:07:25,890 --> 00:07:26,160 OK. 110 00:07:26,970 --> 00:07:31,230 But we are interested since that's what we were requesting these exercises. 111 00:07:31,470 --> 00:07:34,980 We are interested in working with lowercase letters. 112 00:07:35,310 --> 00:07:39,120 OK, so we asked if current character is greater or equal to lowercase a. 113 00:07:39,360 --> 00:07:46,860 And also, if current character is less than or equal to Z, then we can say for sure that current character. 114 00:07:49,220 --> 00:07:53,180 Holds a lowercase letter. 115 00:07:54,170 --> 00:08:01,190 OK, so if that's the case, what we would like to do is go to this array and say, let's increase the 116 00:08:01,190 --> 00:08:02,760 associated element. 117 00:08:02,780 --> 00:08:05,180 OK, let's increase its frequency appearances. 118 00:08:06,230 --> 00:08:12,410 So if we would go about it and say, like frequency, appearance, frequency array at index current 119 00:08:12,410 --> 00:08:17,030 character and we say like plus plus, then we could get a problem. 120 00:08:17,660 --> 00:08:19,880 OK, and the reason why we get a problem? 121 00:08:20,300 --> 00:08:20,780 OK. 122 00:08:20,810 --> 00:08:28,040 The reason is because current character holds the actual character that we are working with. 123 00:08:28,820 --> 00:08:37,500 So if you go and say go to this index, it will not be able to right away say, OK, so let's go this 124 00:08:37,520 --> 00:08:42,050 a represents the index zero because that's not how it's going to work. 125 00:08:42,560 --> 00:08:44,450 A is basically some number. 126 00:08:44,610 --> 00:08:49,940 OK, in the ASCII table, it has a decimal representation of, I think, 97. 127 00:08:50,240 --> 00:08:54,800 So you will try to go to Index 97, and that's also access violation. 128 00:08:54,800 --> 00:08:56,630 You will get probably an error. 129 00:08:57,620 --> 00:09:04,100 So you need to, you know, OK, as an outside observer, you know that these array at index zero, 130 00:09:04,130 --> 00:09:07,940 it will specify the number of appearances for Character A. 131 00:09:09,030 --> 00:09:11,250 But the program doesn't know it. 132 00:09:11,460 --> 00:09:12,690 He doesn't seize. 133 00:09:13,020 --> 00:09:15,540 He doesn't see that current character here. 134 00:09:15,690 --> 00:09:19,170 If it holds a, it represents the value of zero. 135 00:09:19,620 --> 00:09:24,060 So you need like to reduce the character a out of it. 136 00:09:24,060 --> 00:09:27,300 So we will specify minus character. 137 00:09:27,300 --> 00:09:27,570 Eight. 138 00:09:28,290 --> 00:09:32,490 So what it will do, it will give the character, let's say it will be character A.. 139 00:09:32,520 --> 00:09:35,850 OK, so in current character, we read the value of a. 140 00:09:36,180 --> 00:09:41,730 So it will take the value of a minus the value of Fey and it will get the index zero. 141 00:09:41,730 --> 00:09:47,460 And that's why we will be able to go here and to use plus plus to increment the number of appearances 142 00:09:47,460 --> 00:09:47,970 by one. 143 00:09:48,480 --> 00:09:51,570 If, for example, current character was C, let's see. 144 00:09:51,600 --> 00:09:53,310 OK, so it will be like this. 145 00:09:53,580 --> 00:09:57,210 So C minus C will be what will be two. 146 00:09:57,540 --> 00:10:02,820 OK, so you will go to these array and you will simply print and you will simply implemented by one. 147 00:10:03,570 --> 00:10:07,620 OK, so that's the way that you access each of these elements and how you increment them. 148 00:10:08,490 --> 00:10:08,910 OK. 149 00:10:09,450 --> 00:10:10,590 So after these? 150 00:10:11,690 --> 00:10:14,900 Part is over and we reached the end of the file. 151 00:10:15,320 --> 00:10:24,530 We will have an array of 26 elements and each element representing the number of occurrences of each 152 00:10:24,530 --> 00:10:25,190 character. 153 00:10:25,850 --> 00:10:31,010 Now all that remains is simply to print these values to the screen. 154 00:10:31,010 --> 00:10:32,720 So let's go with something nice. 155 00:10:32,720 --> 00:10:36,980 Let's use print f total appearances. 156 00:10:38,090 --> 00:10:48,470 Off lower case letters in file, let's say, specify also the file name itself will be, I don't know, 157 00:10:48,560 --> 00:10:50,500 let's go like this and file name. 158 00:10:51,970 --> 00:10:57,730 OK, so what we've done is total appearances of lowercase letters in file here, we will specify to 159 00:10:57,730 --> 00:10:58,180 file. 160 00:10:58,870 --> 00:10:59,500 That's it. 161 00:10:59,950 --> 00:11:00,250 OK. 162 00:11:00,910 --> 00:11:05,410 So if we were on it, we will not see the number of appearances of every letter, of course. 163 00:11:05,440 --> 00:11:08,280 We will simply see the message over the file name. 164 00:11:08,290 --> 00:11:08,770 That's it. 165 00:11:09,430 --> 00:11:15,490 So what we need to do is to iterate now over all of the elements of these frequency appearance's array 166 00:11:15,970 --> 00:11:18,670 and the way we do it is using some for a loop. 167 00:11:19,030 --> 00:11:23,020 OK, so for let's create also a variable, it's create variable. 168 00:11:23,020 --> 00:11:27,460 I said we will say four are equals to zero. 169 00:11:27,910 --> 00:11:32,680 As long as I is less than what less than 26 I plus plus. 170 00:11:33,800 --> 00:11:39,590 So if that's the case, we are going to iterate over each of the elements and printing out there. 171 00:11:39,650 --> 00:11:41,210 Let's say later. 172 00:11:41,720 --> 00:11:43,640 And we will specify a higher percentage. 173 00:11:43,640 --> 00:11:44,090 See? 174 00:11:44,540 --> 00:11:44,800 Right. 175 00:11:44,900 --> 00:11:46,220 The actual letter. 176 00:11:47,560 --> 00:11:52,450 A year, how many times percentage these times, right? 177 00:11:54,550 --> 00:12:01,300 And now, instead of the present, the U.S. will need to specify what we will need to specify the actual 178 00:12:01,690 --> 00:12:04,780 value that we are talking about just using here. 179 00:12:04,780 --> 00:12:09,670 I will not work because it will be zero and we need to represent from a. 180 00:12:09,970 --> 00:12:13,630 So that's why we will add these distance, these gap. 181 00:12:14,990 --> 00:12:19,790 And also, we will specify instead of percentage will specify what. 182 00:12:20,880 --> 00:12:25,740 We will specify frequency, appearances, array and index I. 183 00:12:26,960 --> 00:12:34,700 So this way we will print that letter specific letter a right will star zero plus eight is a OnePlus 184 00:12:34,700 --> 00:12:37,250 eight is B two plus a C. 185 00:12:37,820 --> 00:12:45,320 So letter specific letter appears percentage frequency array at index design, which represents the 186 00:12:45,320 --> 00:12:49,580 actual number of appearances of these particular value. 187 00:12:50,030 --> 00:12:50,420 OK. 188 00:12:51,900 --> 00:12:54,510 Oh, so this was not an easy one to explain. 189 00:12:55,290 --> 00:12:57,000 I hope you're with me so far. 190 00:12:57,090 --> 00:13:00,990 Okay, now let's try to run this program and make sure that everything works. 191 00:13:00,990 --> 00:13:04,410 Okay, so here is the final solution to this program. 192 00:13:04,860 --> 00:13:05,680 Let's run it. 193 00:13:05,700 --> 00:13:06,810 Make sure that it works. 194 00:13:06,810 --> 00:13:12,000 Okay, I have my previous file also here, so enter a file name to test you. 195 00:13:12,000 --> 00:13:13,740 Create your own file. 196 00:13:14,040 --> 00:13:17,120 OK, save you two with whatever a name you like. 197 00:13:17,130 --> 00:13:21,410 I'm going to work with Violet already have, so my file data extreme. 198 00:13:21,870 --> 00:13:28,980 And now, once I'm going to press enter, I would like to receive a full information about all the characters 199 00:13:28,980 --> 00:13:34,400 and the frequency of appearances inside of these file called my file that DSD. 200 00:13:34,410 --> 00:13:36,750 So let's hit, enter and see what happens. 201 00:13:37,680 --> 00:13:38,250 All right. 202 00:13:38,580 --> 00:13:44,250 So we see Letter A appears three times that there would be zero literacy, one times and so on and so 203 00:13:44,250 --> 00:13:44,700 forth. 204 00:13:45,630 --> 00:13:47,820 You can see that I appears four times. 205 00:13:48,420 --> 00:13:54,870 OK, so basically, the lowercase v doesn't appear at all because I think that in the file itself, 206 00:13:54,870 --> 00:13:58,680 I used uppercase v to specify my name, right? 207 00:13:58,710 --> 00:13:59,260 What was it? 208 00:13:59,280 --> 00:13:59,970 Let's see. 209 00:14:00,630 --> 00:14:08,190 So yeah, I use the capital an uppercase V, so we did not take it into account since we were interested 210 00:14:08,190 --> 00:14:10,500 just in lowercase letters. 211 00:14:11,340 --> 00:14:11,760 OK. 212 00:14:12,800 --> 00:14:14,280 So that's about it, OK? 213 00:14:14,300 --> 00:14:23,000 And you can see that iReports are four times lower case, a one, two and three times exactly as we 214 00:14:23,000 --> 00:14:24,710 had right here, right? 215 00:14:24,710 --> 00:14:25,250 Where was it? 216 00:14:26,870 --> 00:14:28,880 Exactly three times. 217 00:14:28,910 --> 00:14:32,210 OK, so awesome, it seems to be working just fine. 218 00:14:32,660 --> 00:14:33,980 Tested out on your own. 219 00:14:34,010 --> 00:14:37,670 Check it and make sure that it works exactly as you expect. 220 00:14:38,120 --> 00:14:39,660 And until the next time. 221 00:14:39,680 --> 00:14:40,970 Thank you guys for watching. 222 00:14:41,030 --> 00:14:42,380 Keep on practicing. 223 00:14:42,440 --> 00:14:45,800 Keep on moving forward and you are bound to succeed. 224 00:14:46,700 --> 00:14:51,380 Good luck in the next exercises and in the next topics until the next time. 225 00:14:51,740 --> 00:14:52,130 Bye. 20141

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.