Sunday, October 10, 2010

First C++ PROGRAM

Hi there we meet again here. Today i am going to teach you  how to write a really simple coding for beginners.
Okaih, are you ready??

After i ve told you have to run Dev C++ , the only thing that we should do now is CODING. Don't copy and paste right away. But try to write the coding by yourself.

-------------------------------------------------------------------------------------


// Our First Program : Hello world I love Programming
#include <iostream>
using namespace std;

int main()
{
    cout << "This is my first lesson to bring some output from my program"<<endl;
    cout << "Programming is cool"<<endl ;
  
    system("pause");
    return 0 ;
  
}

-------------------------------------------------------------------------------------

Try to compile & run the code using F9.

You will have this output


Ok .. But I havent explain yet what the purpose of each written coding. So we will go one by one >< 


1) // Our First Program : Hello world I love Programming

  • This line shows that we want to comment on our coding for some certain reasons. For this program i commented  "Our Firs Program ......................" so that i myself know that this program is my first program and what is it about. The compiler wont execute any line that started with  // or /* and end with */ 
  • Other comment example
  1. //This program is about calculating area of circle (use for single line comment)
  2. /* This program is written by Alia */  (use for multiple lines comment)
2) # include <iostream>
  • # means preprocessor directives
  1. Preprocessor read your program and only executes lines beginning with a # symbol
  • #include means to include the contents of another file in the program . As u learn along you ll understand what this coding crapping about :D 
  • <iostream> means to include Input output file , and allow program to use the input output function such as cin>> OR cout<<
3) using namespace std; - to organize the names of program entities.

4) int main ()
  • marks the beginning of a function. 
  • int : indicates that the function sends an integer value as a return value. 
5) { (Open Curly braces) and (Closed Curly Braces) } 
  • While writing coding we have to write the programming statements inside block of Curly Braces 

6) Programming statements
      
    cout << "This is my first lesson to bring some output from my program"<<endl;
    cout << "Programming is cool"<<endl ;
  • This statement using the cout function to display the written statement. It is important to ensure that the strings are written in double quoted marks "    " 
7) system("pause") : means to let the display pause for a while. Do not terminate the program right away after          
                               executing it.

8) return 0 : means the function returns value of 0 


No comments:

Post a Comment