tugas algo (hampir jadi)

 avatar
mitraKukar01
c_cpp
3 years ago
5.6 kB
7
Indexable
#include <iostream>
#include <locale> //
#include <memory> //
#include <Windows.h> // untuk syntax didalam windows 10
using namespace std;

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\tFaktur\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(int i = 0; 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 = 0;
    system("cls");
    auto thousands = std::make_unique<separate_thousands>();
    std::cout.imbue(std::locale(std::cout.getloc(), thousands.release()));
    cout << "|\t\tLaporan Pendapatan Harian\t\t|\n|\t\t  per tanggal 30 Mei 2022\t\t|" << endl;
    cout << "+---------------------------------------+\n";
    cout << "|\tNama Tamu\t|    Tgl.Check In    |    Tgl.Check Out    |  Lama Menginap  |  Kode Kamar  |  Harga Kamar  |  Diskon  |\tTotal Bayar\t|" << endl;
    cout << "+---------------------------------------+";
    for(int j = 0; j<n;j++){
        cout << "\n|\t" << namaTamu[j] << "\t|    ";
        cout << checkin[j] << "    |    ";
        cout << checkout[j] << "    |  ";
        cout << lamaInap[j] << " Hari  |  ";
        for(int i = 0; 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] << "\t|";
        totalPendapatan += totalBayar[j];
    }
    cout << "\n+---------------------------------------+";
    cout << "\n|\t\t\t\t\tTotal Pendapatan Harian : Rp. " << totalPendapatan << " |\n";
}

int main(){
    // system("COLOR 17");

    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;

    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);                
                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;
}