hallo sobat... ada pelajaran lagi yang saya berikan untuk sobat. dan penjelasan nya terdapat dua bahasa yaitu bahasa indonesia dan English .. download saja di bawah:
semoga bermaanfaat untuk sobat semua:
FUNCTION in C++
The function is a block of program
code designed to perform specific tasks.
The function of many involved in the
creation of a program, with the aim of:
1.
The program became more tersetuktur,
making it easy to understand and easy to develop
Can reduce code duplication.
2.
A structured program. Large programs
can be broken down into
several smaller programs, each one
is a small program
has a specific task.
3.
Can reduce code duplication.
4.
The function can be called from another
program or function.
The general form of a function is as
follows:
Data
type the function name (parameter list)
{
/
* Function Body * /
return
value return; / * for the data type is not void * /
}
|
Functions of type void
Functions
of type void, if the pascal or delphi program called procedure. This function
has no return value, so the function of this type is just a bunch of code that
works in accordance with the given parameters.
function main
Is
a core function of the program and the beginning and end of the execution. This
function should be present in every program. {Open braces mark the first sign
and the sign function main braces} be an sign of the end of the main function.
First run, the computer will look
for Funsi Main () and execute the instructions in it.
Examples of functions of type void:
Shown void Name ()
{
Text color (RED);
cprintf ("My Name: Write name Ada \ n \ r");
cprintf ("Address: Jl. No. May Sabara. 641 \ n \ r");
cprintf ("Phone: 022-888-555 \ n \ r");
}
main ()
{
Shown name ();
Shown name ();
Shown name ();
}
|
In the above program, there is a
function called Appearing Name (), which is useful for displaying data Name,
Address, and Phone. In the main program (function main ()), how to call a
function is to write the name of the function (in this case Shown name ()). So
the above program will display the contents Shown function name () 3 times.
The above function is a function called without using
parameters. To see examples of parameterized functions, consider the program
below.
void box (int X1, int Y1, int X2, int Y2, int frame, int background)
{
int i;
textcolor (Frame);
textbackground (Background);
gotoxy (X1, Y1); cprintf ("é") / * alt +218 * /
gotoxy (X1, Y2); cprintf ("% c", 192);
gotoxy (X2, Y1); cprintf ("% c", 191);
gotoxy (X2, Y2); cprintf ("% c", 217);
for (i = X1 +1; i <= X2-1; i + +)
{
gotoxy (i, Y1); cprintf ("% c", 196);
gotoxy (i, Y2); cprintf ("% c", 196);
}
for (i = Y1 +1; i <= Y2-1; i + +)
{
gotoxy (X1, i); cprintf ("% c", 179);
gotoxy (X2, i); cprintf ("% c", 179);
}
}
main ()
{
Box (1,1,80,24, WHITE, BLUE);/ / Calling Procedure Box
Box (2,2,15,23, WHITE, RED);
getch ();
return 0;
}
|
Void Box is a function that will
create a box on the screen according to the coordinates given in the parameter.
These coordinates are the top left coordinates (X1, Y1), and the coordinates of
the lower right (X2, Y2). Besides this function requires a parameter that is
useful for determining frame box frame color, as well as a useful parameter for
determining background color background made box.
Dialling Box (1,1,80,24, WHITE, BLUE) allows you to create a
box with upper left position on the coordinate (1,1) and bottom right position
at coordinates (80.24) with the color white box frame with background blue box.
Function data type
In the world of mathematics, we
know the function. Example: F (X) = X2 +3 X +5, which means we have a function
named F which takes the parameter X as the data to be calculated by the
equation X2 +3 X +5 so if we write F (5), then the value of the function was 52
+ 3.5 + 5 = 45.
The general form of this function in the Pascal language is:
Type Data Name
Function (parameter list)
{
commands;
commands;
The Return Value To
Function;
}
Example 1: Function to
calculate mathematical equations F (X) = X2 +3 X +5;
float F (float X)
{
return X * X * X +5 +3;/ /
Function filled result of the calculation of X2 +3 * X +5
}
|
Example 2: Function to
find the factorial of a value
float factorial (int N)
{
int I;
float result;
Result: = 1;
for (i = 2; I <= N; I + +)
Result = Result * I;
return result;
}
|
Example 3: The
function to look for combination with the formula:
The combination of (X,
Y) =
Float Combination (int X, int
Y)
{
return factorial (Y) /
(factorial (X) * Factorial (YX));
}
|
Contoh sebuah program
yang terdiri dari satu main program dan satu subprogram (fungsi).
Sample source code
available
/ / PROGRAM AREA AND
VOLUME
# include
<stdio.h>
# include
<conio.h>
/ / function area of
a rectangle
int arithmetic_broad
(int p, int l) {
int ls;
ls = p * l;
return ls;
}
/ / function block's
volume
arithmetic _volume int
(int p, int l, int t) {
int vol;
vol = p * l * t;
return vol;
}
/ / main program
main () {
int length, width,
height, area, volume;
printf ("PROGRAM
AREA AND VOLUME \ n");
printf ("Enter
the length:"); scanf ("% d", & length);
printf ("Enter
the width:"); scanf ("% d", & width);
printf ("Enter
the height:"); scanf ("% d", & height);
area = arithmetic _
broad (length, width);
arithmetic _volume
volume = (length, width, height);
printf ("Area of
square is:% d \ n", area);
printf ("The
volume of the block is:% d \ n", volume);
getch ();
}
jika anda ingin mempunyai tutorial yang lebih lengkap download aja di bawa ini:
Free Download Tutorial bahasa indonesia Klik disini
Free Download Tutorial bahasa inggris Klik disini
Free Download Tutorial bahasa inggris Klik disini
Tidak ada komentar:
Posting Komentar