You are on page 1of 4

#include <iostream>

#include <string>
#include <iomanip>
#include <map>
using namespace std;

// Function to calculate total amount


int calculateTotal(int days, int price) {
return days * price;
}

// Function to calculate pajak


float calculatePajak(int total) {
return total * 0.11; // Use floating-point numbers for accurate calculation
}

// Function to calculate total amount after pajak


int calculateTotalAfterPajak(int total, float pajak) {
return total + static_cast<int>(pajak); // Cast pajak to int for consistency
}

// Function to calculate potongan


int calculatePotongan(int total, string kodePromo) {
static const map<string, int> promoDiscounts = {
{"HEMAT01", 10},
{"HEMAT02", 15},
{"HEMAT03", 20}
};

int potongan = 0;
auto it = promoDiscounts.find(kodePromo);
if (it != promoDiscounts.end()) {
potongan = total * it->second / 100;
}

return potongan;
}

// Function to print transaction details


void printTransaction(string namaPenyewa, string tanggalMenyewa, int days, string kodeMobil,
string namaMobil, int price,
int subtotal, float pajak, int totalAfterPajak, string kodePromo, int potongan, int total)
{
cout << "\nData Transaksi Pembayaran Rental di RENTAL FTI UNISKA\n";
cout << "Nama Penyewa\t\t:" << namaPenyewa << endl;
cout << "Tanggal Menyewa\t\t:" << tanggalMenyewa << endl;
cout << "Lama Menyewa\t\t:" << days << endl;
cout << "Kode Mobil\t\t:" << kodeMobil << endl;
cout << "Nama Mobil\t\t:" << namaMobil << endl;
cout << "Biaya Per Hari\t\t:" << price << endl;
cout << "Subtotal\t\t:" << subtotal << endl;
cout << "Pajak 11%\t\t:" << static_cast<int>(pajak) << endl; // Cast pajak to int for consistency
cout << "Total Setelah Pajak\t:" << totalAfterPajak << endl;
cout << "Kode Promo\t\t:" << kodePromo << endl;
cout << "Potongan\t\t:" << potongan << endl;
cout << "Total Keseluruhan\t:" << total << endl;
}

int main() {
int loginAttempts = 3;
string username, password;
int totalAfterPajak = 0; // Declare totalAfterPajak outside the case 1 block

while (loginAttempts > 0) {


cout << "===========================\n";
cout << "Silahkan Login Untuk masuk ke sistem\n";
cout << "Input Username: ";
cin >> username;
cout << "Input Password: ";
cin >> password;

if (username == "admin" && password == "admin1") {


cout << "Login berhasil! Selamat datang, Admin.\n";
break;
} else {
cout << "Username dan Password Salah: Silahkan Ulangi!\n";
loginAttempts--;
cout << "Kesempatan Mengulang: " << loginAttempts << " kali\n";
}
}

if (loginAttempts == 0) {
cout << "Anda telah mencapai batas maksimal percobaan login. Program berhenti.\n";
return 0;
}

int menu;
string namaPenyewa, kodeMobil, namaMobil, tanggalMenyewa, kodePromo;
int days, price, total = 0, subtotal, potongan;
float pajak;
bool continueProgram = true;

while (continueProgram) {
cout << "===========================\n";
cout << "Menu Utama :\n";
cout << "1. Input Transaksi\n";
cout << "2. Cetak Transaksi Terakhir\n";
cout << "3. Keluar\n";
cout << "Input Menu [1-3]: ";
cin >> menu;

// Implementasi case-case menu


switch (menu) {
case 1: {
// Input Transaksi
cout << "===========================\n";
cout << "Input Nama Penyewa: ";
cin >> namaPenyewa;
cout << "Input Kode Mobil: ";
cin >> kodeMobil;
cout << "Input Lama Menyewa: ";
cin >> days;
cout << "Input Tanggal Menyewa: ";
cin >> tanggalMenyewa;

// Perform branching to get the price based on the kodeMobil


if (kodeMobil == "MPV-1") {
namaMobil = "Toyota Avanza 2015";
price = 300000;
} else if (kodeMobil == "MPV-2") {
namaMobil = "Daihatsu Xenia 2016";
price = 320000;
} else if (kodeMobil == "CTY-1") {
namaMobil = "Daihatsu Ayla 2017";
price = 230000;
} else if (kodeMobil == "CTY-2") {
namaMobil = "Honda Brio 2015";
price = 250000;
} else if (kodeMobil == "HMPV-1") {
namaMobil = "Toyota Alphard 2015";
price = 1200000;
} else {
cout << "Kode Mobil tidak valid.\n";
continue;
}

// Calculate Data
subtotal = calculateTotal(days, price);
pajak = calculatePajak(subtotal);
totalAfterPajak = calculateTotalAfterPajak(subtotal, pajak);

// Additional input for kodePromo


cout << "Input Kode Promo (HEMAT01, HEMAT02, HEMAT03): ";
cin >> kodePromo;

// Calculate Potongan
potongan = calculatePotongan(totalAfterPajak, kodePromo);

// Update Total
total = totalAfterPajak - potongan;

// Output Data
printTransaction(namaPenyewa, tanggalMenyewa, days, kodeMobil, namaMobil, price,
subtotal, pajak, totalAfterPajak, kodePromo, potongan, total);
break;
}
case 2:
// Cetak Transaksi Terakhir
if (total == 0) {
cout << "===========================\n";
cout << "Belum Ada Data Transaksi Pembayaran.\n";
} else {
cout << "===========================\n";
cout << "Data Transaksi Terakhir:\n";
printTransaction(namaPenyewa, tanggalMenyewa, days, kodeMobil, namaMobil,
price, subtotal, pajak, totalAfterPajak, kodePromo, potongan, total);
}
break;

case 3:
// Keluar
cout << "===========================\n";
cout << "Program Berhenti.\n";
continueProgram = false;
break;

default:
cout << "Menu tidak valid.\n";
break;
}

// Ask if the user wants to continue


char c;
cout << "Ulang lagi(y/t): ";
cin >> c;
if (toupper(c) == 'T') {
continueProgram = false;
}
}

return 0;
}

You might also like