#include <iostream>
#include <string>
using namespace std;
void judul() {
cout << "-------------------------------------------------------------------\n";
cout << " PROGRAM TIKET KERETA |\n";
cout << "-------------------------------------------------------------------\n";
}
void tabel() {
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";
}
void hasil() {
cout << "-------------------------------------------------------------------\n";
cout << "| HASIL PEMESANAN |\n";
cout << "-------------------------------------------------------------------\n";
}
string cek_nama_kereta(string kodeKereta) {
if (kodeKereta == "AG" || kodeKereta == "ag") return "Argo Bromo";
else if (kodeKereta == "AL" || kodeKereta == "al") return "Argo Lawu";
else if (kodeKereta == "PH" || kodeKereta == "ph") return "Argo Wilis";
else return "Kode Kereta Salah";
}
string cek_kelas(int kodeKelas) {
switch (kodeKelas) {
case 1: return "Executive";
case 2: return "Bisnis";
case 3: return "Ekonomi";
default: return "Kode Kelas Salah";
}
}
int cek_harga(string kodeKereta, int kodeKelas) {
if (kodeKereta == "AG" || kodeKereta == "ag") {
if (kodeKelas == 1) return 500000;
else if (kodeKelas == 2) return 480000;
else if (kodeKelas == 3) return 460000;
} else if (kodeKereta == "AL" || kodeKereta == "al") {
if (kodeKelas == 1) return 475000;
else if (kodeKelas == 2) return 455000;
else if (kodeKelas == 3) return 435000;
} else if (kodeKereta == "PH" || kodeKereta == "ph") {
if (kodeKelas == 1) return 450000;
else if (kodeKelas == 2) return 430000;
else if (kodeKelas == 3) return 410000;
}
return 0;
}
float hitungDiskon(int jumlahBeli, float subtotal) {
if (jumlahBeli > 10) {
return subtotal * 0.1;
} else if (jumlahBeli > 5) {
return subtotal * 0.05;
} else
return 0;
}
int main() {
string namaPemesan, kodeKereta;
int kodeKelas, jumlahBeli;
judul();
tabel();
cout << "Nama Pemesan : ";
cin >> namaPemesan; cout<<"\n";
cout << "Masukkan Kode Kereta [AG/AL/PH] : ";
cin >> kodeKereta; cout<<"\n";
cout << "Masukkan Kode Kelas [1/2/3] : ";
cin >> kodeKelas; cout<<"\n";
cout << "Jumlah Beli : " << endl;
cin >> jumlahBeli;
string namaKereta = cek_nama_kereta(kodeKereta);
string namaKelas = cek_kelas(kodeKelas);
int hargaTiket = cek_harga(kodeKereta, kodeKelas);
if (namaKereta == "Kode Kereta Salah" || namaKelas == "Kode Kelas Salah" || hargaTiket == 0) {
cout << "\nKode Kereta atau Kode Kelas yang Anda masukkan salah.\n";
return 1;
}
float subtotal = hargaTiket * jumlahBeli;
float diskon = hitungDiskon(jumlahBeli, subtotal);
float total = subtotal - diskon;
hasil();
cout << "Nama Pemesan : " << namaPemesan << endl;
cout << "Kode Kereta : " << kodeKereta << endl;
cout << "Kode Kelas : " << kodeKelas << endl;
cout << "Nama Kereta : " << namaKereta << endl;
cout << "Nama Kelas : " << namaKelas << endl;
cout << "Harga Tiket : Rp." << hargaTiket << endl;
printf ("Subtotal : Rp.%.2f \n", subtotal);
printf ("Diskon : Rp.%.2f \n", diskon);
printf ("Total : Rp.%.2f \n", total);
cout << "-------------------------------------------------------------------\n";
cout << "Nama : Dhafin Shabir alfatih\n";
cout << "Email : dhafinshabir610@gmail.com\n";
return 0;
}