Showing posts with label Robotics. Show all posts
Showing posts with label Robotics. 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++ Classes.






     Helllooo.... Readers... Welcome to inspire++. How are you my technical nerdy followers. The week before Last week was awesome. Thanks to the seniors from mechatronics.. We had a awesome workshop on robotics.. All the circuits, cool robots, drones you presented, the actual circuits we created using arduino boards most importantly the programming challenges you gave us !!! Truly seniors!! You did great. That was a day to remember.. :) 
That been said.. Owkayy!! Lets Jump in to the lesson today!!

Classes.
     The main purpose of C++ programming is to add object orientation to the C programming language and classes are the central feature of C++ that supports object-oriented programming and are often called user-defined types.

     Last week we talked what are objects. An object is an entity (Real world thing). In programming , an object is a thing either from the perspective of the user of the software or the programmer. 

     * Object has two components, Properties and Behaviors.

     Classes on the other hand known as blueprints (Plans) of objects. It's just like house planing. You build a house according to the plan. You can build as many houses as you want using the same plan, if you want to. For each house, you don't want to make a new plan. 

     In a program when you want to create an object, first what you have to do is create a class of that object. Then use the name of that class to create objects.

     For example , think you have to make a software to a company to record the details about their customers. So a customer has a name , company gives him a customer ID, From when this person is a customer of the company..etc, And the customer buy things , customer may be given a discount by company. 

     Ok.. When you look at this scene what you have to keep in mind is that there are more than one customer in a company (more than 1000 maybe). So you have to see that there is a pattern. The best thing to do is take all the common factors of each customer and make it an object. Means, Create a object to the customer.

     Right! , to create an object what we have to do is, as I mentioned earlier , create a class. Ok.. Now what I'm going to do is , create a class called customer. Let's see how to do that.

First Create the class.






     Then type the keyword public inside the class.


Look!! There is a Colon : after public!! (Not a semi Colon!! ; ) 




     Under public , define all the variables you want.
Ok! We have finished creating the class. Now it's time to create an object using that class (plan). Here's how you do it. 
     In main function, type the class name and leave a space ,and give a new name to your object (C1). 

Then here's how you use the properties of that object.


Did you got the idea. Ok! Just like that we can create any amount of objects we want.


See how simple the idea is. OK.. Now I want you to practice this concept. So here are some examples. I will give you the answers in the next post.

Practice:
     Create a Class named Box. Add variables Height , width , breadth. Create three Box objects in main function using that class. Give different values to the each object. Write a program to print the volumes of each box.

See you guys soon. Bye bye..!! :)






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...