Tugas UAS v3

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

int entry, lamaInap[100], pKodeKamar[100], kodeKamar[] = {101, 201, 301}, hargaKamar[] = {1000000, 600000, 450000}, totalBayar[100], n=0, i=0;
string button, namaTamu[100], checkin[100], checkout[100], yesno, 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[100], string checkin[100], string checkout[100], string namaKamar[], int pKodeKamar[100], int n, int kodeKamar[], int hargaKamar[], int lamaInap[100], int totalBayar[100]){
    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[n] << "|" << endl;
    cout << "|Tgl. Kedatangan (Check In) : " << checkin[n] << "|" << endl;
    cout << "|Tgl. Keberangkatan (Check Out) : " << checkout[n] << "|" << endl;
    cout << "|Lama Menginap : " << lamaInap[n] << " Hari |" << endl;
    for(i; i<3; i++){
        if(kodeKamar[i] == pKodeKamar[n]){
            cout << "|Kode Kamar : " << kodeKamar[i] << "|" << endl;
            cout << "|Harga Kamar : Rp. " << hargaKamar[i] << "|" << endl;
            cout << "|Nama Kamar : " << namaKamar[i] << "|" << endl;

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

void LaporanHarian(string namaTamu[100], string checkin[100], string checkout[100], string namaKamar[], int pKodeKamar[100], int n, int kodeKamar[], int hargaKamar[], int lamaInap[100], int totalBayar[100]){
    int totalPendapatan;
    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;
    for(int j = 0; j<n;j++){
        cout << "| " << namaTamu[j] << " |";
        cout << checkin[j] << " |";
        cout << checkout[j] << " |";
        cout << lamaInap[j] << " Hari |";
        for(i; i<3; i++){
            if(kodeKamar[i] == pKodeKamar[j]){
                cout << kodeKamar[i] << " (" << namaKamar[i] << ") |";
                cout << "Rp. " << hargaKamar[i] << " |";
            }
        }
        if(lamaInap[j] > 3){
            cout << "12,5%" << " |";
        }else{
            cout << "-" << " |";
        }
        cout << "Rp. " << totalBayar[j] << " |" << endl;
        totalPendapatan = totalPendapatan + totalBayar[j];
    }
    cout << endl << totalPendapatan;
}

int main(){
    // system("COLOR 17");
    do{
        system("cls");
        cout << "1. Faktur Tamu\n2. Laporan Harian\n3. Exit\nPilih: "; cin >> entry;
        switch(entry){
        case 1:
            for(i; i<100;i++){
                system("cls");
                cout << "Nama Tamu: "; getline(cin >> ws, namaTamu[i]);
                cout << "Tanggal Check In: "; getline(cin >> ws, checkin[i]);
                cout << "Tanggal Check Out : "; getline(cin >> ws, checkout[i]);
                cout << "Lama Menginap : "; cin >> lamaInap[i];
                cout << "Kode Kamar : "; cin >> pKodeKamar[i];
                FakturTamu(namaTamu, checkin, checkout, namaKamar, pKodeKamar, n, kodeKamar, hargaKamar, lamaInap, totalBayar);                
                cout << namaTamu[n];
                n += 1;
                
                cout << "\n\nLanjut ke tamu berikutnya? (yes/no) : "; cin >> yesno;
                if(yesno == "yes" || yesno == "Yes" || yesno == "YEs" || yesno == "YES" || yesno == "Y" || yesno == "y"){
                    continue;
                }else if(yesno == "no" || yesno == "No" || yesno == "NO" || yesno == "n" || yesno == "N"){
                    break;
                }
            }
            Sleep(1500);
            break;
        case 2:
            system("cls");
            LaporanHarian(namaTamu, checkin, checkout, namaKamar, pKodeKamar, n, kodeKamar, hargaKamar, lamaInap, totalBayar);
            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;
}