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 


Software needed to RUN C++

Hi everybody. Before we start our first lesson , we have to download a c++ compiler to run our written code program.

There are many FREE available software to be download by you. I will give some link for you to download.


Now im using Visual C++ Express Edition 2008. But for our lesson, i prefer to use Dev C++ because its  more easy to use. Ok everybody. Hope that you have download your compiler safely. 

Next , we start on how to use this brilliant C++ compiler. First we run Dev c++ . 

Program Image.

2) Open FILE menu , choose NEW > SOURCE FILE
3) Start writing the coding. 
4) Open EXECUTE menu , choose COMPILE & RUN (to run the program)
5) Finished ! If your program is well written . It will Run, if not compiler will tell you that your program has
    errors.

To be continued ..............







About Us

 Hi everybody this is my last attempt to contribute some Programming knowledge over the world. To be frank im not among GENIUS student in my class. But i believed that sharing is the reason why someone succeed. 
Let me introduce myself. I am Jannatul Alia Ramli , Graphic Software and Multimedia student from (University Technology Malaysia). I am in my second year. And I love programming. The reason why i build this website is just to share my little knowledge and help others to understand C++ in simpler way.Above than that i also want to improve myself. If we can proceed successfully in C++ lesson, i would like to continue with OpenGL programming as well. 

Thats all for now. Keep supporting.