Saturday, February 14, 2009

PEMROGRAMAN BERORIENTASI OBYEK

Contoh program mencari bilangan prima :

#include
#include
int bilangan_prima(int nilai);
main()
{
int angka;
int i;
cout <<"\n\tPROGRAM PENGHITUNG BILANGAN\n"; cout << "==========================================\n"; cout <<"\nMasukkan batas angka yang anda inginkan: ";cin>>angka;
for(i=1;i<=angka;i++) { cout<<< "\t: Bilangan "; if(i % 2 == 0) cout << "genap "; else cout <<"ganjil "; if(i!=0 && i!=1) { if(bilangan_prima(i)==1) cout <<"prima"; } cout <<"\n"; } getch(); return 0; } int bilangan_prima(int nilai) { int i; for(i=2;iPerulangan input data :

#include
#include

main() {
cout<<"Apakah ada dt barang yang akan diinput(Y/T)? "; char jwb; cin>>jwb;
char nama[15];
int jml,n=0;
double harga,stotal,totalb=0;

while ((jwb=='y')||(jwb=='Y'))
{ cout<<"\n\nData Barangnya : \n"; cout<<"Nama Barang = ";cin>>nama;
cout<<"Jumlah Barang = ";cin>>jml;
cout<<"Harga Satuan = ";cin>>harga;
stotal=jml*harga;
cout<<"Subtotal = "<<<" Ada lagi (y/t)? ";cin>>jwb;
}
cout<<"\n\nTotal bayar = "<<<"\nItem barang = "<Program mencari bilangan ganjil :

#include
#include

main() {
int n,jml=0;
cout<<"Batas = ";cin>>n;
for(int i=1;i<=n;i=i+1) if (i%2!=0) { jml+=i; cout<<<"\n"; } cout<<"\n\nJumlah = "<Program menghitung gaji karyawan :

#include
#include
#include

main() {
char nama[20];
double gpokok,potongan;
int anak;
cout<<"Nama karyawan = ";cin>>nama;
cout<<"Gaji pokok = ";cin>>gpokok;
cout<<"Potongan = ";cin>>potongan;
cout<<"Jumlah anak = ";cin>>anak;
double tunjangan;
if (anak<=3) tunjangan=anak*0.05*gpokok; else tunjangan=3*0.05*gpokok; cout<<"\nTunjangan anak = "<<<"\nGaji total sebelum pajak = "<<=3000000)
pajak=0.1*gaji;
else if (gaji>=2000000)
pajak=0.05*gaji;
else
pajak=0;
cout<<"\nBesarnya pajak = "<<<"\nGaji total setelah pajak = "<<Mencari luas persegi panjang :

#include
#include

int cari_luas(int p, int l)
{ int ls;
ls=p*l;
return ls;
}

main() {
int hasil,x,y;
//x=12;
//y=8;
cout<<"Masukkan panjang = ";cin>>x;
cout<<"Masukkan lebar = ";cin>>y;
hasil=cari_luas(x,y);
cout<<"\nLuas persegi panjang = "<
getch();
}

0 comments:

Post a Comment

Please leave your message here..