This video teaches how to write C++ programs to calculate the area of a square (side × side) and the perimeter of a rectangle (2 × (length + breadth)), demonstrating essential programming concepts including header file inclusion, variable declaration and initialization, formula implementation using variables, and output using cout statements, while emphasizing the importance of using variables instead of hardcoded values and understanding the difference between mathematical notation and programming syntax.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
C++ Area and PerimeterAdded:
hello student welcome to the online classes of computer science today also we are going to continue with the word problems uh that we will be doing using a c plus plus programming language so the first question that is here is write a program to calculate the area of a square with side equals to 5 i hope that you all know the formula as how to calculate the area of a square so basically how do we calculate it so we come to our program where we shall be seeing it okay so here's the program children now as you can see in this program the first lines are your necessary lines mandatory lines that is hash include iostream.h which is used to include the header files which is also important because if you want to deal with the input output so you have to include this header file then is your hash include console header line call your dot h okay and then is your void main because this is the place from where the execution of your program begins so this line has to be there okay then is the curly braces which marks the starting of your program next is your clr spr which is used to clear the screen so that the previous output is not there next is your variable declaration and initialization line now children in the question we were asked to calculate the area of a square where side is equals to 5. now children as we know for the formula the area of the square is equals to side into side i hope that you have understood this so considering this formula in mind so over here the data type that i have used is int and the variable that i'm using is s so s the value is 5 is equals to 5 by 5 because this is the value which was given to us in the question itself and next is your a by a because a will be the variable that will be holding the final value area okay and the initial value that is the starting value that i have given to this variable is 0. okay children now comes the formula part okay so as we all know the formula to to calculate the area of a square is side into side so i have written over here is s into s okay children now see children you can also do it in a manner where you can just write a is equal to 5 into 5 that is also correct but as i have told you that if you will be writing it in that way it is correct for this program but then we will proceed and then we will be learning about these scene statements okay so in those uh that places we must be knowing that initially initializing the variable is very important because their values get changed so and using variables in the formula is also very important because ultimately different values will come to that variable so basically instead of using direct numbers over here we should keep in practice of using these variables okay now once it is calculated and in this point it has been calculated with the help of this formula next is to give the output now how do we give the output children for that we use the c out statement okay see out object okay now see out object with your cascading brackets and inside the double quotes we give the message okay and the message is area of a square is open after this i have used in cascading brackets and then i've written index by enter because i want the value to be printed into the next line and not in the same line okay now we have put a semicolon over here now next is again i've used a c out object and with this a cascading bracket and see children over here i've used a variable a because a is the variable that holds the final value which holds the area of a square okay and then [Music] gets it holds the output screen till you enter any character from the keyboard and then the curly braces which marks the end of the program after this what you need to do is you have to compile it okay it says no error now we will run our program and you will see the output so it says 25 so the area of a square is 20 but of course 5 into 5 is [Music] you can also use the float data type over here and you can give the values in decimal point okay depending upon your question type you can just manipulate this [Music] so i hope that you all know the formula is how to calculate the perimeter of the rectangle so here we shall be using the program [Music] so this is a very the the same program that we used for how to calculate the area first so now we will do these changes as you can see the first two lines will remain same because this is how we start our program and then [Music] that is used to clear the screen this will also be there and next is your variable declaration and initialization now this will change okay so now when you're talking about rectangle and to calculate the area so we go by what do we need now first is length which was given in the question paper was eight okay come on the breadth that was given in the question that was equal to 5 comma area sorry the perimeter we are supposed to find out the perimeter equals to zero okay now same equal as right now okay children now as for going about the formula that is there we say perimeter equal to 2 into 10 plus so children if you write them this way the two in the bracket you write l and then you write plus and then you write p and then again you put the brackets and semicolon this is how you've been doing in your mathematics but when you're talking about computer science children your computer will not understand that what it's supposed to do over here then between two and this bracket okay [Music] it is okay fine is and the variable now that holds the final value is b now we will just compile okay it says errors now over here it says call of non-function okay children uh as when we started our c i must have told you that uh these uh brackets as round brackets is because of the function okay whenever you see this round packet it is a function this main is a function then this clr scr is a function your guess see it is a function okay and then it says then if b [Music] [Music] in your maths you know that it is basically we have to multiply it okay but in computer science we have to tell the compiler that what it needs to do over here so over here we have to put this asterisk [Music] okay so this is very important you cannot just put the single bracket with this tool you have to put this active sign which is multiplication okay in computer science while doing programs you have to do it now we will compile this program again and now it says success okay and now we will run this program we shall be going so the output is 26. okay children you can just match up with yours and you can find out whether the computer is right or not i'm sure it is okay this is a simple program of finding out the perimeter of a rectangle when you have been given length and breadth in the question if you have not been given the length and the breadth then you may use your own numbers and you can just find out the perimeter same goes with the area okay now children if you can find out the perimeter of the rectangle you can of course find out the area of our example okay by just changing the formula over here you can just find out the area for a triangle and also in case of square altitude we have done a program of finding out the area but when you know how to do it and you know the formula then you can find the perimeter of a square as well so these were the very basic and simple programs that you all need to know that's all for today thank you
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03











