Showing posts with label Startup. Show all posts
Showing posts with label Startup. Show all posts

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

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