Ads 468x60px

Pages

Selasa, 08 Oktober 2013

Penggunaan FUNCTION dalam C++

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void lingkaran ();
void segitiga ();
void segi_empat ();
void segitiga_2();

void main()

{
int pil;
cout<<"==================================================\n";
cout<<"|  Program untuk menghitung LUAS dan KELILING BANGUN DATAR   |\n";
cout<<"==================================================\n";
cout<<"     Pilihan :\n";
cout<<"\n";
cout<<" 1 Untuk Menghitung Luas LINGKARAN\n";
cout<<"\n";
cout<<" 2 1 Untuk Menghitung Luas SEGITIGA SAMA SISI\n";
cout<<"\n";
cout<<"   2 Untuk Menghitung Luas SEGITIGA SAMA KAKI\n";
cout<<"\n";
cout<<" 3 Untuk Menghitung Luas SEGI EMPAT\n";
cout<<"\n";
cout<<"Masukan Pilihan Anda : ";
cin>>pil;
cout<<"\n";
cout<<"\n";
if(pil==1){lingkaran();}
if(pil==21){segitiga();}
if(pil==22) {segitiga_2();}
if(pil==3){segi_empat();}
}

void lingkaran()
{
 clrscr;
float jari ,keliling ,luas;
const float pi= 3.14;


cout<<"================================================\n";
cout<<"|  Program untuk menghitung LUAS dan KELILING LINGKARAN      |\n";
cout<<"================================================\n";
cout<<"\n";
cout<<"  Masukan panjang jari_jari(r) : ";cin>>jari;
luas = pi * jari * jari;
keliling = 2 * pi * jari;
cout<<"\n";
cout<<"\n";
cout<<"===================================================\n";
cout<<"  Luas lingkaran adalah     : "<<luas <<"\n";
cout<<"  Keliling lingkaran adalah : "<<keliling <<"\n";
cout<<"===================================================\n";
cout<<"\n";
cout<<"\n";
cout<<"  Tekan ENTER untuk KELUAR";
getch ();
}
void segitiga()
{
 clrscr;
float a, t, sisi, luas ,keliling;


cout<<"=====================================================\n";
cout<<"|  Program untuk menghitung LUAS dan KELILING SEGITIGA SAMA SISI |\n";
cout<<"=====================================================\n";
cout<<"\n";
cout<<"  Masukan panjang alas   : ";cin>>a;
cout<<"  Masukan panjang tinggi : ";cin>>t;
luas = (0.5 *a)*t;
keliling = a+a+a;
cout<<"\n ";
cout<<"\n ";
cout<<"\n ";
cout<<"\n";
cout<<"============================================================\n";
cout<<"  Hasil perhitungan        \n" ;
cout<<"\n";
cout<<"  Keliling Segitiga adalah : "<<keliling <<"\n";
cout<<"  Luas Segitiga adalah     : "<<luas <<"\n";
cout<<"============================================================\n";
cout<<"\n";
cout<<"\n";
cout<<"  Tekan ENTER untuk KELUAR";
getch ();
}
void segitiga_2()
{
 clrscr;
float pk, a, t,luas ,keliling;


cout<<"=======================================================\n";
cout<<"|  Program untuk menghitung LUAS dan KELILING SEGITIGA SAMA KAKI |\n";
cout<<"=======================================================\n";
cout<<"\n";
cout<<"  Masukan panjang panjang kaki: ";cin>>pk;
cout<<"  Masukan panjang tinggi      : ";cin>>t;
cout<<"  Masukan panjang alas        : ";cin>>a;
luas = (0.5*a)*t;
keliling = (2*pk)+a;
cout<<"\n ";
cout<<"\n ";
cout<<"\n ";
cout<<"\n";
cout<<"========================================================\n";
cout<<"  Hasil perhitungan        \n" ;
cout<<"\n";
cout<<"  Keliling Segitiga adalah : "<<keliling <<"\n";
cout<<"  Luas Segitiga adalah     : "<<luas <<"\n";
cout<<"=======================================================\n";
cout<<"\n";
cout<<"\n";
cout<<"  Tekan ENTER untuk KELUAR";
getch ();
}
void segi_empat()
{
 clrscr;
float pjg ,lbr ,luas ,keliling;


cout<<"======================================================\n";
cout<<"| Program untuk menghitung LUAS dan KELILING SEGI EMPAT    |\n";
cout<<"======================================================\n";
cout<<"\n";
cout<<"  Masukan panjang panjang : ";cin>>pjg;
cout<<"  Masukan panjang lebar   : ";cin>>lbr;
luas = pjg * lbr;
keliling = 2 * (pjg+lbr);
cout<<"\n ";
cout<<"\n ";
cout<<"\n ";
cout<<"\n";
cout<<"=====================================================\n";
cout<<"  Hasil perhitungan        \n" ;
cout<<"\n";
cout<<"  Keliling Segi Empat adalah : "<<keliling <<"\n";
cout<<"  Luas Segi Empat adalah     : "<<luas <<"\n";
cout<<"======================================================\n";
cout<<"\n";
cout<<"\n";
cout<<"  Tekan ENTER untuk KELUAR";
getch ();
}


Hasilnya :





0 komentar:

Posting Komentar