#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
//Nama : Moh.Faqih S.Karim
//Nim : 3420230034
void judul() {
cout << "----------------------------------------------------------------\n";
cout << " PROGRAM TIKET KERETA\n";
cout << "--------------------------------------------------------------\n";
cout << "| Kelas | AG(Argo Bromo) | AL(Argo Lawu) | PH(Argo Wilis) |\n";
cout << "|-------------|----------------|---------------|----------------|\n";
cout << "| 1-Executive | 500.000 | 475.000 | 450.000 |\n";
cout << "| 2-Bisnis | 480.000 | 455.000 | 430.000 |\n";
cout << "| 3-Ekonomi | 460.000 | 435.000 | 410.000 |\n";
cout << "----------------------------------------------------------------\n";
cout << "Ketentuan Discount:\n";
cout << "Apabila pembelian tiket diatas 10 maka diskon 10% dari Total\n";
cout << "Apabila pembelian tiket diatas 5 maka diskon 5% dari Total\n";
cout << "----------------------------------------------------------------\n";
cout << "Ketentuan Salah Input:\n";
cout << "Jika input Kode Kereta ATAU Kode Kelas salah maka muncul pesan.\n";
cout << "----------------------------------------------------------------\n";
cout << "Ketentuan Kondisi:\n";
cout << "Program harus menggunakan switch case dan if else.\n";
cout << "Harus ada fungsi JUDUL.\n";
cout << "Harus ada fungsi CEK_HARGA.\n";
cout << "Harus ada fungsi CEK_NAMA_KERETA.\n";
cout << "Harus ada fungsi CEK_KELAS.\n";
cout << "Harus ada fungsi CEK_DISKON.\n";
cout << "Harus bisa handle input huruf besar dan kecil.\n";
cout << "----------------------------------------------------------------\n";
}
void cek_harga(int &harga, string kodeKereta, int kelas) {
if (kodeKereta == "AG") {
if (kelas == 1) harga = 500000;
else if (kelas == 2) harga = 480000;
else if (kelas == 3) harga = 460000;
} else if (kodeKereta == "AL") {
if (kelas == 1) harga = 475000;
else if (kelas == 2) harga = 455000;
else if (kelas == 3) harga = 435000;
} else if (kodeKereta == "PH") {
if (kelas == 1) harga = 450000;
else if (kelas == 2) harga = 430000;
else if (kelas == 3) harga = 410000;
}
}
void garis() {
cout << "----------------------------------------------------------------\n";
}
string cek_nama_kereta(string kodeKereta) {
if (kodeKereta == "AG") return "Argo Bromo";
else if (kodeKereta == "AL") return "Argo Lawu";
else if (kodeKereta == "PH") return "Argo Wilis";
return "Tidak diketahui";
}
double cek_diskon(int jumlah, double subtotal) {
if (jumlah > 10) return subtotal * 0.10;
else if (jumlah > 5) return subtotal * 0.05;
return 0;
}
string cek_kelas(int kelas) {
switch (kelas) {
case 1: return "Executive";
case 2: return "Bisnis";
case 3: return "Ekonomi";
default: return "Kode Kelas Salah";
}
}
int main() {
judul();
string namaPemesan, kodeKereta;
int kodeKelas, harga, jumlahBeli;
double subtotal, diskon, total;
cout << "Nama Pemesan : <input>\n";
cin >> namaPemesan;
cout << "Masukan Kode Kereta [AG/AL/PH] : <input>\n";
cin >> kodeKereta;
cout << "Masukan Kode Kelas [1/2/3] : <input>\n";
cin >> kodeKelas;
if (kodeKereta != "AG" && kodeKereta != "AL" && kodeKereta != "PH") {
cout << "Kode Kereta salah!\n";
return 1;
}
if (kodeKelas < 1 || kodeKelas > 3) {
cout << "Kode Kelas salah!\n";
return 1;
}
cek_harga(harga, kodeKereta, kodeKelas);
string namaKereta = cek_nama_kereta(kodeKereta);
string namaKelas = cek_kelas(kodeKelas);
cout <<endl;
cin >> jumlahBeli;
subtotal = harga * jumlahBeli;
diskon = cek_diskon(jumlahBeli, subtotal);
total = subtotal - diskon;
// Output data pemesanan
cout << "\n--------------------------------------------------------------\n";
cout << "DATA PEMESANAN KERETA\n";
cout << "--------------------------------------------------------------\n";
cout << "Nama Pemesan : " << namaPemesan <<" <output>" << endl;
cout << "Kode Kereta : " << kodeKereta <<" <output>" << endl;
cout << "Kode Kelas : " << kodeKelas << "<output>" << endl;
cout << "Nama Kereta : " << namaKereta <<" <output>" << endl;
cout << "Nama Kelas : " << namaKelas <<" <output>" << endl;
cout << "Harga Tiket : " << fixed << setprecision(2) << harga <<" <output>" << endl;
cout << "Jumlah Beli : " /*<< jumlahBeli*/ <<"<input>" << endl;
cout << "Subtotal : " << fixed << setprecision(2) << subtotal <<" <output>" << endl;
cout << "Diskon : " << fixed << setprecision(2) << diskon <<" <output>" << endl;
cout << "Total : " << fixed << setprecision(2) << total <<" <output>" << endl;
cout << "--------------------------------------------------------------\n";
cout << "Nama : Moh.Faqihh S.Karim";
cout << "\nEmail : muhammadfaqih1434@gmail.com";
return 0;
}