MATERI-MATERI MATA KULIAH SISTEM INFORMASI STMIK MDP

Pasang Iklan Gratis Disini !!!

ads ads ads ads

Sabtu, 27 November 2010

ha...ha..ha... Latihan Deklarasi Fungsi

. Sabtu, 27 November 2010

cin = masukan
cout = keluaran
void main = void; kosong, main; utama.
fungsi cpp : bsa dipakai program lain
void = tidak dipakai oleh program lain,
() = kosong, kalo dipake oleh program lain, maka di isi.

cout<< " # \n"
system ("pause")
}

Contoh_1 :
#include "iostream"
using namespace std;
void garis() { //deklarasi fungsi dengan nama garis
cout<<"---------------------\n";
}
void main () {
int i=0;
garis ();
cout<<"##### WELCOME TO MY CLASS #####\n";
garis();
for (i=1;i<=10;i++){
    cout<<i*2-1<<endl;
}
system ("pause");
}

Contoh_2:
#include "iostream"
using namespace std;
void ganjil() { //deklarasi fungsi
    int i=0;
cout<<"10 BILANGAN GANJIL PERTAMA   \n";
for (i=1;i<=10;i++){
    cout<<"           "<<i*2-1<<"       "<<endl;
    cout<<"-----------------------"<<endl;
}

cout<<"---------------------\n";
}
void genap() { //deklarasi fungsi
    int i=0;
    cout<<"10 BILANGAN GENAP PERTAMA   \n";
for (i=1;i<=10;i++){
    cout<<"           "<<i*2<<"       "<<endl;
    cout<<"-----------------------"<<endl;
}
}

void main () {
cout<<"##### WELCOME TO MY CLASS #####\n";
ganjil();
genap();

system ("pause");
}

Contoh_3:
#include "iostream"
#include "iomanip"
using namespace std;
void garis (){ //deklarasi fungsi dengan nama garis
    cout<<"---------------------------------\n";
}

void ganjil() { //deklarasi fungsi
cout<<"10 BILANGAN GANJIL PERTAMA   \n";
for (int i=1;i<=10;i++){
    cout<<setw(20)<<i*2-1<<endl;
    garis();
}
}
void genap() { //deklarasi fungsi
    cout<<"10 BILANGAN GENAP PERTAMA   \n";
for (int i=1;i<=10;i++){
        cout<<setw(20)<<i*2<<endl;
    garis();
}
}

void main () {
int pilihan, maka ;
awal:
cout<<"##### WELCOME TO MY CLASS #####\n";
cout<<" 1. GENAP\n";
cout<<" 2. GANJIL\n";
cout<<" 3. EXIT\n";
cout<<" Masukkan pilihan (1/2/3) : ";cin>>pilihan;
if (pilihan==1){
ganjil();
    goto awal;}
else if (pilihan==2){
genap();
goto awal;}
else if (pilihan==3){
    exit;}
else{
cout<< "SALAH INPUT PILIHAN !!!\n";
goto awal;}

system ("pause");
}

SEMOGA BERMANFAAT

1 komentar:

Let's Share Together mengatakan...

jadi inget jaman kuliah dulu :D

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Posting Komentar

Tuliskan Komentar Disini..

Related Posts Plugin for WordPress, Blogger...
 
{Sistem Informasi} is proudly powered by Blogger.com | Template by : Sukriyadi | sukriyadi.blogspot.com