Quick actions

cmd+k|ctrl+k

Navigation

Languages

Latihan 12.1 Algoritma Dan Struktur Data

Snippet info

Language

Cpp

Visibility

public

Author

fadhlanr

Created

2025-12-27T05:26:04.317173Z

Updated

2025-12-27T05:57:14.06616Z

#include <iostream>
#include <iomanip>
using namespace std;

struct Penginapan {
    string nama;
    char kode;
    int lama;
    string tipe;
    double harga;
    string souvenir;
    double admin;
    double total;
};

void Garis() {
    cout << "--------------------------------------------\n";
}

void Judul() {
    Garis();
    cout << "Harmoni Hotel & Guest House\n";
    Garis();
}

void Ketentuan() {
    cout << "List Function\n";
    Garis();
    cout << "1. Function Garis()\n";
    cout << "2. Function Judul()\n";
    cout << "3. Function Ketentuan()\n";
    cout << "4. Function TTD()\n";
    cout << "5. Function infoTarif()\n";
    cout << "6. Function Cek_Tipe()\n";
    cout << "7. Function Cek_Harga()\n";
    cout << "8. Function Cek_Souvenir()\n";
    Garis();
    cout << "Harus bisa handle huruf besar dan kecil.\n";
    cout << "Harus menggunakan Struct.\n";
    Garis();
    cout << "Jika lama menginap lebih dari 6 hari maka mendapatkan souvenir Handphone Iphone\n";
    cout << "Biaya admin 200.000\n";
    cout << "Total Bayar adalah (Harga dikali Lama Menginap) + Biaya Admin\n";
    Garis();
}

void infoTarif() {
    cout << "| Kode | Tipe             | Harga   |\n";
    Garis();
    cout << "| A    | Matahari         | 800.000 |\n";
    cout << "| B    | Single Room      | 700.000 |\n";
    cout << "| C    | Date Room        | 600.000 |\n";
    Garis();
}

void TTD(Penginapan &p) {
    cin >> p.nama >> p.kode >> p.lama;
}

void Cek_Tipe(Penginapan &p) {
    if (p.kode == 'A' || p.kode == 'a') p.tipe = "Matahari";
    else if (p.kode == 'B' || p.kode == 'b') p.tipe = "Single Room";
    else if (p.kode == 'C' || p.kode == 'c') p.tipe = " Date Room";
}

void Cek_Harga(Penginapan &p) {
    if (p.kode == 'A' || p.kode == 'a') p.harga = 800000;
    else if (p.kode == 'B' || p.kode == 'b') p.harga = 700000;
    else if (p.kode == 'C' || p.kode == 'c') p.harga = 600000;
}

void Cek_Souvenir(Penginapan &p) {
    if (p.lama > 6) p.souvenir = "Handphone Iphone";
    else p.souvenir = "-";
}

int main() {
    Penginapan p;
    p.admin = 200000;

    Judul();
    Ketentuan();
    infoTarif();

    TTD(p);
    Cek_Tipe(p);
    Cek_Harga(p);
    Cek_Souvenir(p);

    p.total = (p.harga * p.lama) + p.admin;

    cout << fixed << setprecision(2);
    cout << "Nama Penyewa      : " << p.nama << endl;
    cout << "Kode Kamar [A/B/C]: " << p.kode << endl;
    cout << "Lama Menginap     : " << p.lama << " hari\n";
    cout << "Harga Sewa        : Rp." << p.harga << endl;
    cout << "Tipe Kamar        : " << p.tipe << endl;
    cout << "Souvenir          : " << p.souvenir << endl;
    cout << "Administrasi      : Rp." << p.admin << endl;
    cout << "Total Biaya       : Rp." << p.total << endl;
    Garis();
    cout << "Nama  : M Fadhlan Robbi\n";
    cout << "Email : [email protected]\n";

    return 0;
}
INFO