Selasa, 24 September 2013

1.1 History of C + +



INTRODUCTION C + +
Chapter 1
Language C + + was created by Bjarne Stroustrup at AT & T Bell
Laboratories early 1980s by C ANSI ( American National
Standard Institute ) . The first time , a prototype C + + C emerged as the
enhanced by class facilities . The language is called C with classes
( C wih class ) . During the years 1983-1984 , with a class C enhanced
by adding pembebanlebihan facility operators and functions
then gave birth to what is called C + + . + + Is an operator symbol
C for raising operation , appear to indicate that this new language
a more advanced version of C.
Borland International released a compiler Borland C + + and Turbo C + + .
Both are equally compiler can be used to compile code
C + + . The difference, Borland C + + can be used under the environment than
DOS , also can be used for Windows programming .
In addition to Borland International , several other companies have also released
C + + compiler , such Topspeed Zortech C + + and C + + .

Example C Program :


# Include <stdio.h>
Main ( )
{
Char message [ ] = "Hi , C programmers ! " ;
Printf ( message ) ;
Return 0 ;
}

Example C + + program :


# Include <iostream>
Main ( )
{
Char message [ ] = "Hi , C programmers ! " ;
Cout << message ;
Return 0 ;
}


ABOUT C + + 1.2

C + + was created to support -oriented programming
object ( Object Oriented Pragramming / OOP ) that are not owned by C. while C
their environment is the best programming language , this language does not
T. Structured Programming 2 ( 1 ) Page 1 of 6

have OOP capabilities . Reputation C is undoubtedly in
generating program . EXE small , fast execution ,
interface ( interfacing ) is simple with other languages ​​and flexibility
programming . What makes C may seem difficult to learn because
absence of type checking . For example , can mix integers
the string to produce a character . However , it lies dsitu
flexibility of C , C can process data as freely process the data in the language
assembly .


BORLAND C + + 1.3


Compared to C + + compiler to another , Borland C + + has
advantages , especially in terms of speed and efficiency compilation . Besides
that , Borland C + + supports multiple operating systems , namely DOS , Windows
16bit ( Window 3.0 ) and Windows 32 bit ( Windows NT ) . nevertheless
Borland C + + compiler also has disadvantages when compared to compiler
Another C + + , for example : programming with Borland C + + primarily
regarding the view is much more difficult than programming with
Microsoft Visual C + + .


1.4 STRUCTURE OF LANGUAGE C + +


Program C and C + + are always composed of four (4 ) main sections , namely :
1 . The comments section is marked with the symbol / / and a partner / * ... * /
2 . Compiler steering parts marked by the symbol #
3 . declaration section
4 . part of the definition


COMMENTS SECTION 1.4.1


Good programs are generally given comments that will help
one another, and the program makers to understand the program
made . In C or C + + any writing flanked by symbols / * ... * / or
every line that begins with the symbol / / is considered a comment . C + + is not
allow nested comments ( nested comment) , but Borland C + +
more flexible in this regard .

Example C + + using the comment :


/ * FIRST.CPP * /
/ * Program C + + first * /
/ / Preprocessing
# Include <iostream>
Void main ( )
{
Char message [ ] = " Hello , C + + programmers ! " ;

T. Structured Programming 2 ( 1 ) Page 2 of 6

Cout << message ;
Return 0 ;
}

On Borland C + + can use nested comments option as long as the check
N
ested comments on the menu Options / Compiler / Source selected .


DIRECTOR SECTION 1.4.2 compiler


Example C + + program :


# Include <iostream>
Void main ( )
{
Char message [ ] = " Hello , C + + programmers ! " ;
Cout << message ;
Return 0 ;
}

Praprosesor a statement , referring also called compiler because
controls the compilation process .
Iostream.h is a program file that contains the declaration of classes of
which
be required
by
object
cout .
Files
with
extension
. H
which
contain

declaration
functions
standard
C is ,
called
in
general
as
file

header .

some
steering
compiler
is
:




1 . # define
2 . # include
3 . # If , # else , # elif , # endif
4 . # Ifdef , # ifndef
DIRECTOR 1.4.2.1 Compiler # DEFINE


To define an identifier / constants which will be
replaced by praprosesor when the program is compiled .

Example Program :


# Define SIZE 30
Int array [ SIZE ] ;
For ( register int i = 0 ; i < SIZE ; i + + )
{
Cout << array [ i ] ;
}



T. Structured Programming 2 ( 1 ) Page 3 of 6

1.4.2.2 DIRECTOR # INCLUDE compiler

Function to read specific program file and include that file
in the compilation process . The file name must be enclosed symbol is ' < '
and ' > ' or double quotation marks ( " ... " ) .


1.4.2.3 STEERING compiler # IF , # ELSE , # elif , # ENDIF


Used to select the parts of the program will be compiled . compilation
This search is called conditional compilation and a good program usually
utilizing this technique .


1.4.2.4 STEERING compiler # ifdef , # ifndef


Used also in conditional compilation . # Ifdef can be read : ' if
defined ' and # ifndef can be read : ' if not defined ' .
Steering compiler is often used to indicate that a file
already included in the compilation


1.4.3 THE DECLARATION AND DEFINITIONS


All C programs are basically composed of a series
function calls are working on a bunch of data . In addition to calling
function , C programs contain other components called statement .
Statement C was twofold : the statement can not be executed / non
executable ( when compiled does not generate object code and usually
used to regulate the flow of the program ) , and a statement that can be
executed / executable ( when compiled to produce object code ) .
Each function call or executable statement in C must
terminated with a semicolon ( ; ) .

Example C + + program :


# Include <iostream>
Void main ( )
{
Char message [ ] = " Hello , C + + programmers ! " ;
Cout << message ;
Return 0 ;
}

In C + + program example above , an example of Return
executable statement that instructs a function
returns the specified return value . Examples of non- executable statement is :
If, else , and while .

T. Structured Programming 2 ( 1 ) Page 4 of 6

Main ( ) is an example of the function , while the message is an example
data. Both data and functions must be declared . Data need to be
declared so that the compiler knows how many bytes of memory that must be provided
for the data in question , while the functions need to be declared in order
the compiler can check the accuracy of the relevant function calls .
Often called the function declaration function prototype .


1.5 INPUT AND OUTPUT


In ANSI C , input and output operations performed using
functions in the header file stdio.h . example for input and
output layer to monitor use commands like printf , scanf , putch , etc. .
For input and output to a file use the command like fread , fwrite , fputc ,
etc. .
C + + engineering has a new input and output , namely :
using streams. Header file for input and output stream is
iostream.h and some other files , such as strstrea.h , fstream.h , and
constrea.h .
Stream is a logic device ( hardware logic ) that
produce and receive information or a container that is used
to accommodate and hold output data stream . Stream is
common name to accommodate the flow of data ( eg files , keyboard , mouse ) ,
and for output ( example : layer , printer ) .
In C + + input means reading from the stream and output means
write to the stream .

General Output operator form :


Cout << expression ;

Input common form of operator :


Cin >> variable ;

In C + + , using the escape sequences for
represents a character that is not contained in the traditional
symbol . Some of them are :

\ N : linefeed / new line
\ B : back space
\ " : Double quotation








T. Structured Programming 2 ( 1 ) Page 5 of 6

Examples of ANSI C version of the program :

# Include <stdio.h>
Void main ( )
{
Int x ;
Printf ( " Enter a number : \ n " ) ;
Scanf ( " % d " , & x ) ;
Printf ( " Numbers are entered is % d \ n " , x ) ;
}

Example C + + version of the program :


# Include <iostream>
Void main ( )
{
Int x ;
Cout << " Enter a number : " << endl ;
Cin >> x ;
cout << " Numbers are entered is " << x << endl ;
}


Example Program for input and output :


# Include <iostream>
Main ( )
{
Int a;
Cout << " enter a number : " ;
Cin >> a;
Cout << " The value of plus 1 = " << a +1 ;
Return 0 ;
}

Tidak ada komentar:

Posting Komentar