#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
//Moh.Faqih S.Karim
//3420230034
void judul() {
cout << "----------------------------------------------------------------"<<endl;
cout << " PROGRAM TIKET KERETA\n";
cout << "----------------------------------------------------------------"<<endl;
cout << "| Kelas | AG(Argo Bromo) | AL(Argo Lawu) | PH(Argo Wilis) |"<<endl;
cout << "----------------------------------------------------------------"<<endl;
cout << "| 1-Executive | 500.000 | 475.000 | 450.000 |"<<endl;
cout << "| 2-Bisnis | 480.000 | 455.000 | 430.000 |"<<endl;
cout << "| 3-Ekonomi | 460.000 | 435.000 | 410.000 |"<<endl;
cout << "----------------------------------------------------------------"<<endl;
cout << "Ketentuan Discount:"<<endl;
cout << "Apabila pembelian tiket diatas 10 maka diskon 10% dari Total"<<endl;
cout << "Apabila pembelian tiket diatas 5 maka diskon 5% dari Total"<<endl;
cout << "----------------------------------------------------------------"<<endl;
cout << "Ketentuan Salah Input:"<<endl;
cout << "Jika input Kode Kereta ATAU Kode Kelas salah maka muncul pesan."<<endl;
cout << "----------------------------------------------------------------"<<endl;
cout << "Ketentuan Kondisi:"<<endl;
cout << "Program harus menggunakan switch case dan if else."<<endl;
cout << "Harus ada fungsi JUDUL."<<endl;
cout << "Harus ada fungsi CEK_HARGA."<<endl;
cout << "Harus ada fungsi CEK_NAMA_KERETA."<<endl;
cout << "Harus ada fungsi CEK_KELAS."<<endl;
cout << "Harus ada fungsi CEK_DISKON."<<endl;
cout << "Harus bisa handle input huruf besar dan kecil."<<endl;
cout << "----------------------------------------------------------------"<<endl;
}
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 << "----------------------------------------------------------------"<<endl;
}
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>"<<endl;
cin >> namaPemesan;
cout << "Masukan Kode Kereta [AG/AL/PH] : <input>"<<endl;
cin >> kodeKereta;
cout << "Masukan Kode Kelas [1/2/3] : <input>"<<endl;
cin >> kodeKelas;
if (kodeKereta != "AG" && kodeKereta != "AL" && kodeKereta != "PH") {
cout << "Kode Kereta salah!"<<endl;
return 1;
}
if (kodeKelas < 1 || kodeKelas > 3) {
cout << "Kode Kelas salah!"<<endl;
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 << "----------------------------------------------------------------"<<endl;
cout << "DATA PEMESANAN KERETA" <<endl;
cout << "----------------------------------------------------------------"<<endl;
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 << "----------------------------------------------------------------"<<endl;
cout << "Nama : Mohh.Faqih S.Karim";
cout << "\nEmail : muhammadfaqih1434@gmail.com";
return 0;
}