Hey guys, this is your boy, Vandat Rewal And in today's video, we are going to launch a new C++ DS algorithm code So, the main focus of this will be that you can break all the placement related companies Whether it is a big or small company We will be launching this in two phases Phase 1 will be totally placement oriented That you can break any company by studying for 70 hours Phase 2 will be for total coders That we have to go in competitive coding and depth You have to jump, you are going ahead of placement So, we will be uploading that in Phase 2. This course is made by 5 faculties, 2 of which are Microsoft, 1 is Google, 1 is RCCM, 1 is GS. Similarly, the course of WebD is also made by Fado. He has broken GSOC.
So, in this course, as you can see, we have made an index first. I will give you a brief overview, where we are going to teach all the topics. In the market, if someone takes Rs. 20,000, Rs. 30,000, Rs. 50,000, even Rs. 1 lakh, he cannot put such level of content.
We have introduced animation in quality production which is not done by institutes so that you can understand the theory concept well. We will be solving a lot of questions. We have introduced phase 2 so that competitive coders who have to study further than placement we are also satisfying them.
If you come down, we have covered all your topics. I am showing you a little overview of the index here. And if you come down more, then we have gone crazy.
So, let's get to it. These topics are not even coming here, but we have added them. So, we must be understanding the concepts through animation. After that, we will practice the questions and in the description box of every video, you must be getting some notes in which you will have additional exercises or your notes will be related to that video.
So, let's start the wonderful course. In real life, if we have to do any work with a person, then we give him a set of instructions which is one, through communication language like if you and I are talking we are talking in Hindi language we can also talk in English but if we want to use a computer or laptop or mobile device then we have to communicate first now we don't understand English and Hindi we understand Binary which is 0 and 1 why 0 and 1? because our laptop and computer are electrical devices and what can I say? that when the current is going inside the circuit, we should represent it as plus 1 and when there is no current going inside the circuit, we should represent it as 0 or we can think of it as when the device is detecting high voltage, we should represent it as plus 1 or when it is detecting low voltage, we should represent it as 0 so in this way, let's assume that 0 to 9 are the decimals in real life we can represent 0 with 0 in binary Decimal 1 we can represent with 1 in binary Decimal 3 we can represent with 11 in binary Decimal 4 we can represent with 100 in binary And in this way we move forward Similarly, A, B, C, D, E, F, G, special characters All the things we can explain to the computer in combinations of 0 and 1 Now in this way, you will think Brother This is looking very complicated. If I have to do 2 number addition in the future, 53 plus 72, then it will take a lot of time to write 0,1.
So I said, here we have high level languages, which help us. How? The high level language we are learning in this course is C++. So we write our code in C++, and that is sitting inside the compiler, which converts that C++ code into binary format, which the computer understands.
So, from here, our coding journey starts. Now, you have learned to talk, we have to give some set of instructions. To give instructions, we have to program.
So, we are using C++ as a language to give commands or instructions to the computer to perform something. Do we understand this thing? Let's take an example. Now, in day-to-day life, if I have to execute some work, So, we will give a set of instructions for that, which we will understand from a flow chart.
First of all, I will start. I need some raw material like maggi, masala and water. After that, I need some utensils and a stove where I can light the gas. Next step is that we put water, maggi and masala in that utensil.
After that, we boil it. And we check in between again and again that is maggi ready or not. If maggi is not ready, then we say boil it more. And if Maggie is ready, then we say, now turn off the gas.
After that, we eat, we serve Maggie, and we exit our flowchart. Similarly, when you want to explain a code to a computer, then before writing the code, we understand it through a flowchart, so that we know that, okay, in real life, how much similar communication is happening between computers. Find the sum of any two given numbers.
First of all, we will start. We need two numbers. So, should I take two inputs from the user?
Number 1 and number 2. After that, I have to add them. So, I have a sum equal to num1 plus num2. Here, sum is a new variable in which the added value of both of them will be stored.
After that, we want to print, show, and show the output on our desktop. So, should I say print sum? Similarly, what is a pseudocode?
Like we have made a flow chart here. This is called step-by-step. First you start, then you take input, then you calculate sum, then print sum, then exit. This is called Sudo code.
Now let's see some good examples. So now we are going to see one more question to make a flowchart and pseudocode. And our question is that we have to find the maximum of three given numbers.
So for flowchart, first of all, we will take input ABC. ABC are our three numbers from which we have to find the maximum. So what we will do is first of all, we will compare these two numbers.
So here I have compared A and B and I will check if A is more than B. So this is our decision box in which we are comparing. So decision box can have two outputs either yes or no.
So if A is more than B then we will get yes. So we will go to yes and check if A is more than C. If C is more than B then we will get yes.
A is maximum so we printed A If A is not bigger than C Means A is bigger than B But C is bigger than A So C is maximum So we printed C Now let's come back here Same thing is happening here If A is less than B So we will come to the side of No instead of Yes and here we will compare b and c if b is bigger than c then we will print b and if not then we will print c and last exit so this is our flow chart to check the maximum of three numbers here you have seen a new thing that what is decision box and if you see its pseudo code in pseudo code we are doing the same thing start and then read a b and c and then compare if a is more than b if it is then compare a and c if a is more than c then print a else means print c and if this is not true then we will come to else here we will compare b with c and if it is true then we will print b and if it is false then we will print c and exit ok So now let's see one more question and this question is that we have to find if a given number is prime or not. So prime numbers you must be knowing that prime numbers are those numbers which have only two divisors. One is that number itself and one is one.
So what we have to do here is to tell us whether any number is prime or not. We have to divide it from all the numbers. If any number is divided then it means that it is non-prime. and if it is not then it is prime now the question is how much we should check so we will start checking from 2 because 1 is already dissolved so we will start from 2 so I have read my number N and I have put my value 2 in the divisor now what I will do is I will check in the decision box that is divisor is less than N So, I asked you that till where we will check? We will check till less than n.
Because again n will be divided by n. So, we have to check till before that. So, we have to check till before 2 to that number that is dividing n completely or not. So, if we get this yes from here, then now we will divide n by divisor. and this percentage sign gives us remainder so if our n is divided by divisor and remainder is 0 so if we go to yes then our number will be non prime because any number is dividing n completely so it is a non prime so we will print non prime and if it is not like this if we come to no So here we will increment the divisor from 1 to 1. We will add 1 to it.
We checked for 2 first. Then we will check for 3. And then for 4 and so on. How long will we do this? Till the time divisor is less than n.
As soon as it becomes equal to n. Then we will know that we have divided n from all the numbers. And it is not divisible from any number.
So it means. ki prime number hai. Toh yaha pe hum print kar denge prime and then exit. If you see its pseudo code, we are reading n, we are taking divisor is equal to 2 and while divisor is less than n, we are checking whether n is divisible by divisor. If yes, then we will print non-prime and here we will finish our program.
If this doesn't happen then we will increment the divisor once. When this loop ends, you can see a loop is created. When this loop ends, we will print prime.
Because if this loop doesn't end anywhere in between, complete or a toe is come at lucky ko be number n co divided nahi kar raha hai and it is a prime number so we'll print prime number and exit take it to yay ho gaya to check if a given number is prime or not tomorrow next question kata he keep print all prime numbers still n I'm the key a number killing case a checker the key or primary any I'm a character in the key to prime numbers and whoa So for that we will see every number which is smaller than n and we will see if it is prime or not. If it is prime then we will print it and if it is not then we will check for next number and we will do this till we reach n. So you have seen its flow chart, we have started here and we have taken our input number n.
Now what we will do is we will start with 2 because 2 is our first prime number. So we will start with 2 and we will check that the value of 2 is more than n. Because we have to check the number till it is less than or equal to n.
So when it is more than n, we will exit. If it is not, then we will take a divisor, to which we gave value 2. check karenge ki kya wo num se kum hai agar hain hai to num se divide karke dekhenge us divisor ko tk to aap ye wala jo loop dekh rahe hai aap ye wala loop wohi hai jo humne last wale question me lagaya tha the exact same one aur ye loop kya kar rahe hai ye hamara check kar rahe hai ki num hai wo ek prime number hai ya nahi tk to yahan pe agar yahan se hamara the remainder comes by dividing the num with the divisor. If it doesn't come with 0, then we will make the divisor plus 1, and our loop will continue. If the remainder comes with 0, the num divides with a particular number, then it means that our num is not a prime number, because it is divided by a number.
so we will jump to next num so we checked for 2 and we got that it is prime so we checked for 4 and we got that 2 is dividing 4 so we will do num plus 1 so we will check for 5 and we will check again what is num is less or equal to if it is then we will repeat the same thing if not then we will exit ok now here the second thing is that here if the whole loop gets finished and the divisor becomes equal to num it means that no number could divide num completely and num is a prime number so here what we will do is we have to print the prime numbers So we have printed the num and then we will jump to the next num and then again we will check that it is not more than n. So we have this big loop where we are running all the numbers from 2 to n and there is a small loop in this big loop where we are checking that any num is prime or not. So this is the flowchart and pseudo code.
Here we are doing the same thing that read n take num is equal to 2 and till num is less than equal to n till then what we will do this loop this part inside it in which we will check that num is prime so we took divisor as 2 and till divisor is less than num till then see num is divisible by div no So what we will do is, if it is there, we will move on to the next number. So we will do num is equal to num plus 1. And if it is not there, then we will increment the divisor. Div is equal to div plus 1. And when this while loop will end, it means that our num is prime. So we have printed the num and then jumped to the next number. Ended and exit.
So this was our flowchart and pseudocode. to tell all the to print all the prime numbers till n. To download VS Code, we need to download the compiler first. So we will download compiler, i.e.
JV, 64 or 32-bit according to the architecture. So we will download the version of the compiler from searchforce.net, which is suitable. The.exe file will be downloaded. We will set it up.
At last, we can change the path or leave it the same. I will keep it in C program files because I will include this path when I set the environment variable. I will change its last name. After completing the installation, we have to set the environment variable.
For that, we will set the environment variable in the search bar. In the path, simply add the bin folder of our location, i.e. 64-bit. After adding this path, we can install the AS code.
After downloading, we will install the link. Following the instructions given. Nothing to change, it will automatically add the path to the variable.
Once this is done, we will write a simple code in this code of Hello World. From here, you can add extensions and plugins. By going to extensions, I have installed C++ plugins of CodeRunner and C++ Intelligence.
Let's write this code. Let's run it and see how it will print out Now we will see how to install this software First of all, we will open the terminal Type g++ in the terminal which is a compiler of C++ Now it will ask for permissions, so click on install we will accept the terms and conditions our software is downloading so what we do next is we install the VS Code till it is downloading to install the VS Code we will open Google Chrome and search we will open the first search result and select the one from the Mac now as it is being installed Now we will open this folder, extract it and then install it Our VS Code and our compiler is also installed The first thing we will do is we will create a folder We will create a new folder named Hello World A new screen of our VS Code has opened where our Hello World folder is showing So what we do is we create a new file So basically we give some name to this file like main.cpp And now what we have to do is we have to install 2-3 extensions in our VS Code to run C++ program First of all, we will type c++ here for the extension. And here we have installed it.
Now we will install coderunner to run the program. And this is also installed. Now we will go back to our file where we were writing the code.
Now we will check whether our installation is working or not. So basically, let's write a hello world c++ program and see if it is working or not. Here we have the option to run, so we will click on Run. As we can see, the hello world is now printed. When we run the program in VS Code, we have to save it first.
And then run it. We are going to see how we can make the VS Code that we installed last time, look better. So basically, what we do is, we divide our screen into two parts. We will write code on one side and blocks of input and output on the other side.
So, what we do for this is, we will go to view first. We will go to editor layout and select the two columns our screen is split into two parts go to editor layout again and split down the screen we split the right side screen into two parts now we will make the input file in the upper part and output file in the lower part so our program will take the input file and output file will be put in output file right side click on the top and press Ctrl and basically to open a new file so we make a file named input.txt same thing we do in the lower one and make a file named output.txt now when we have two files so here we can put our input whatever we want to put and here our output will come so basically what we have to do is we have to write some code so that the compiler will know that I have to take input from this file and I have to output in this file so now we see that code so basically we write in the first line we will include header file so our header file is our Iostream in next line we will write using namespace then our main block will start and in end we will write return 0 and in between you have to write lines so that compiler can know so for that basically this line is there what you have to do is to remember it exactly and as much as we will write program then you have to write same to same lines So, you must remember this in a way. We will see further what is its logic and how it works.
So, I will show you an example of how we write inputs on the right side and how its corresponding output comes. So, we take two integers and print their sum. So, suppose we have two integers a and b. So, we took their input from scene operator and then printed their sum a plus b.
We saved our program. We put two numbers in input, 2 and 3. and then run our program so you can see that our output is in output and texture which should be 5, by adding 2 plus 3, 5 is coming so 5 is coming in our output guys, it's time for a brain teaser now so brain teasers are asked in interviews and we should keep practicing to improve our analytical thinking so today's brain teaser is this we are given 2 hour glasses understand hour glasses These two hourglasses are such that one hourglass is empty in 7 minutes and the other hourglass is empty in 4 minutes. Empty means that the upper part of the hourglass takes this much time to get sand in the lower part.
So, the big one takes 7 minutes and the small one takes 4 minutes. Now the question is that we have to measure the time of 9 minutes by using these two hourglasses. So, how can we do that? About this, wait here. think about it and if you don't understand then come back to the video we will discuss its answer so how will I do this?
suppose the time is 0 minutes so I will flip both the hourglasses now in 4 minutes the sand of the small hourglass will be finished all the sand above will come down so in 4 minutes I will flip the small hourglass again in the big hourglass the sand of 3 minutes is still there will be left to come down. That will end in 7 minutes. So what will happen in 7 minutes?
My big hourglass will be completely empty and my 4 minute hourglass will still have 1 minute sand left in it. Right? Because 4 to 7, 3 minutes have elapsed. So 1 minute sand will still be left in it. So at 7 minutes I will flip my big hourglass again.
Done. So what will happen in 8 minutes, in 8 minutes my small hourglass will be empty again and in my 7 minute hourglass, only 1 minute sand will be dropped. What will I do in 8 minutes, I will flip my big hourglass again, at this time not the small one but the big one.
So what will happen with that, as I said in my big hourglass, only 1 minute sand will be dropped. So if I flip it, then I will see that the sand will be dropped. So it will take 1 minute to come down.
Till now our 8 minutes were covered. And I will measure 1 more minute in this as soon as the sand comes down. So I can say that my 1 minute has elapsed.
So like this 8 plus 1 will be 9. And that's how we will be able to measure using these two hour glasses for 9 minutes. So this is a very famous brain teaser. And I hope you understood. We have added more brain teasers in the PDF along with more questions on pseudocode and flowchart. So do try them out.
And that's all for this video. Thanks for watching. Bye-bye. Take care.