Tugas Algoritma V2

 avatar
mitraKukar01
c_cpp
2 years ago
4.5 kB
11
Indexable
Never
#include <iostream>
#include <locale>
#include <memory>
#include <Windows.h> // untuk syntax didalam windows 10
using namespace std;

int entry, lamaInap, pKodeKamar, kodeKamar[] = {101, 201, 301}, hargaKamar[] = {1000000, 600000, 450000}, n = sizeof(kodeKamar)/sizeof(kodeKamar[0]), totalBayar;
string button, namaTamu, checkin, checkout, namaKamar[] = {"Deluxe", "Standard", "Ekonomi"};
bool isTrue = true;

struct separate_thousands : std::numpunct<char> {
    char_type do_thousands_sep() const override { return '.'; }  // dipisahkan dengan titik
    string_type do_grouping() const override { return "\3"; } // dibagi antara 3 digit angka
};

void FakturTamu(string namaTamu, string checkin, string checkout, string namaKamar[], int pKodeKamar, int n, int kodeKamar[], int hargaKamar[], int lamaInap){
    system("cls");
    auto thousands = std::make_unique<separate_thousands>();
    std::cout.imbue(std::locale(std::cout.getloc(), thousands.release()));
    cout << "\n\n\n+---------------------------------------+" << endl;
    cout << "\t\t|Faktur\t\t|" << endl;
    cout << "|Nama Tamu: " << namaTamu << "|" << endl;
    cout << "|Tgl. Kedatangan (Check In) : " << checkin << "|" << endl;
    cout << "|Tgl. Keberangkatan (Check Out) : " << checkout << "|" << endl;
    cout << "|Lama Menginap : " << lamaInap << " Hari |" << endl;
    for(int i = 0; i<n; i++){
        if(kodeKamar[i] == pKodeKamar){
            cout << "|Kode Kamar : " << kodeKamar[i] << "|" << endl;
            cout << "|Harga Kamar : Rp. " << hargaKamar[i] << "|" << endl;
            cout << "|Nama Kamar : " << namaKamar[i] << "|" << endl;

            totalBayar = hargaKamar[i] * lamaInap;
        }
    }
    if(lamaInap > 3){
        // totalBayar = totalBayar - (totalBayar * 0.125);
        totalBayar -= totalBayar * 0.125;
        cout << "|Diskon : 12,5% |" << endl;
        cout << "|Total Bayar : " << totalBayar << "|" << endl;
    }else{
        cout << "|Total Bayar : " << totalBayar << "|" << endl;
    }
    cout << "+---------------------------------------+\n\n" << endl;
}

void LaporanHarian(string namaTamu, string checkin, string checkout, string namaKamar[], int pKodeKamar, int n, int kodeKamar[], int hargaKamar[], int lamaInap){
    system("cls");
    auto thousands = std::make_unique<separate_thousands>();
    std::cout.imbue(std::locale(std::cout.getloc(), thousands.release()));
    cout << "| Laporan Pendapatan Harian |\n| per tanggal 30 Mei 2022 |" << endl;
    cout << "| Nama Tamu | Tgl.Check In | Tgl.Check Out | Lama Menginap | Kode Kamar | Harga Kamar | Diskon | Total Bayar |" << endl;
    cout << "| " <<namaTamu << " |";
    cout << checkin << " |";
    cout << checkout << " |";
    cout << lamaInap << " Hari |";
    for(int i = 0; i<n; i++){
        if(kodeKamar[i] == pKodeKamar){
            cout << kodeKamar[i] << " (" << namaKamar[i] << ") |";
            cout << "Rp. " << hargaKamar[i] << " |";
        }
    }
    if(lamaInap > 3){
        cout << "12,5%" << " |";
    }else{
        cout << "-" << " |";
    }
    cout << "Rp. " << totalBayar << " |" << endl;
}

int main(){
    // system("COLOR 17");
    do{
        system("cls");
        cout << "1. Faktur Tamu\n2. Laporan Harian\n3. Exit\nPilih: "; cin >> entry;
        switch(entry){
        case 1:
            system("cls");
            std::cin.ignore();
            cout << "Nama Tamu: "; getline(cin, namaTamu);
            cout << "Tanggal Check In: "; getline(cin, checkin);
            cout << "Tanggal Check Out : "; getline(cin, checkout);
            cout << "Lama Menginap : "; cin >> lamaInap;
            cout << "Kode Kamar : "; cin >> pKodeKamar;
            FakturTamu(namaTamu, checkin, checkout, namaKamar, pKodeKamar, n, kodeKamar, hargaKamar, lamaInap);
            do{system("pause");
            }while(button == " ");
            Sleep(1500);
            break;
        case 2:
            system("cls");
            LaporanHarian(namaTamu, checkin, checkout, namaKamar, pKodeKamar, n, kodeKamar, hargaKamar, lamaInap);
            do{system("pause");
            }while(button == " ");
            Sleep(1500);
            break;
        case 3:
            system("cls");
            cout << "Good Bye...\n\n";
            isTrue = false;
            Sleep(1000);
            break;
        }
    }while (isTrue != false);
    return 0;
}