Tugas 12.1

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <string> #include <cctype> #include <iomanip> // Nama : Ramdika Rovansah // Nim : 3420230027 using namespace std; struct Kamar { char kode; string tipe; double harga; }; //Fungsi garis void Garis() { cout << "----------------------------------" << endl; } //Fungsi Judul void Judul() { Garis(); cout<<"PENGINAPAN PASTI BETAH"<<endl; Garis(); cout<<"List Function"<<endl; Garis(); cout<<"1. Function Garis()"<<endl; cout<<"2. Function Judul()"<<endl; cout<<"3. Function Ketentuan()"<<endl; cout<<"4. Function TTD()"<<endl; cout<<"5. Function Tarif()"<<endl; cout<<"6. Function Cek_Tipe()"<<endl; cout<<"7. Function Cek_Harga()"<<endl; cout<<"8. Function Cek_Souvenir()"<<endl; Garis(); cout<<"Harus bisa handle huruf besar dan kecil."<<endl; cout<<"Harus Menggunakan Struct."<<endl; Garis(); } //Fungsi Ketentuan void Ketentuan() { cout << "Jika lama menginap lebih dari 6 hari maka mendapatkan souvenir Payung Cantik" << endl; cout << "Biaya admin 200.000" << endl; cout << "Total Bayar adalah (Harga dikali Lama Menginap) + Biaya Admin" << endl; } //Fungsi TTD void TTD() { Garis(); cout << "Nama : Ramdika Rovansah" << endl; cout << "Email: ramdika33@gmail.com" << endl; } //Fungsi infoTarif void infoTarif() { Garis(); cout<<"| Kode | Tipe | Harga |"<<endl; Garis(); cout<<"| A | Anggrek | 800.000 |"<<endl; cout<<"| B | Bougenville | 700.000 |"<<endl; cout<<"| C | Mawar | 600.000 |"<<endl; Garis(); } double Tarif(char kodeKamar) { switch (kodeKamar) { case 'A': case 'a': return 800000; case 'B': case 'b': return 700000; case 'C': case 'c': return 600000; default: return 0; } } //Fungsi Cek Tipe string Cek_Tipe(char kode, const Kamar kamar[], int n) { kode = tolower(kode); for (int i = 0; i < n; i++) { if (tolower(kamar[i].kode) == kode) { return kamar[i].tipe; } } return "Tidak Diketahui"; } //Fungsi Cek Harga double Cek_Harga(char kode, const Kamar kamar[], int n) { kode = tolower(kode); for (int i = 0; i < n; i++) { if (tolower(kamar[i].kode) == kode) { return kamar[i].harga; } } return 0; } //Fungsi Cek Souvennir string Cek_Souvenir(int lamaMenginap) { return (lamaMenginap > 6) ? "Payung Cantik" : "Tidak Ada"; } int main() { Kamar kamar[] = { {'A', "Anggrek", 800000}, {'B', "Bougenville", 700000}, {'C', "Mawar", 600000} }; const int n = sizeof(kamar) / sizeof(kamar[0]); string nama; char kodeKamar; int lamaMenginap; Judul(); Ketentuan(); Garis(); // Input cout << "Nama Penyewa \t : <input>\n"; cin >> nama; cout << "Kode Kamar [A/B/M]: <input>\n"; cin >> kodeKamar; cout << "Lama Menginap \t : <input>\n"; cin >> lamaMenginap; infoTarif(); // Proses double hargaSewa = Cek_Harga(kodeKamar, kamar, n); string tipeKamar = Cek_Tipe(kodeKamar, kamar, n); string souvenir = Cek_Souvenir(lamaMenginap); double administrasi = 200000; double totalBiaya = (hargaSewa * lamaMenginap) + administrasi; // Output cout << "Nama Penyewa : " << nama << endl; cout << "Kode Kamar : " << kodeKamar << endl; cout << "Lama Menginap : " << lamaMenginap << " hari" << endl; cout << "Harga Sewa : Rp." << fixed << setprecision(2) << hargaSewa << endl; cout << "Tipe Kamar : " << tipeKamar << endl; cout << "Souvenir : " << souvenir << endl; cout << "Administrasi : Rp." << administrasi << endl; cout << "Total Biaya : Rp." << totalBiaya << endl; TTD(); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines