Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
All right, so let us start with this simple template that I'm giving to you.
OK, that's just some standard template that you already know most of its parts, OK?
And you know that this program will read a file name from the user.
So we will create an array of characters just to store the actual file name that we are expected to
read from the user.
We're also probably going to create write a pointer to file FP since we are going to work with files
and then we are going to read the file name from the user and store it inside file name.
So far, so good.
Then we are going to make sure that we have opened the file correctly and we are going to iterate over
all the elements of the file itself.
Basically taking in reading each character one at a time.
So one of the question is how can you know, OK?
Because we are interested just in the lowercase letters we are interested in knowing how many times
the lowercase a will appear, how many times the lowercase B, how many times C and so on up until Z.
Right.
So that's what we are interested in.
And one of the options that basically, I think the most trivial in the first option that may come to
mind is like to neglect and not work with this frequency appearance's array and simply to create variables
like this.
OK, so in a b, c, d, e f g and so on and so forth.
And each of these variables is going to represent the total number of appearances of character, a character
B and so on.
OK, but that's not the best way to go about it.
And I think that you can see why, because we have 26 variables this way and every time we will need
to increment them, and the program is going to be probably really, really huge and not so optimized
and not so extensible.
Well, and also not so easy to read, in my opinion, at least.
OK.
So we are going to go with a simple way, which is going to be pretty much the same.
OK, we are going to create a frequency appearances array, which is going to look like this.
OK, it's going to be of these format.
OK, let me draw it.
OK, let me get this part.
We are going to create these frequency appearances and raise so frequency.
Frequency appearances are ringing.
And this array is going to be of what size, what size do you think these areas should be?
We are talking about lower case letters.
Well, we know that in English we have 26 lowercase letters, so the size of the array is going to be
26, right?
So that means that if we start from index zero, then we are going to have one two three up until 25.
Right.
A total of 26 elements.
So far, so good.
Awesome.
And each of these elements, right?
Each of these elements is going to represent the number of appearances.
OK, so each element, let's say it right here.
Each element.
Is going.
He's going to represent to represent.
The total.
Appearances.
Total appearances.
Come on.
Total appearances.
Of.
A certain.
Character.
OK of a certain letter.
And this means that.
We will say that.
Frequency appearances are rate index zero will represent the total number of times that a character
A appears in the file frequency appearances at Index one will represent the total number of appearances
a character B appears in the file.
Also, we will go for a C, for a D, so on and so forth up until Z.
All right, is it clear, so that's what we are going to do inside of this array.
That's why we are going to use it and how we are going to do it.
That's exactly what we are going to see right now.
But first of all, it's very important that you will understand what each and every one of these elements
that you are using this array, what it's used to represent.
All right.
So we are going to create.
Let's see how we can do it.
We are going to create a frequency array, OK, and frequency array.
Let's use it int into frequency frequency array of what size of size 26.
And we are going to initialize each of these values to zero and not to stay with the garbage values
that we cannot basically use a lot of things with them.
And we are going to say that all of the elements are going to be zero representing that before we started
to read the file itself.
We say that each letter appears zero times right because we didn't read any character so far.
OK.
We're also going to create some additional variables for our assistance.
We will call it current director, and this variable is going to store inside of it.
Just for simplicity is going to store every character that we will read on every iteration inside of
the while loop.
OK.
So far, so good.
So we have these array of characters.
Each value inside of this array equals to you.
Let's get let's get.
These color equals two zero zero zero zero at that time, up until the last element.
Now what we are going to do is to ask, while we did not reach the end of the final.
Let's read character by character from the file itself and store these characters inside of current
character equals to f get C and store it right here.
OK, so on every duration, we will read one after the other, a character after a character from the
file.
And now we would need to think about what should be the condition to make sure that we have read a lowercase
letter.
So one of the options to use here is if current character is greater or equal to lower case.
And also, if it is, if it's basically low no less than or equal to lowercase that z.
If that's the case, then it means that the current character are based on the YASSKY table is in the
range between lowercase a two lowercase z.
OK.
If not, then it's probably a different character.
It may be an uppercase.
It may be some digit.
I don't know.
It also may be some special characters like different signs and so on.
OK.
But we are interested since that's what we were requesting these exercises.
We are interested in working with lowercase letters.
OK, so we asked if current character is greater or equal to lowercase a.
And also, if current character is less than or equal to Z, then we can say for sure that current character.
Holds a lowercase letter.
OK, so if that's the case, what we would like to do is go to this array and say, let's increase the
associated element.
OK, let's increase its frequency appearances.
So if we would go about it and say, like frequency, appearance, frequency array at index current
character and we say like plus plus, then we could get a problem.
OK, and the reason why we get a problem?
OK.
The reason is because current character holds the actual character that we are working with.
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
a represents the index zero because that's not how it's going to work.
A is basically some number.
OK, in the ASCII table, it has a decimal representation of, I think, 97.
So you will try to go to Index 97, and that's also access violation.
You will get probably an error.
So you need to, you know, OK, as an outside observer, you know that these array at index zero,
it will specify the number of appearances for Character A.
But the program doesn't know it.
He doesn't seize.
He doesn't see that current character here.
If it holds a, it represents the value of zero.
So you need like to reduce the character a out of it.
So we will specify minus character.
Eight.
So what it will do, it will give the character, let's say it will be character A..
OK, so in current character, we read the value of a.
So it will take the value of a minus the value of Fey and it will get the index zero.
And that's why we will be able to go here and to use plus plus to increment the number of appearances
by one.
If, for example, current character was C, let's see.
OK, so it will be like this.
So C minus C will be what will be two.
OK, so you will go to these array and you will simply print and you will simply implemented by one.
OK, so that's the way that you access each of these elements and how you increment them.
OK.
So after these?
Part is over and we reached the end of the file.
We will have an array of 26 elements and each element representing the number of occurrences of each
character.
Now all that remains is simply to print these values to the screen.
So let's go with something nice.
Let's use print f total appearances.
Off lower case letters in file, let's say, specify also the file name itself will be, I don't know,
let's go like this and file name.
OK, so what we've done is total appearances of lowercase letters in file here, we will specify to
file.
That's it.
OK.
So if we were on it, we will not see the number of appearances of every letter, of course.
We will simply see the message over the file name.
That's it.
So what we need to do is to iterate now over all of the elements of these frequency appearance's array
and the way we do it is using some for a loop.
OK, so for let's create also a variable, it's create variable.
I said we will say four are equals to zero.
As long as I is less than what less than 26 I plus plus.
So if that's the case, we are going to iterate over each of the elements and printing out there.
Let's say later.
And we will specify a higher percentage.
See?
Right.
The actual letter.
A year, how many times percentage these times, right?
And now, instead of the present, the U.S. will need to specify what we will need to specify the actual
value that we are talking about just using here.
I will not work because it will be zero and we need to represent from a.
So that's why we will add these distance, these gap.
And also, we will specify instead of percentage will specify what.
We will specify frequency, appearances, array and index I.
So this way we will print that letter specific letter a right will star zero plus eight is a OnePlus
eight is B two plus a C.
So letter specific letter appears percentage frequency array at index design, which represents the
actual number of appearances of these particular value.
OK.
Oh, so this was not an easy one to explain.
I hope you're with me so far.
Okay, now let's try to run this program and make sure that everything works.
Okay, so here is the final solution to this program.
Let's run it.
Make sure that it works.
Okay, I have my previous file also here, so enter a file name to test you.
Create your own file.
OK, save you two with whatever a name you like.
I'm going to work with Violet already have, so my file data extreme.
And now, once I'm going to press enter, I would like to receive a full information about all the characters
and the frequency of appearances inside of these file called my file that DSD.
So let's hit, enter and see what happens.
All right.
So we see Letter A appears three times that there would be zero literacy, one times and so on and so
forth.
You can see that I appears four times.
OK, so basically, the lowercase v doesn't appear at all because I think that in the file itself,
I used uppercase v to specify my name, right?
What was it?
Let's see.
So yeah, I use the capital an uppercase V, so we did not take it into account since we were interested
just in lowercase letters.
OK.
So that's about it, OK?
And you can see that iReports are four times lower case, a one, two and three times exactly as we
had right here, right?
Where was it?
Exactly three times.
OK, so awesome, it seems to be working just fine.
Tested out on your own.
Check it and make sure that it works exactly as you expect.
And until the next time.
Thank you guys for watching.
Keep on practicing.
Keep on moving forward and you are bound to succeed.
Good luck in the next exercises and in the next topics until the next time.
Bye.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.