PERTEMUAN 11 FUNGSI ( FUNCTION )
By Aldhen FY - May 04, 2018
Fungsi ( Function )
Tugas 11 Membuat Program Fungsi ( Function )
Tugas 1
#include<conio.h>
#include<iostream>
#include<stdio.h>
using namespace std;
garis1(){
cout<<"========================================"<<endl;}
garis2(){
cout<<"-------------------------------------------"<<endl;
}
enter(){
cout<<endl;
}
potong(float price, float discount){
return(price*discount);
}
int main()
{
float x,
y, z;
enter();
garis2();
cout<<" PROGRAM MENGHITUNG DISKON 'ALDHEN TRAVEL'
"<<endl;
garis2();
cout<<" Harga Barang Rp ";cin>> x;
enter();
potong(x,y);
if
(x>5000000)
{
y =
x * 0.35;
}
else if (x >= 1000000)
{
y = x * 0.2;
}
if (x <1000000)
{
y = 0;
}
printf(" Diskon yang diberikan sebesar Rp %1.0f ",y);
enter();
z = x - y;
printf(" Total yang harus dibayar Rp %1.0f ",z);
enter();
garis2();
getch();
}
|
Tugas 2
#include<conio.h>
#include<iostream>
#include<stdio.h>
using namespace std;
garis()
{
cout<<"========================================"<<endl;
}
garis2()
{
cout<<"
------------------------------------------------------------------------"<<endl;
}
space()
{
cout<<endl<<endl;
}
main()
{
int tb, bp, total;
int
tarif_sewa;
int tp(int
tarif_buku, int banyak_pinjam);
string nama,
kb, jb;
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();
garis();
cout<<" PERPUSTAKAAN ALDHEN TRAVEL "<<endl;
garis();
cout<<" Nama Penyewa Buku : ";cin>>nama;
cout<<" Kode Buku : ";cin>>kb;
cout<<" Banyak Pinjam : ";cin>>bp;
garis();
space();
if
(kb=="c" || kb=="C")
{
jb="CerPen (Kumpulan Cerita
Pendek)";
tb=500;
}
else if
(kb=="k" || kb=="K")
{
jb="Komik";
tb=700;
}
else if
(kb=="n" || kb=="N")
{
jb="Novel";
tb=1000;
}
cout<<" TRANSAKSI
"<<endl;
garis();
cout<<" Tarif Sewa Rp
"<< tb <<endl;
cout<<" Jenis Buku : "<< jb<<endl;
cout<<" Penyewa dengan Nama : "<<nama<<endl;
total = tp(tb,bp);
cout<<" Jumlah Bayar Penyewaan
Sebesar Rp "<<total<<endl;
getch();
}
tp(int
tarif_buku, int banyak_pinjam)
{
return
(tarif_buku*banyak_pinjam);
}
|
0 comments