♫ ♫ Opening Music Hello! Welcome to another lesson of their course Algorithm. My name is Gustavo Guanabara, I'm your teacher .
. . .
. . And now, after all those lessons that we saw.
Finally, we got our first class exercises! We will exercise the sequential structures when creating our algorithms. So I created some situations here.
We will try to solve these problems, both the "Scratch", as in "Visualg". Initially, we will use the two tools, but focus their studies on "Visualg". For it is with him that you will leave for other programming languages, such as: Java, PHP and other languages you want to learn.
So let's begin our lesson solved exercises . . .
. . .
Knowing an important character, which will greatly help us today. So let's go to our exercise class, with a very important person: the "Creuza"! The Creuza, this figure is part of packet "Scratch".
So we'll use it in our programming. The Creuza is good people as hell and are in need of help. In fact, it is in need of six aid!
And we will begin to help Creuza, solving those little problems that she has. The first problem is that's coming her birthday and she does not know how many candles to put on the cake. So, like I said .
. . .
. . Is to take place the anniversary of Creuza .
. . .
. . And she does not know how many candles to put on the cake.
He gave a problem in her head. She knows what year you were born, but do not remember her age. And we will make a program to solve this simple problem that Creuza is having.
And we will, right away, using the "Scratch", which is simpler and we can put Creuza on the screen. It is important to say that this first exercise, I'll show you step-by-step creation of Creuza, put it on the table and such. Then, in the next years, I will have to come up with it all ready!
So if you have any questions ahead, go back to class five, then, I'll just show it once! Then, you will open the "Scratch". He will come up with a kitten .
. . .
. . And I will remove this object.
For this, I'll click right and will choose "delete". Now, I'm no object. Let's add the Creuza by clicking on this button here in the middle.
What is "Choose a sprite file. " Clicking on it, we will enter in the "People" and Creuza . .
. . .
. It is somewhere around here. On here!
I'll put. . .
. . .
It quick stop there! I come here to stage . .
. come here in desktop background . .
. import a background. Let's put Creusa at her house.
Will you be home? The Creuza. Yeah there at her house.
You are about to make birthday. And there is some problem. Let's click here in the object.
The object has to be selected. We'll see the commands for her. So my command will be .
. . when I click on the flag .
. . something will happen.
So as I said before, just to recap, the Creuza's with a problem . . .
she knows when he was born but she does not know how many candle have to put on the cake. So what do we do, it is to create an interaction between Creuza and our program. Let's see how we do it!
Then I put there in my control section, when the banner is clicked. Let's create here a sensor. Where Creuza ask: - What year are we?
And then wait for the answer. I'll put the answer down here. Later she'll ask another question.
Will be In what year I was born? And it will also wait for the answer. And the answers can not be there loose, they have to be saved We have seen in previous lessons that there are variables.
So we have to create variables for the current year and the year she was born. So we here in variables. we will create a variable for the current year and a variable for year of birth And do not forget the identifiers naming rules we saw in class 2 algorithms.
So if you still have questions Go on to class 2 and see what the 6 rules. It has to start with letter, then can be letter or number, can not contain space can not have stress, can not be reserved words and symbols or contain then these are the six identifiers naming rules that we have in programming languages, so . .
. we used the underline "_" to separate two words, then these are the names valid so now I have to put each of these responses within the variables so I'll put here, change the "ano_atual" to "answer" in which I give in the first then makes the second question, then I'll change the year of birth "ano_nasc" to "answer" careful you do not select the "change by", he will add values here you have to be "move to" and "change to" so now he asked "What year are we? " The variable "ano_atual" said she was born and put in the year of birth variable "ano_nasc" and now it's simple right?
For you know the age of a person just know the year we are and the year she was born, simply subtract these two values . . .
and then we arrived in the person's age. To make this account, we will create another variable, which is the age of Creuza. So here in the area of variables, I'll create another called age and I will change the age to a formula For this I will use the operators we've seen It is a subtraction operator That will contain the current year Least the year of birth of Creuza.
So we will change the age to "ano_atual" less year of birth "ano_nasc" Now I'll make the Creuza find out what her age. For this I'll click on "Appearance" and have her think her age I will come here in variable, take the age and drop this box Be careful not to drop this box is the time in seconds it will think. Let's click on the banner and see the result.
The first thing Creuza did was ask "What year are we? " We are in 2014. In that year she was born?
You were born, Creuza in 1999. Pressing "Enter" She will think you have fifteen years. See how simple was the line of reasoning?
One thing that was strange was she just think of a number Let's put a message for her to think. For I will come in "Operators" and use the "add" Then he will join with something else. I'll put "My age is" and then age.
I will drag this "join" here. Running again . .
. "In what year we are", 2014. In what year was he born: 1999.
Now she will think "My age is 15. " Doing it that way is very easy, is not it? Now let's go to the "Visualg" And let's see how it would be the same solution using the first tool .
. . to build algorithms that we present this course.
Passing here to the "Visualg" We will make the program "Creuza01" At the beginning of the program . . .
We will do the same thing here, let's make her ask what year we are And expect an answer. Let's put here Write ( "What year are we in? ") Remember that you can use accent here .
. . I'm just not using because of my keyboard incompatibility with this Windows virtual machine.
Let's put Read and brackets "()", we put the variable is stored In the case here, I will use the same name, year underline current "ano_atual" Let's put current underline year "(ano_atual)" We'll have to put the variable up here "Ano_atual" like "Full" Let's do the second question: Write ( "In what year I was born? ") and we put Read (ano_nasc) We will declare also ano_nasc And it's important that I give two tips here: the first, you must already realize that I did not create the top-down algorithm, I do not get, as some teachers ask in universities and colleges, that early on they ask "how many variables are going to have? " I do not know how many variables will have!
It begins to make the program needed the variable goes up there and declares. The second tip is the indentation Indent indicates which commands are within other structures. So take a look here with me, you will understand what is indenting.
So if you notice here, my variables are a little inside. I just use the keyboard TAB key to create this tab. This indicates that the variables are within the "var" area.
The same thing happened here pro "Write" where, when I use a tab, and the "Type" go inside, the "start" automatically aligns with the "fimalgoritmo". This is not an obligation, but it is a good programming practice. Your program will function normally without the indentation But that does not mean it should not exist.
well indented codes are basic features of a good programmer. From now on, I will do the following: my current year minus year of birth, It is the formula that I'll use and I will play this result into the variable age. I'll say up here and finally we write the result what is: My age will be It is the age Remember that the word "age" is in red because it is in quotes, will appear the word "age".
The word "age" is in black, and it will display the contents of the variable age, We've seen this before. Let's run the program: What year are we? 2014.
In what year I was born? 1999. It will show: "My age is 15.
" Perfect? So we did the same problem solved in two different situations: one using Scratch and another using VisuAlg. Initially I recommend that you practice the two, because practice makes perfect.
And the tool independent of it. At any time, remember that you can pause this video by clicking here, and look at the code, making it the VisuAlg. Never forget: the best way to practice is doing.
Only attend class does not help much. Let us now go to the second situation where Creuza will star here shows your problems. The second problem which will pass Creuza is as follows: She had her birthday, and she wants to give away a trip to the States.
And the first thing you have to do, after you buy the ticket, of course, It is to buy dollars. And then the Creuza're having trouble with this. So, to celebrate the birthday, she will travel and need to buy dollars.
And here comes the first problem: she has her money, which is Real, And she'll need to know how many dollars it will be able to buy, or exchange, call it what you want. And then I will do this: I'm here with my browser on a currency converter I'll put here, so I know how much that 1 dollar ta costing, So 1 Dollar're costing 2. 22.
So pro our exercise, let's consider one dollar is equal to 2 reais and 22 cents. So I've created here Scratch, with Creuza stop now on the lawn, And we'll do the commands here. Let's create a control, "When is clicked" We will ask, "How real do I have?
" And we will wait for the answer. This response will be stored in a variable, I will create a variable here, which is called "real". And we'll change the actual to the answer that was given.
Now we'll change the dollar, for something. We will use an operator that is the division operator, And we'll put here: to convert the variable "real" divided by the price, which is 2. 22, as we saw earlier.
We do now in appearance she say something. Let's create a junction. For her show, "Can I have $", and the value in US dollars.
Let's run: She will ask: "How real do I have? " I'll put 100 reais. 100 reais gives to buy $ 45.
04. Let's see if that's right: if I'm Real, I'll convert to Dollar were 100. Gives 45.
05. Huh? Rounding here, gives 45.
05. Let's do another example: Let's assume that she has, like, 428 reais. 428 reais would give $ 192 or so.
Back here in my converter: 428, 192 would approximately. And now directly pro Visualg. In VisuAlg, we will have the program "Creuza02" And I have to state here, since I already know the variables and real dollars, the real kind, since it has the decimal part.
Let's write: "How Real I have? " I'll put an R $ side just to make typing easier. I will read the amount of actual.
Note that my real variable is called, but I can not declare a variable called real, because "real" is a reserved word, And we will do the conversion, which is the amount of actual divided by 2. 20, here is not 2 point 20. 2 point 20.
And let's play this result into the variable dollars. Finally, we will write the result, that is: "Can I have $" US dollars. let's run, let's do the same example with 100 (one hundred).
give 45. 45 (forty-five point forty-five) and the same example with 428 reais (R $) that would give $ 194 (US $) and there he saw how it is simple ? !
go to another problem that creuza this going, why she has traveled, we have arrived noas United States, and had a big problem Arriving in the US it ta facing a big problem, which is the temperature. If you do not know, in the US the temperature measurement used is not Celcius (C) is fahrenheit (F) So when creuza arrived at the airport she looked at you that was 100 degrees and she thought, "gee, 100 degrees ? !
in rio de janeiro with 40 (forty degrees) I'm already desperate, imagine 100 ! ! I'm going to melt here!
" and in fact he did not know it was another way to measure. So we will create here a program that does the conversion of temperature that creuza ta seeing it for the temperature it would here in Brazil. conversion between Fahrenheit and Celsius are made through this formula, where the temperature is in Celsius temperature in Fahrenheit least 32 (thirty two) divided by 1.
8 (one point eight) going directly to the scratch and see it works So in scracht, I have prepared her here he is in the United States Then we'll create a control here, when the banner is clicked I'll make a sensor to ask what the current temperature? What's the temperature here? I'll put the answer, I will keep this answer in a variable named "F" Fahrenheit important that you use clear names for variáves I will make "F" pass to answer and now we'll do one more variable which is the variable "C" is the temperature in Celsius, so we'll change "C" For that our formula which is calculated by a division where numerator I have a subtraction Important to establish this way, this subtraction is made the amount of F least 32 divided by 1.
8. So let's change "C" for it all Finally we put in appearance, for her to think a joint "in Brazil would be? " and we will show the temperature in Celsius Let's run.
What is the temperature here? Let's take the example of 100 degrees In Brazil was 37. 7 which is a normal temperature especially here in Rio de Janeiro Let's go directly to the Visualg and do the same problem.
Let's create the two variables Fahrenheit and Celsius of the actual type Let's ask the temperature there. What's the temperature here? Using the same questions I used there in Scratch.
Read "F" "C" will be worth the variable "F" minus 32 divided by 1. 8 It is important here since "F" is the numerator you put in brackets Otherwise you will remember that it will take 32 divided by 1. 8 and subtract the result of "F" For the order of precedence that we saw in the first algorithm classes say first is made multiplication and division and after additions and subtractions We will show the result "would be in Brazil and the variable" C "" Let's see if it works, using 100 37.
7. Remembering that we can format this by placing, for example, 1, 2, 3, 4 houses a whole Four houses and one after the comma. Running we have here in case four houses, where he used only 3:01 after the comma So was 37.
8 in Brazil, became clear. So now we go to our last situation That Creuza is going, as she returned from trip I bought a lot of swag, bought many electronics And now she will have to pay taxes so So as I said she returned from trip and bought a lot of muamba And electronic equipment has a tax as soon as you arrive in Brazil This tax is variable, but we will consider, where 60% because we are in the early years And here comes a big problem that many people have when it comes calculations, which is the percentage calculation Calculate the percentage of something is very simple and I'll show you, we will use as an example the calculation that I spoke here as I said the tax is 60% calculate 60% of something is quite simple I get that something multiply by 60 and divided by 100 and even the name says sixty percent You get the value multiplied by 60 and divided by 100 sixty percent And I know your teacher algorithm or the person who taught you to program may have taught you a lot of trick a lot of formulazinha a lot simpler thing but nothing more simple to get this thing multiply by 60 and divide by 100 then in a similar way if I want 10% of something I get that something multiply by 10 and divided by 100 Let's see how this works So now there ta the Creuza already returned to Rio de Janeiro that warmth and she's in trouble you have to pay tax So when the banner is clicked we will make it enter What is the value of the product? and will wait for the answer that answer goes to variable price.
I can not use ç so is price we will change the price for response We will also create one variable tax and this variable tax You will receive a value which is 60% of the price value for that we'll get a split in the numerator and we put a multiplication which is made by the asterisk then we will put the price of the product, as I want 60% will put 60 and will divide by 100 if I want 20% I put 20 here, if I want 40 button 40 and so on then my tax will be 60% of the price we show appearance for him to say a junction of a tax will be, we put the tax amount here. Let's run! if I bought a thing a thousand dollars, I have six hundred tax dollars let's just put the currency symbol to be cute the value of the product US $ 980, will have a US $ 588 tax Let's see Visualg, then we will put here, to ask him What is the price of the product?
put here, Read price I will have here the price variable, we'll have the tax, we'll declare up here both the real kind and my tax will receive the price times 60 divided by 100 in this case is not necessary parentheses, but since price is 60 times the numerator I will use parentheses to force and make it clear that it will happen first but remembering that parentheses in this case was optional, we show the tax will be tax, let's run. bought something thousand dollar tax will be 600 Format it are two points five houses in all two decimal 987 would get 592. 20 so here I have three two five, I got five numbers in all, two of which are at the end so I have five numbers to the whole of which two are at the end and there has to understand the problems that had Creuza and which are simple mathematical calculations are situations of everyday life and were situations that I applied here creating story for you So is this now your time has come to practice For the Creuza's with another problem and that I will not solve This is for you So after buying the stash and have 60% to pay the tax Creuza ran out of money And she had to get a bank loan I know that this loan thing is kinda complicated but we will simplify this for your situation and you will understand what I want to do then talking to the manager Creuza made the following taking a loan it will have 20% interest and will be able to piecemeal So what I propose to you is the following, you will make a program to help Creuza She will tell how much she wants to get loan, for example R $ 1,000.
00 by loan account will be 20% increase because of interest So for example picking up R $ 1,000. 00 loan she will have to pay R $ 1,200. 00 this is a hypothetical situation and she will be able to piecemeal so she will be able to say how many times she will have to share this R $ 1,200.
00 to R $ 1,000. 00 catch borrowed I created this situation it is already resolved and I'll show you how I want it to happen but I will not show you the code then the situation is this, I'll click on the flag What is the value of the loan, we put R $ 1,000. 00 R $ 1,000.
00 20% increase would R $ 1,200. 00 How many installments? 10 If I get R $ 1,200.
00 and divided into 10 installments, each installment will be R $ 120. 00 Then I will pay 10 installments of R $ 120. 00 Gave to understand what I want, then all this will need your reasoning the mathematical calculation is the basis that we made previously You will then have the percentage calculation and you will have to divide by the number of installments try to improve that your algorithm for him to show what the full amount, which the full amount with interest What is the total amount of each installment So do programs, create programs So this solution is that you have to create Are you have to study enough practicing in order to create this algorithm so I wanted to once again like to thank everyone Thank for the success that's being this course algorithm and invite you as always by clicking here You will sign the Travel Channel in Video Then all the lessons that leave you will receive directly in your feed and I always give the recommendation goes there click the engrenagenzinha side register and he says, look I want to receive e-mail saying every time you leave a lesson whenever you leave a lesson you will be warned, you will not miss any By clicking here you will see all classes of travel So from the first class from the inicioziinho You're coming now're just seeing exercise, you have an entire course for you to learn this then by clicking here you will have access to all classes and do not forget to always access the www.
cursoemvideo. com because there you have the packages to download has exercises, you have a number of things there the site're always going through changes us when we're launching this video 're going through some changes, then thank you for the patience of all the material're getting there're being very important so you can learn algorithm, learning to program using the Video Course, then move this idea forward to show people short video, show on social networks, show on Facebook so much so that the course will grow, and so will you encourage me to do always new lessons then a big hug and good studies to the next Hi Hi Hi Hi Hi tá difficult today Music he, he, he, returned to and calm.