The first Program in C++. Using Code Blocks


Hello Again my Fellow Readers..!!
Hope you have installed Code Blocks and waiting to start your first C++ program and looking for me.. ;)
Sorry for the delay..! Let’s start quickly..
So if you opened a new project and opened it’s main.cpp file , now you can see the first program has already created…
Really..!!
Sure..  What you can actually see is bunch of lines of codes of a simple program. This line of code is known as the source code of your program. Means this is the set of instructions you gave to the program.

So what happened in this program.. Let’s check it out.. In the top tool bar you will see an icon with a cog wheel saying build.. You can build your program using it.. Click on it..
 (It will compile your program.. )  Then you see a green color arrow head icon next to build icon.. (Run) Click it and boom!! There is your first program.. It will open the command prompt and run your program in it.

This program will display the message “Hello World” in cmd. Press Enter and then the program will terminated.
            So what happened here was the source code was translated into machine code by a compiler. That’s what you done by building the program. Then you run the program.
So a compiler is a translator between programming language  and machine language.
There is another translator called interpreter. Both compiler and interpreter do the same thing but in different ways. A compiler translates the entire program at once. Interpreter does that by translating the codes line by line , consuming more time but, easier to identify errors more accurately than compilers.

Come back to your code, Select the code, and press delete. Right.. Now do exactly what I say..
1.     Type   #include<iostream>
     This is a header file, Also known as a preprocessor.
2.     Next line Type   include namespace std;
    
This part is essential to output a message in cmd. Don’t forget the semi-colon ; at the end of the line.
3.     Then type   main()
4.     On the next line type   {
     Open curly brace.
5.     Then type   cout<<”Your Name”;
      replace the Your name with your name  ;) (Within quotation marks)  ex:-    “Shehan”. Don’t forget the semi colon again.
6.     Then type    return 0;
7.     And finally type       }

Done…   Now build and run the program.    
This will be the output.


Right, now I want you to delete   cout<<”Your name”;   and  type  cout<<”Your_Name”<<endl;  and  cout<<”Your_Address”<<endl; in two different lines.
Build it.. and run it.. And see the result.


       I think you got the idea that cout<<” ” is use to display an outputs in your program.   
       endl; - is refer as end of line, which creates a new line, after that.

       So…!   Use cout, to display different outputs.
 Try to use it creatively.
See You in m next Post..!!!   Have fun..    R.S.
Next Post>>

Let’s Start Coding ( Introducing Code Blocks )

Let’s Start Coding.



Hello Guys..!! Welcome to engineers favorite programming blog.. ;)
Last week we started our little chat about programming…  Computers, codes, Instructions so and so..
            And remember the simple game which I introduced to you.. I hope you have enjoyed your first approach to the world of programming.. :)
            Last week We came up to a point..
A computer program is a list of instructions that tells a computer what to do.. Everything a computer does is done by using  computer programs. A computer program is written in a programming language.”
Starting from that point,
            A program is a written thing, in a computer (list of instructions). To write something we need a language.
            OK..!!  We know some languages.. right..! we can use them to write a program.. (English or sinhala or tamil ) easy..!!
            But, unfortunately computers can-not understand human languages.
Computers, use 
very complicated language to operate which is really hard for us (human) to use. ( :D You know computers, they are geniuses) (ex : Machine Language -Binary)

            So in order to talk to a computer , and to make things done by him, we need an intermediate language. And create a program (List of instructions) using that language. Those kind of languages are known as programming languages.

 “FORTRAN” was the first programming language, created in 1953..

There are thousands of programming languages in the world.
·         Java.
·         PHP. ...
·         JavaScript. ...
·         Python. ...
·         Objective-C. ...
·         Ruby. ...
·         Perl. ...
·         C, C++ and C

So what you have to do is pick a language and learn to code using it.

            As our language, I Chose C++ to begin our journey..
C++ was a creation of Mr. Bjarne Stroustrup in 1979 from Bell Labs. See that bald guy here, that's him.


As the name stands for C++ is an enhancement to the C language 1983.

            We can make c++ programs by just using a compiler and note pad, Save the written program in “.cpp” extension and compile it and run it in command prompt. Or by using the terminal in Linux or Ubuntu You can do the same process..,
            But, That is a lot to do..
            To make the process easier, We can use an IDE (integrated development environment).
You might have heard about it already CODE BLOCKS. A Famous cross platform IDE. You can download it free from here http://www.codeblocks.org
Just download it, Run the setup and and you are ready to start programming.


            When you first opened the Code Blocks here's what you have to do,
1.    Open the Code Blocks.

2.    Select new Project.

3.    Select Console Program

4.    Select C++

5.    Give a name for Your Project.

6.    And Finish Wizard.

Then you will end up in this interface.


On the left side of the screen, there is a panel choose projects. And There will be your project in a tree view. Click on it (+ Sign).

Then You will see a file called main.cpp, Double click on it.


On the code screen a Sample program (Hello World) will appear, You can start program by changing it as you wish..  :) This is really Easy..!!
Try it now.. 
I will see you in my next post to tell you how to make your First C++ Program...!

Let’s start at the very beginning.


When you think about the word “Programming” what comes to your mind.??..  A computer , Bunch of codes , a geeky thing which makes you  headache..
Yeah.. I know right.. ;)  But wait….!



What if I tell you that programming is not as hard as you think , or better what if it is the most easiest and fun thing to learn among your engineering subjects… ( You kidding me.. right..!!)  No…
Let me explain….

Think about your alarm clock for a minute.. At night you set your alarm (for a specific time you want) and go to bed, on next morning the alarm rings on time, you hear it , you snooze it and you sleep again… ;) right..
In that scenario you gave instructions to the alarm clock by setting the alarm and the clock worked according to your instructions..

The concept behind computer programming is same..  You give instructions to the computer and computer works according to those instructions and that set of instruction is called a computer program..


A software is a collection of such programs made by computer programmers.
So simply.. “A computer program is a list of instructions that tell a computer what to do.. Everything a computer does is done by using a computer program. A computer program is written in a programming language.”
Easy.. right..!! :) 
See.. That’s what I told you… I hope you’ve already started to feel it… You like it..? Follow me.. There is a lot to tell you.. 
See you in next post.. Bye..!


P.S

Hey there.. Here’s a bonus for you.. I’m hoping to tell you about variables, control structure, looping, arrays, functions in future…

  Those words might be new to you.. But eventually you will realize how easy those concepts are.. And I’m going to tell you an extra easier and fun way to understand those concepts..

This is a simple puzzle game called light-bot.


Lightbot is great fun and does a surprisingly thorough job of introducing some pretty complex principles of programming.

You don’t want any programming knowledge to play this game, But at the end of the game you will end up having a good understanding about all the basic concepts of programming. And you will receive a certificate like this


for completing a basic programming course .

Hope you will enjoy.. See you soon.. Happy weekend..!! 
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...