Breaking News

Laman

Selasa, 03 April 2012

Modul VII Function

This program is a simple example of application of functions in C + +, I hope this program can be beneficial.
The first program.
#include <iostream.h>

#include <conio.h>
//deklarasi fungsi

input(float, float);

gajipokok(float, float);


bonus(float, float);

gajibersih(float, float);
//penggunaan fungsi

void main()

{

float gp, bon;

cout<<"===========================================\n";

cout<<"=  Masukkan Gaji Bersih :"; cin>>gp;

cout<<"=  Masukkan Persentase Bonus :"; cin>>bon;

cout<<"===========================================\n";

cout<<"===========================================\n";

cout<<"=  Slib Gaji Bulanan Pekerja.             =\n";

cout<<"===========================================\n";

cout<<input(gp, bon);
getch();

}

input(float c, float v)

{

gajipokok(c,v);

cout<<"============================================\n";

cout<<"\n= Tunjanggan profesi yang didapat : Rp. 50000.";

cout<<"\n= Gaji Pokok Pekerja : Rp."<<gajipokok(c,v);

bonus(c,v);

cout<<"\n= Bonus Bulan ini : Rp."<<bonus(c,v);

gajibersih(c,v);

cout<<"\n= Gaji yang diterima pekerja : Rp."<<gajibersih(c,v);

cout<<"\n===========================================\n";
getch();

return 0;

}

gajipokok(float g, float b)

{

float gaj;

gaj = g + 50000;
return gaj;

}

bonus(float ga, float bo)

{

float bonus;

bonus = (bo/100)*(ga+50000);
return bonus;

}

gajibersih(float gaji, float bo)

{

float totalgj;

totalgj= (bo/100 * (gaji+50000))+ gaji + 50000;
return totalgj;

}
The second program.
#include <conio.h>

#include <iostream.h>

#include <stdlib.h>
//deklarasi Fungsi

fungsi(char , int , int );
//penggunaan Fungsi

void main()

{

int b1, b2;

char men;

do{

clrscr();

cout<<"==================================\n";

cout<<"=              Menu              =\n";

cout<<"==================================\n";

cout<<"=  1. Oprasi Penjumlahan.        =\n";

cout<<"=  2. Oprasi Penguranggan.       =\n";

cout<<"=  3. Oprasi Perkalian.          =\n";

cout<<"=  4. Oprasi Pembagian.          =\n";

cout<<"=  X/x. Keluar                   =\n";

cout<<"==================================\n";

cout<<"Masukkan Pilihn Anda :"; cin>>men;

cout<<"\n==================================\n";

if(men=='1' || men=='2' || men=='3' || men=='4')

{

cout<<"==================================\n";

cout<<"Masukkan Bilanggan Pertama :"; cin>>b1;

cout<<"\nMasukkan Bilanggan Kedua :"; cin>>b2;

cout<<"==================================\n";

}

cout<<fungsi(men,b1,b2);

getch();

}

while(men=='1' || men=='2' || men=='3' || men=='4');

}
fungsi(char a, int b1, int b2)

{

int tam, kur, kal, bag;

if(a=='1')

{

tam=b1+b2;

cout<<"Hasil penjumlahaannya adalah :";

return tam;

}

else if (a=='2')

{

kur=b1-b2;

cout<<"Hasil penggurangannya adalah :";

return kur;

}

else if (a=='3')

{

kal=b1*b2;

cout<<"Hasil perkaliannya adalah :";

return kal;

}

else if (a=='4')

{

bag=b1/b2;

cout<<"Hasil penggurangannya adalah :";

return bag;

}

else if (a=='x' || a=='X')

{

cout<<"Trima kasih";

}

else

{

cout<<"Maaf Kode tidak Sesuai";

}

return 0;

}

Tidak ada komentar:

Designed By