Followers


INTRODUCTION C++ LANGUAGE

Posted by siSobri

Introduction

Programming language C + + based on C language so that C + + compiler can be used to compile programs written in C. Feature of C + + language is that it supports the programming language object or directional often known as the Object Oriented Programming (OOP).

Structure of C + + programs

Language C + + in general has a structure like the following program
List of header files
Declaration of global variables and additional functions
Head utamamain function
Definition utamamain function
Definition of additional functions (subroutine)
Subroutine can be written after the main function or in the file library (library). But when placed in the library, the library file must be included with the directive # include prepocessor placed on the list of header files.
Program examples turbo C + +? comments
# include? preprosesorheader file
main () (? main functions
court "ElektroUII technique";? definition of main function
return 0;
)

General rules of writing in C + +

1. Language C + + distinguishes the writing capital and lowercase letters.
2. To make comments on a statement (state), can be used at the beginning and at the end or in one line.
3. Beginning and end of the subroutine or function must be enclosed in curly braces.
4. Each statement must end in a semicolon.
5. Each variable that is used must be declared first.

Main function

Is a function of the core of the program and the beginning and end of execution. This function must exist in each program. Sign of open brace (is the main function of the early signs and sign closing brace) be an sign of the end of main function.

Prepocessor directive
Preprocessor directive is a statement which will diikiutsertakan in the program, which the statement will be compiled before the actual process conducted compilasi.

Basic commands C + +

 
court
Command is typically used to display an output on the screen
Example court "Lab. Computer Programming ";
court
Is a useful command to enter data, which in turn is defined as variable data.
example int age;
cin age;

Constant

Is a numerical value or character that remain unchanged. In C + + there are 4 class constants, ie
1. Integer constant, usually an integer, long integer (long int) and an unmarked integer (unsigned integer). Value can be decimal, octal or hexadecimal.
2. Floating point constants, can contain fractional values, which is usually written in the form of ordinary and fractional exponential form and is always expressed as a double, unless terminated by F or f (float constant state).
3. The constant string, a sequence of characters that begins and ends with double quotation marks ( "..."). Can also contain characters that use a character called escape (escape sequences).
4. Constant character, always begins and ends with single quotation marks ( '...'). Some character constants can be preceded by a sign (placing it after the single quotes).


Table escape character sets

      
Sequence Character Descriptions
      
a Bel Alert (bell sounds)
      
b BS Backspace (resigned 1 characters)
      
f Form feed FF (change pages)
      
LF n New line (new line switch)
      
r CR Carriage return (back to column 1)
      
t HT Horizontal Tab (horizontal tabulation)
      
v VT Vertical Tab (vertical tabulation)
        
Backslash
      
'' Single quotes
      
"" Double Cite
        
Question mark
      
Whatever DDD DDD is the digit octal value
      
Whatever hhh is xHHH digit hexadecimal value
      
Null ASCII character = 0

      
Is a value that can be expressed in the form of constants or variables and operators. The constant state of permanent value, while the variable declared yag value can change during the execution took place.

      
Simple data types are data types inherited from C + +, this data type consists of several types of data that is

      
o is an integral data type data type that consists of numbers with a range of different.
      
Integral Data Type Bytes Range Long Range
      
Char 1 -128 - 127 0 to 255
      
Short 2 -32,768 - 32,767 0 to 65,535
      
Int 2 -32,768 - 32,767 0 to 65,535

      
o Floating is the data type to decimal. For all the Turbo C + +, type floating-point format that uses IEEE-format floating-point used by the intel 8087. Type float using a real 32-bit format IEEE. Type double use real 64-bit format IEEE. Long double type uses real extended 80-bit format IEEE.
      
Integral Data Type Bytes Range
      
Float 4 3.4E-38 - 3.4E +38 (7 digits)
      
Double 4 1.7E-308 - 1.7E +308 (15 digits)
      
Long Double 8 1.7E-308 - 1.7E +308 (15 digits)

      
Address is a data type that is used to designate a memory address. While structured data type is a data type formation.

      
Here is an example of C + + programs

      
Example 1 the sum of a and b are the values for c
      
# include
      
main ()
      
(
      
int a, b, c;
      
a = 25;
      
b = 20;
      
c = a + b;
      
printf ( "% d", c);
      
)

      
Example 2 displays the input names
      
# include
      
main ()
      
(
      
char name [20];
      
printf ( "Enter Your Name"); printf ( "% s", name);
      
printf ( "Your Name nJadi% s", name);
      
)

      
Example 3 large calculation
      
# include
      
# define pi 3:14
      
void main ()
      
(
      
float area;
      
float jejari = 5;
      
area = 4jejarijejari;
      
printf ( "% nLuas is 5.2fn", area);
      
)

      
Example 4
      
# include
      
void main () program to calculate area of rectangle
      
(
      
float P;
      
int Size, L;
      
printf ( "Fill in the length value (p) ="); printf ( "% f", & P);
      
printf ( "Fill in the value of the width (l) ="); printf ( "% d", & L);
      
Size = PL;
      
printf ( "a rectangular area (L) =%-6dn", Size);
      
)

      
Example 5
      
# include
      
# include to enable clrscr () and getch ()
      
void main ()
      
(int p;
      
float area, L, A;
      
clrscr ();
      
printf ( "Fill in the data P ="); printf ( "% d", & P);
      
printf ( "Fill in the data L ="); printf ( "% f", & L);
      
A = 0.5;
      
Size = APL;
      
printf ( "Area of a Triangle =% 6.2fn", Size);
      
getch ();
      
)

      
Example 6
      
# include
      
# include
      
void main ()
      
(
      
char C;
      
int I;
      
long int LI;
      
double D;
      
float F;
      
long double LD;
      
clrscr ();
      
printf ( "t list data type size n");
      
printf ( "t The size of characters% d bytes n", sizeof (C));
      
printf ( "t integer size% d bytes n", sizeof (I));
      
printf ( "t long size integer n% d bytes", sizeof (LI));
      
printf ( "t double size n% d bytes", sizeof (D));
      
printf ( "t size float% d bytes n", sizeof (F));
      
printf ( "t long size double% d bytes n", sizeof (LD));
      
getch ();
      


Klik tombol like diatas... Jika anda menyukai artikel ini.
Terima Kasih telah mengunjungi Blog ini,
Jangan lupa untuk memberikan komentar, kritik maupun saran pada form dibawah post ini...

Share / Bagikan Artikel ini ke teman Anda :

{ 1 comments ... Tambahkan Komentar Anda }

Johan Computer said...

nice post, see also my post about Introduction C Language

Post a Comment

BERIKAN KOMENTAR DI SINI !!