Saturday, April 27, 2013

Learning To Program in C++ !

Programming allow the user to program a piece of code which allow the user to control the computer, and making it do any task the user wants, and gives the user the power to interact with the computer. For example writing a payroll program which compute employees base pay, and net pay after taxes.

*Getting started*
The first thing you going to need is having a compiler, a compiler is a program which takes in the code you write and turn it to binary numbers, because computer only understand binary which is 0 and 1.

For window users i recommend Code Blocks Link ----> http://www.codeblocks.org/downloads

For Mac User I recommend XCode ----> https://developer.apple.com/xcode/

I will be using Xcode,

Step 1: to get started simply click XCode, and than click on Create a new Xcode project

Step 2: Click on command Line tool and click next
Step 3: Name your project i will Name mind "program1" and click create.
Step 4: On the left side click on main.cpp which will take you to a page where you write your code on.
Step 5: Let's Have fun programming our first program

Allow me to explain each line. 
Line 1-7 are a section for comments, usualy they would include the programmer name and the project name and date. 
Line 9 The "#include is a "preprocessor" it simply telling the compiler to put the code from the header which is "iostream" into out program before creating a executable code. 
Line 10 "using namespace std;" This tells the compiler to use a functions which is part of a library "std" which for example allow the use of a cout statement which prints a line of code. 
line 11"int main()" Tells the comipler there is a function called main and that functions returns an integer, that's where the int comes from  int= integer numbers.

Line 15  "cout << "Hello, World!"<<endl; This is a line of code which telling the computer to print out the statement " Hello, World!" the cout it's used to tell the compiler we would like to print out something in this case we wanted to print out "Hello, World!". It uses the << symbols, known as "insertion operators", to indicate what to output. Therefor to print or output something into the screen we would write cout << ""<<; and the code would print out anything that is between the two quotation mark!

Example if we wanted to print out " I am writing my first C++ Program"

We would use a code   cout << " I am writing my first C++ Program"<<endl;

our last step is to build the program and run it.

to build the program we click on command+B, if we didn't make any mistake it should say build program Succeeded,

Final step to run the program and display the result.
we click command+R

We Successful wrote our first C++ program,

Line 16 shows the example practice we used to print out " I am writing my first C++ Program"

and we could see our result in the Output Window.