Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

C++ Functions


     Hey People..!! WWeLLcoMMe to coding tutor blog.. After a loooong time.!! So how are you doing? Me..? I'm great!!!  Hope you too!!
     Well.., This year , I started to write this blog by determined to end this lesson series.The reason is that this lesson series took so long to complete and also I have more fun stuff to teach you to do with your computer and mobile.. I'm hoping to add more Fun , Interesting and Interactive Stuffs to my blog. Hope you will  enjoy them too!! 


     Alright!! Let's get started.!

Introduction.

          What is a function? In programming , a function is like an electronic device which do things for you. 

     
For example , If you feel hot turn on AC or fan, It'll cool you down , wanna wash some clothes? put them into the washer and turn it on, It'll wash your clothes and give you.  
Want some Chilled water? put your bottle of water in to the fridge and it'll give you chilled water, warm food? put in the microwave oven...  So the list goes on..! You get the idea right?

     So just like those devices, functions do things for us. If you have a bunch of numbers and you want to find the maximum number out of them? You can use "MAX" function. Wanna find out the minimum number ? use the "MIN" function. Wanna sort out some messed list of things in alphabetical order? Use "SORT" function! Does the robot you programmed, going zig-zag instead of walk in a straight line? use "PID" function.(It's a code for robots ^-^)



     So you can see that the "Life is easy with functions!! ".




  





Parts of a Function

     In a c++ function, there are specific parts.




  1. Data Type (ReturnType)
  2. Function Name
  3. Arguments (Inputs to the function)
  4. Statements (Things done by the function)
  5. Return Value (Outputs from the function)

Steps to Writing a Function


  1. Understand the purpose of the function.
  2. Define the data that comes into the function from the caller (in the form of parameters)
  3. Define what data variables are needed inside the function to accomplish its goal.
  4. Decide on the set of steps that the program will use to accomplish this goal.
 ( Reference : http://www.cs.utah.edu/~germain/PPS/Topics/functions.html)

That's all about the functions. In next post let's do some exercises on functions. Bye!! :)

C++ Variables


     Helloo.. My favorite blog readers.. Welcome to the newest post from ispire++ blog. This post is the next post of our fundamental of programming post series . So don't get confused this with our new post series OOP.
     I gave you some homeworks in my last post. Did you do those. Well if you did here are the answers for them.

Last posts Homework answers ;)









So... last week I promised you to start to talk about c++ variables. Here lets start it. Variables are a kind of structure we use to hold data in a program. 
     We know that when we run a program, it runs on our RAM.(Random Access Memory) . In a program, when we want to store some data(Temporarily, Not on hard disk), We create variables. 
      For example, let say we want to store the age of a person. What we have to do is create a variable to hold that data age of a person. Age is measured by years, so it is we can consider as an integer value. So what exactly we want to do here is, create a variable to hold an integer data. And store our data (age) in it. 
How do we do this.
     We want an integer variable, so we type int first,
     Then we put a space, and then we type a suitable name for the variable, ie:- age.
Ok, and finally as always we type semicolon ; . Right! We now have officially created the first variable we ever created in c++. Weldone guys.. :) 



     
     Ok.. now after we created the variable, lets store something in it. In this example age. Let say the age of the person is 23. So what we do is , in a new line we type the name of our variable, age , and then we type equal sign(in c++ it is known as assignment operator) after that we type the value we want 23 and finally semicolon;. 
     Congratulations you have assigned a value to your variable. Now let's check the variable. In a new line let's start a code to print the value. Type, cout<<age; and build and run your program.




     See the output! It says 23 right!! That's the value we assigned to our variable. See how easy to create variables, assign values to them and use them!! 

     Now I want you to create 5 variables about 5 subjects of a student naming English, Programming, Drawing, Electrical, Fluid. And assign the marks values as follows 80, 83, 75, 80, 60. And then in your program write a code to take them as output. Do this as a homework I'll give you the answers in our next post. 
     Ok.. here I end up this post. Hoping to see you in my next post soon.. Bye..!! :)

Next post>>>

Life of a Systems Engineer

  Hello, my dear readers. ✌😀✋ I'm talking to you after a very long time. And I am thrilled to talk-to and hear-from you after all thi...