#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
// 1. Function NOT Return Value (Without Parameter)
void buatGaris() {
puts("-------------------------------------------------------------");
}
// 2. Function NOT Return Value (With Parameter)
void tampilJudul(string namaToko, string lokasi) {
buatGaris();
cout << namaToko << endl;
cout << lokasi << endl;
buatGaris();
}
// 3. Function Return Value (Without Parameter)
float getPPN() {
return 0.1; // 10%
}
// 4. Function Return Value (With Parameter)
long hitungSubtotal(int harga, int jumlah) {
return (long)harga * jumlah;
}
// Function NOT Return Value (With Parameter)
void ttd(string nama, string email, string nim) {
buatGaris();
cout << "Nama : " << nama << endl;
cout << "Email : " << email << endl;
cout << "NIM : " << nim << endl;
}
int main() {
int kode, jumlah;
string judulBuku, bonus = "-";
int harga = 0;
float diskon = 0, ppn_rp, total;
long subtotal;
tampilJudul("Toko Buku Ananda", "Jatirahayu - Bekasi");
puts("KETENTUAN");
buatGaris();
puts("| Kode | Judul | Harga |");
buatGaris();
puts("| 1 | Bungkam Suara | 90.000 |");
puts("| 2 | Dompet Ayah Sepatu Ibu | 95.000 |");
puts("| 3 | Kami (bukan) Sarjana Kertas | 85.000 |");
buatGaris();
cout << "Subtotal = Harga x Jumlah Beli" << endl;
cout << "PPN = 10% x Subtotal" << endl;
cout << "Jika jumlah beli > 5, diskon 10% dan bonus Magnetic Bookmark" << endl;
buatGaris();
puts("Harus Terdapat Fungsi:");
puts("cout, cin, printf, scanf, puts");
puts("Struktur IF dan Switch Case");
puts("Function Return Value (Without Parameter)");
puts("Function Return Value (With Parameter)");
puts("Function NOT Return Value (Without Parameter)");
puts("Function NOT Return Value (With Parameter)");
buatGaris();
// Memenuhi kriteria: printf dan scanf
printf("Masukan kode buku [1/2/3] : ");
scanf("%d", &kode);
printf("\n");
// Memenuhi kriteria: cout dan cin
cout << "Jumlah pembelian buku : " << endl;
cin >> jumlah;
// Struktur Switch Case
switch (kode) {
case 1:
judulBuku = "Bungkam Suara";
harga = 90000;
break;
case 2:
judulBuku = "Dompet Ayah Sepatu Ibu";
harga = 95000;
break;
case 3:
judulBuku = "Kami (bukan) Sarjana Kertas";
harga = 85000;
break;
default:
judulBuku = "Kode Tidak Valid";
harga = 0;
break;
}
subtotal = hitungSubtotal(harga, jumlah);
// Struktur IF
if (jumlah > 5) {
diskon = 0.1 * subtotal;
bonus = "Magnetic Bookmark";
}
ppn_rp = getPPN() * subtotal;
total = (float)subtotal - diskon + ppn_rp;
// Output Hasil
buatGaris();
cout << "Nama Buku : " << judulBuku << endl;
cout << "Harga Buku : " << harga << endl;
cout << "Bonus : " << bonus << endl;
// Output dengan printf (Format dua desimal)
printf("Subtotal : Rp. %.2f\n", (float)subtotal);
printf("Potongan : Rp. %.2f\n", diskon);
printf("PPN : Rp. %.2f\n", ppn_rp);
printf("Total : Rp. %.2f\n", total);
buatGaris();
puts("Terima Kasih Sudah Berbelanja");
ttd("Ananda Rakhma Aulia", "anandara7891@gmail.com", "3420220024");
buatGaris();
return 0;
}