Tuesday 31 May 2016

Introduction to C++ 

Introduction to C++ - Armed with the basic concepts of algorithms and programming, so we can further learn programming  language that we will use in this time  to learn the  C++ programming language. The solutions of the problems that we face need to be mapped into the algorithmic language to make it more easily understood in the form of the programming language used. Then algorithmic  language is mapped  into C++ in accordance with the structure of C++ programming language.

The C++ programming language was the development of the C programming language as its predecessor. The term of C++ is often known as "C with Classes" bacause the programming language C++ has supported  object­oriented  programming as well as Java programming language. All the existing  library on the C programming language has also been included in the C++ programming language.


The compiler is a software that used to change the program code (source code) into machine language (binary file) so it can be executed by the computer. The program will be able compiled if the program contains no errors at all in its rules (syntax error). Examples for popular  C/C++ compiler are MinGW and GCC, the compiler usually has been packaged/bundled  with its IDE software (Integrated Development Environment). IDE software  is an  integrated  interface with facilities including a compiler for creating or development of the program. The popular and opensource C/C++ IDE Software that are Codeblock, Dev C++, and Sublime (for Mac OS)

The C++ Programming language has case sensitive characteristic, which means the compiler distinguish uppercase  and lowercase letters, for example, if we write printf and Printf in the C language, the C compiler will consider both of the texts are in different meanings. In practical of C++ programming language today, we are going to use Dev C++ IDE which also as the open source compiler program.

The parts that support the making of a program created by the C++ language programming, there are: 


  • Comment, is part of the  program code  which not executed  by the  compiler. Comments are  considered  importantly to  clarify the  program to be  more  easily understood  and  provide  information  on specific  parts of program code.  By commenting, our program can be read easily by other to be developed further. Usually without comment, people will be hard to understand the flow of the program code that been  made, therefore  the  comments are  needed in  order  to make our code  more informative.
  • Identifier, the  name  given by the  programmer (the  person who make the  program). Naming an identifier can be used in the program name, the name of the function, or other  objects that involved  in  the  programming  language, such as variable  names, constants which will be discussed further.
  • Keywords are  specific  words that contain  special meaning  contained  in  the  programming language. In C++ programming language, which called as keyword are asm,instance,  class, delete,  friend, inline,  new, operator, private,  protected, public, template, this, virtual, etc.. The words are  considered  as keywords according to the standard of a programming language should not be used as an identifier name.
  • Library of function, in contrast with the keyword, function library is a library that contains the functions provided by the C ++ language in the header files or the library. The functions are used to perform a particular tasks. Functions are grouped according to the type also characteristic and stored in a file with extension .h . For example,  a function cout which  is stored  in the library file iostream.h , used to print on the screen. Default functions of the C language, for example, printf from the stdio.h library can also be used in C++ if we write #include <stdio.h> at the beginning of the program.

Program structure

// my first program in C++
#include <iostream.h>
using namespace std;
int main () {
cout << "Hello World!";
/* It is also a comment line */
return 0;
}

Hello World!


  • // my first program in C++ , is a comment line that begins with two oblique sign (/ /) or are enclosed in / ** / and has no effect on the program. In this case, this comment line is used to describe a piece of code ever made.
  • #include <iostream.h> , preceded by a sharp mark (#) or, this line is a preprocessor line. In this case, #include <iostream> states to include iostream standar file. This particular file includes the declarations of the basic standard input­output library in C ++ language. Functions that commonly are used by beginner programmers of the iostream.h library include: cin, cout, system ("pause").
  • using namespace std;, this line tells the compiler that the program is written using standard C ++ library. Sometimes with the using namespace std; programmer does not need to write the (.h) on writing the standard C++ library.
  • int main () , this line is a main ()function. This line is at the core of the program that may include variables, assignment statements, or commands. This line consists of a series of source code that begins with the opening brace { and closing brace } and mark {} means showing where the main ()function begins and ends or the so­-called code blocks. So when a function is called, the content where enclosed by a block of code to be executed.
  • cout << "Hello World!"; this line is a statement of C++. A statement is a simple expression that can produce several effects. Cout represents the command of standard output in C++, cout is declared in the iostream standard file within the std namespace. So this line of code used to display the phrase "hello world".
    *Notice that the statement ends with a semicolon character (;). This character is used to mark the end of the statement and must be written at the end of all expression statements in all C ++ programs .
  • Return 0;, return instruction causes the main ()function terminated and returns the code that follows the instructions, in this case is 0. This is the most commonly used to end the program..


EmoticonEmoticon