Untitled

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <string> #include <cctype> using namespace std; //Nagita Elsa //3420230026 void garis() { cout<<"==============================================================================="<<endl; } void judul() { garis(); cout<<"PROGRAM TIKET KERETA "<<endl; garis(); cout<<"| Kelas | AG (Argo Bromo) | AL (Argo Lawu) | PH (Argo Wilis) |"<<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; garis(); } void ttd() { cout<<""<<endl; garis(); cout<<"Nama : Nagita Elsa Saputri"<<endl; cout<<"Emali : nagitaelsa39@gmail.com"<<endl; } //fungsi untuk mengecek dan mengembalikan harga tiket double cekHarga(string kodeKereta, int kodeKelas){ double harga = 0; kodeKereta = toupper(kodeKereta[0]); if(kodeKelas <3 || kodeKelas >2 ) return 0; if(kodeKereta == "A") { switch (kodeKelas){ case 1: harga = 500000; break; case 2: harga = 475000; break; case 3: harga = 450000; break; } } else if (kodeKereta == "L") { switch (kodeKelas){ case 1: harga = 480000; break; case 2: harga = 455000; break; case 3: harga = 430000; break; } } else if (kodeKereta == "P") { switch (kodeKelas){ case 1: harga = 460000; break; case 2: harga = 434000; break; case 3: harga = 410000; break; } } else { return -1; } return harga; } // Fungsi untuk menghitung diskon double cekDiskon(double subtotal) { if (subtotal > 1000000) return subtotal * 0.10; // Diskon 10% if (subtotal > 500000) return subtotal * 0.05; // Diskon 5% return 0; // Tidak ada diskon } 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"; else return "Kode Kereta Salah"; } string CEK_KELAS(int kodeKelas) { if (kodeKelas == 1) return "Executive"; else if (kodeKelas == 2) return "Bisnis"; else if (kodeKelas == 3) return "Ekonomi"; else return "Kode Kelas Salah"; } int main() { judul(); string namaPemesan, kodeKereta; int kodeKelas, jumlahTiket; double hargaTiket, subtotal, diskon, total; cout<<""<<endl; cout<<"Nama Pemesan : "; cin >> namaPemesan; cout<<"\nMasukan Kode Kereta [AG/AL/PH] : "; cin >>kodeKereta; cout<<"\nMasukan Kode Kelas [1/2/3] : "<<endl; cin >>kodeKelas; hargaTiket = cekHarga(kodeKereta, kodeKelas); if (hargaTiket == 1) { cout << "Kode Kereta atau Kode Kelas Salah!" << endl; return 1; // Menunjukkan error } subtotal = hargaTiket * jumlahTiket; diskon = cekDiskon(subtotal); total = subtotal - diskon; cout<<""<<endl; garis(); cout << "DATA PEMESANAN KERETA" << endl; garis(); cout << "Nama Pemesan: " << namaPemesan << endl; cout << "Kode Kereta : " << kodeKereta << endl; cout << "Kode Kelas : " << kodeKelas << endl; cout << "Nama Kereta : "; // Menampilkan nama kereta berdasarkan kode kereta if (kodeKereta == "AG" || kodeKereta == "ag") cout << "Argo Bromo" << endl; else if (kodeKereta == "AL" || kodeKereta == "al") cout << "Argo Lawu" << endl; else if (kodeKereta == "PH" || kodeKereta == "ph") cout << "Argo Wilis" << endl; cout << "Nama Kelas : "; // Menampilkan nama kelas berdasarkan kode kelas if (kodeKelas == 1) cout << "Executive" << endl; else if (kodeKelas == 2) cout << "Bisnis" << endl; else cout << "Ekonomi" << endl; cout << "Harga Tiket : " << hargaTiket << endl; cout << "Jumlah Beli : " << jumlahTiket << endl; cout << "Subtotal : " << subtotal << endl; cout << "Diskon : " << diskon << endl; cout << "Total : " << total << endl; ttd(); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines