Kamis, 22 November 2012

Materi Fungsi-Fungsi Dalam Bahasa C++




The function is a block of program code designed to perform specific tasks.


Function (Function)
Execution of a program starting from the function main ()

-Programs are usually designed in several sub-programs
called function (function)
-When the program is executed and met with
statement to call a function of the execution
program will switch to that function. after the function
completed its execution, the statement continued right on
section where the function was invoked 

example

#include <iostream>
using namespace std;
void echo(const string str){
cout << str << endl;
}
int main(){
string kata;
cout << "Ketik sebuah kata: ";
cin >> kata;
echo(kata);




  • -Function: return Statement
When a return statement is executed, the execution of a
function will stop and the value will be returned to the
position where the function is called

int maximum (int x, int y) {
if (x> y) return x;
else return y;
} Called-by-value
or
int maximum (int x, int y) {
return ((x> y)? x: y);
}



Function: Called-by-Value

# include <iostream>
using namespace std;
cumulative int (int n) {
int sum = 0;
for (; n> 0; - n)
sum + = n;
return sum;
}
int main () {
int n = 3, sum;
cout << n << endl;
cumulative sum = (n);
cout << n << ":" << sum << endl;
}


Recursive functions:
Recursive functions (recursive function) calls itself
itself in the body of the. Recursive function always has
termination section to stop the recursive process.
long factorial (int n) {
if (n <= 1)
return;
else
return n * factorial (n - 1);

Recursive Functions: Advanced
void countdown (unsigned int n) {
if (n <= 0)
cout << "BLAST OFF" << endl;
else {
cout << "COUNT:" << n << endl;
countdown (n - 1);
}
}




INDONESIAN VERSION
Fungsi merupakan blok dari kode program yang dirancang untuk melaksanakan tugas khusus.

Fungsi (Function):

Eksekusi sebuah program dimulai dari fungsi main()
-Program biasanya dirancang dalam beberapa sub program
yang disebut fungsi (function)
-Ketika program dieksekusi dan bertemu dengan
pernyataan memanggil sebuah fungsi maka eksekusi
program akan beralih ke fungsi tersebut. Setelah fungsi
selesai dieksekusi, pernyataan dilanjutkan tepat pada
bagian dimana fungsi itu dipanggil

Contoh
#include <iostream>
using namespace std;
void echo(const string str){
cout << str << endl;
}
int main(){
string kata;
cout << "Ketik sebuah kata: ";
cin >> kata;
echo(kata);

Fungsi: Pernyataan return

- Ketika pernyataan return dieksekusi, eksekusi sebuah
fungsi akan berhenti dan nilai akan dikembalikan ke
posisi dimana fungsi tersebut dipanggil

int maximum(int x, int y){
if (x > y) return x;
else return y;
} called-by-value
atau
int maximum(int x, int y){
return ((x > y)? x : y);
}

Fungsi: Called-by-Value

#include <iostream>
using namespace std;
int komulatif(int n){
int sum = 0;
for ( ; n > 0; --n)
sum += n;
return sum;
}
int main(){
int n = 3, sum;
cout << n << endl;
sum = komulatif(n);
cout << n << " : " << sum << endl;
}


Fungsi Rekursif

Fungsi rekursif (recursive function) memanggil dirinya
sendiri dalam bagian body. Fungsi rekursif selalu memiliki
bagian terminasi untuk menghentikan proses rekursif.
long factorial(int n){
if (n <= 1)
return;
else
return n * factorial(n - 1);


}


Fungsi Rekursif: Lanjutan
void countdown(unsigned int n){
if (n <= 0)
cout << "BLAST OFF" << endl;
else {
cout << "COUNT: " << n << endl;
countdown(n - 1);
}
}














1 komentar:

  1. Materi Fungsi-Fungsi Dalam Bahasa C++ ~ Sharing Informasi Bersama >>>>> Download Now

    >>>>> Download Full

    Materi Fungsi-Fungsi Dalam Bahasa C++ ~ Sharing Informasi Bersama >>>>> Download LINK

    >>>>> Download Now

    Materi Fungsi-Fungsi Dalam Bahasa C++ ~ Sharing Informasi Bersama >>>>> Download Full

    >>>>> Download LINK P8

    BalasHapus