#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Nama : Faqih Nur Zaki
// Nim : 3420230041
// Prodi: Teknik Informatika smt 3
void judul() {
cout << "============================================================================" << endl;
cout << "\t\t\tPROGRAM TIKET KERETA " << endl;
cout << "============================================================================" << endl;
}
void Daftar_tiket_kereta() {
cout << "\t\t\tDaftar Tiket Kereta" << endl;
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;
}
void Ketentuan_diskon() {
cout << "\t\t\tKetentuan diskon" << endl;
cout << "1. Apa bila Pembelian tiket di atas 10 maka diskon 10% dari total." << endl;
cout << "2. Apa bila Pembelian tiket di atas 5 maka diskon 5% dari total." << endl;
cout << "============================================================================" << endl;
cout << "\t\t\tKetentuan Salah Input :" << endl;
cout << "Jika input kode kereta ATAU kode kelas salah maka muncul pesan" << endl;
cout << "============================================================================" << endl;
cout << "\t\t\tKetentuan 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;
}
string toUpperCase(string str) {
(str.begin(), str.end(), str.begin(), ::toupper);
return str;
}
string Cek_nama_kereta(string kodekereta)
{
kodekereta = toUpperCase(kodekereta);
if (kodekereta == "AG") return "Argo Bromo";
else if (kodekereta == "AL") return "Argo Lawu";
else if (kodekereta == "PH") return "Argo Wilis";
else if (kodekereta == "ag") return "Argo Bromo";
else if (kodekereta == "al") return "Argo lawu";
else if (kodekereta == "ph") return "Argo Wilis";
else return "Kode Salah";
}
string Cek_kelas(int kodekelas)
{
switch (kodekelas) {
case 1: return "Executive";
case 2: return "Bisnis";
case 3: return "Ekonomi";
default: return "Kode Salah";
}}
int Cek_harga(string kodekereta, int kodekelas) {
kodekereta = toUpperCase(kodekereta);
if (kodekereta == "AG") {
switch (kodekelas) {
case 1: return 400000;
case 2: return 480000;
case 3: return 460000;
default: return -1;
}
} else if (kodekereta == "AL") {
switch (kodekelas) {
case 1: return 475000;
case 2: return 455000;
case 3: return 435000;
default: return -1;
}
} else if (kodekereta == "PH") {
switch (kodekelas) {
case 1: return 650000;
case 2: return 530000;
case 3: return 310000;
default: return -1;
}
} else if (kodekereta == "ag") {
switch (kodekelas) {
case 1: return 400000;
case 2: return 480000;
case 3: return 460000;
default: return -1;
}
} else if (kodekereta == "al") {
switch (kodekelas) {
case 1: return 475000;
case 2: return 455000;
case 3: return 435000;
default: return -1;
}
} else if (kodekereta == "ph") {
switch (kodekelas) {
case 1: return 650000;
case 2: return 530000;
case 3: return 310000;
default: return -1;
}
}
return -1;
}
double Cek_diskon(int jumlahbeli, double subtotal) {
if (jumlahbeli > 10) return subtotal * 0.10;
else if (jumlahbeli > 5) return subtotal * 0.05;
return 0.0;
}
int main() {
string namapemesan, kodekereta;
int kodekelas, jumlahbeli;
judul();
Daftar_tiket_kereta();
Ketentuan_diskon();
cout << " \nNama Pemesan:\n ";
getline(cin, namapemesan);
cout << "Masukkan Kode Kereta [AG/AL/PH]:\n ";cin >> kodekereta;
cout << "Masukkan Kode Kelas [1/2/3]:\n ";cin >> kodekelas;
cout << "Jumlah Beli:\n ";cin >> jumlahbeli;
string kodeKeretaCapital = toUpperCase(kodekereta);
string namakereta = Cek_nama_kereta(kodeKeretaCapital);
string namakelas = Cek_kelas(kodekelas);
int hargatiket = Cek_harga(kodeKeretaCapital, kodekelas);
if (namakereta == "Kode Salah" || namakelas == "Kode Salah" || hargatiket == -1) {
cout << "\nKode yang anda masukan salah, coba lagi!" << endl;
return 0;
}
cout << "==============================================================================" << endl;
double subtotal = hargatiket * jumlahbeli;
double diskon = Cek_diskon(jumlahbeli,subtotal);
double total = subtotal - diskon;
cout << fixed << setprecision(2);
cout << "\t\t\tDATA PEMESANAN KERETA" << endl;
cout << "=============================================================================" << endl;
cout << "Nama Pemesan : " << namapemesan << endl;
cout << "Kode Kereta : " << kodeKeretaCapital << endl;
cout << "Nama Kereta : " << namakereta << endl;
cout << "Kode Kelas : " << kodekelas << endl;
cout << "Nama Kelas : " << namakelas << endl;
cout << "Harga Tiket : " << hargatiket << endl;
cout << "Jumlah Beli : " << jumlahbeli << endl;
cout << "Subtotal : " << subtotal << endl;
cout << "Diskon : " << diskon << endl;
cout << "Total : " << total << endl;
cout << "=============================================================================" << endl;
cout << "Nama : Faqih Nur Zaki" << endl;
cout << "Email : faqihnz24@gmail.com" << endl;
cout << "=============================================================================" << endl;
return 0;
}