Quick actions

cmd+k|ctrl+k

Navigation

Languages

Ujian Tengah Semester - Hikmal

Snippet info

Language

Cpp

Visibility

public

Author

muhammad-hikmal-faturrahman

Created

2024-11-19T00:15:32.903783Z

Updated

2024-11-19T02:03:16.928469Z

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void saya() {
    cout << " Nama  : Muhammad Hikmal Faturrahman\n";
    cout << " NIM   : 1620230001";
}
void garis() {
    cout << "--------------------------------------------------------------\n";
}
void JUDUL() {
    garis();
    cout << "PROGRAM TIKET KERETA\n";
    garis();
    cout << "|  Kelas  | AG(Argo Bromo) | AL(Argo Lawu)  | PH(Argo Wilis) |\n";
    garis();
    cout << "| 1-Executive | 500.000    | 475.000        | 450.000        |\n";
    cout << "| 2-Bisnis    | 480.000    | 455.000        | 430.000        |\n";
    cout << "| 3-Ekonomi   | 450.000    | 435.000        | 410.000        |\n";
    garis();
}
void diskon() {
    cout << "Ketentuan Discount:\n";
    cout << "Apabila pembelian tiket diatas 10 makan diskon 10% dari total\n";
    cout << "Apabila pembelian tiket diatas 5 makan diskon 5% dari total\n";
    garis();
}
void salah() {
    cout << "Ketentuan salah input:\n";
    cout <<"Jika input kode kereta ATAU kode kelas salah maka muncul pesan.\n";
}
void kondisi() {
    cout << "Program harus menggunakan switch case dan if else.\n";
    cout << "Harus ada fungsi JUDUL.\n";
    cout << "Harus ada fungsi CEK_NAMA.\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";
}
double CEK_HARGA(string kodeKereta, int kodeKelas) {
    double harga = 0;
    if (kodeKereta == "AG") {
        if (kodeKelas == 1) harga = 500000;
        else if (kodeKelas == 2) harga = 480000;
        else if (kodeKelas == 3) harga = 450000;
    } else if (kodeKereta == "AL") {
        if (kodeKelas == 1) harga = 475000;
        else if (kodeKelas == 2) harga = 455000;
        else if (kodeKelas == 3) harga = 435000;
    } else if (kodeKereta == "PH") {
        if (kodeKelas == 1) harga = 450000;
        else if (kodeKelas == 2) harga = 430000;
        else if (kodeKelas == 3) harga = 410000;
    }
    return harga;
}
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 "Kode Kereta Tidak Valid";
}
string CEK_KELAS(int kodeKelas) {
    if (kodeKelas == 1) return "Executive";
    else if (kodeKelas == 2) return "Bisnis";
    else if (kodeKelas == 3) return "Ekonomi";
    return "Kode Kelas Tidak Valid";
}
double CEK_DISKON(int jumlahBeli, double subtotal) {
    if (jumlahBeli > 10) return subtotal * 0.10;
    else if (jumlahBeli > 5) return subtotal * 0.05;
    return 0;
}
int main() {
    JUDUL();
    diskon();
    salah();
    garis();
    kondisi();
    garis();
    string nama, kodeKereta;
    int kodeKelas, jumlahBeli;
    cout << "Nama Pemesan: \n";
    cin >> nama;
    cout << "Masukan Kode Kereta [AG/AL/PH]: \n";
    cin >> kodeKereta;
    cout << "Masukan Kode Kelas [1/2/3]: \n";
    cin >> kodeKelas;
    double hargaTiket = CEK_HARGA(kodeKereta, kodeKelas);
    string namaKereta = CEK_NAMA_KERETA(kodeKereta);
    string namaKelas = CEK_KELAS(kodeKelas);
    if (hargaTiket == 0 || namaKereta == "Kode Kereta Tidak Valid" || namaKelas == "Kode Kelas Tidak Valid") {
        cout << "Input Salah: Kode Kereta atau Kode Kelas tidak valid.\n";
    } else {
        cout << "Jumlah Beli: \n";
        cin >> jumlahBeli;
        double subtotal = hargaTiket * jumlahBeli;
        double diskon = CEK_DISKON(jumlahBeli, subtotal);
        double total = subtotal - diskon;
        cout << fixed << setprecision(2);
        garis();
        cout << "DATA PEMESANAN KERETA\n";
        garis();
        cout << "Nama Pemesan : " << nama << "\n";
        cout << "Kode Kereta  : " << kodeKereta << "\n";
        cout << "Kode Kelas   : " << kodeKelas << "\n";
        cout << "Nama Kereta  : " << namaKereta << "\n";
        cout << "Nama Kelas   : " << namaKelas << "\n";
        cout << "Harga Tiket  : " << hargaTiket << "\n";
        cout << "Jumlah Beli  : " << jumlahBeli << "\n";
        cout << "Subtotal     : " << subtotal << "\n";
        cout << "Diskon       : " << diskon << "\n";
        cout << "Total        : " << total << "\n";
        garis();
        saya();
    }
    return 0;
}
INFO