Fungsi (function)
PERTEMUAN 11: FUNGSI (FUNCTION)
Latihan :
#include<conio.h>
#include<iostream>
#include<stdio.h>
using namespace std;
garis1(){
cout<<"========================================"<<endl;}
garis2(){
cout<<"-------------------------------------------"<<endl;
}
space(){
cout<<endl;
}
potong(float price, float discount){
return(price*discount);
}
int main()
{
float
p, d, t;
//int
t; for total bayar no printf %1.0f
/*
INPUT */
space();
garis2();
cout<<" PROGRAM MENGHITUNG DISKON \"LEMBURAN BU\"
"<<endl;
garis2();
cout<<" Harga Barang Rp ";cin>> p;
space();
/* DISCOUNT */
potong(p,d);
/* IF - ELSE DISCOUNT */
if (p <= 1000000)
{
d = 0;
}
else if (p >= 1000000)
{
d = p * 0.2;
}
if (p > 5000000)
{
d = p * 0.35;
}
//cout<<" Diskon yang diberikan sebesar Rp "<< d
<<endl;
printf(" Diskon yang diberikan sebesar Rp %1.0f ",d);
space();
/* TOTAL BAYAR = PRICE - DISCOUNT */
t = p - d;
//cout<<" Total yang harus dibayar Rp "<< t <<endl;
printf(" Total yang harus dibayar Rp %1.0f ",t);
space();
garis2();
getch();
}//END MAINT UTAMA
|
Hasil Outputnya:
Latihan 2:
#include<conio.h>
#include<iostream>
#include<stdio.h>
using namespace std;
garis1()
{
cout<<"========================================"<<endl;
}
garis2()
{
cout<<"
------------------------------------------------------------------------"<<endl;
}
space()
{
cout<<endl<<endl;
}
main()
{
int tb, bp, total;
int tarif_sewa;
int tarif_penyewaan(int tarif_buku, int
banyak_pinjam);
string name, kode_buku, jenis_buku;
int A, B;
garis2(); ////
cout<<" | Kode Buku | Jenis Buku
| Tarif Buku | "<<endl;
garis2(); ////
cout<<" | C | Cerpen (Kumpulan
Cerita Pendek) | 500 | "<<endl;
cout<<" | K | Komik | 700 |
"<<endl;
cout<<" | N | Novel | 1000 |
"<<endl;
garis2();
space();
garis1();
cout<<" PERPUSTAKAAN KECIL-KECILAN
"<<endl;
garis1();
cout<<" Nama Penyewa Buku :
";cin>>name;
cout<<" Kode Buku :
";cin>>kode_buku;
cout<<" Banyak Pinjam :
";cin>>bp;
garis1();
space();
if (kode_buku=="c" ||
kode_buku=="C")
{
jenis_buku="CerPen (Kumpulan Cerita
Pendek)";
tb=500;
}
else if (kode_buku=="k" ||
kode_buku=="K")
{
jenis_buku="Komik";
tb=700;
}
else if (kode_buku=="n" ||
kode_buku=="N")
{
jenis_buku="Novel";
tb=1000;
}
cout<<" TRANSAKSI
"<<endl;
garis1();
cout<<" Tarif Sewa Rp
"<< tb <<endl;
cout<<" Jenis Buku :
"<< jenis_buku<<endl;
cout<<" Penyewa dengan Nama
"<<name<<endl;
total = tarif_penyewaan(tb,bp);
cout<<" Jumlah Bayar Penyewaan
Sebesar Rp "<<total<<endl;
getch();
}
tarif_penyewaan(int tarif_buku, int
banyak_pinjam)
{
return (tarif_buku*banyak_pinjam);
}
|
Hasil Outpunya:
Komentar
Posting Komentar