Membuat Aplikasi Rental Mobil Sederhana dengan C++ menggunakan Linked List

Bahasa pemrograman C++ adalah salah satu bahasa pemrograman yang paling sering digunakan untuk belajar dasar-dasar pemrograman disamping penggunaan bahasa pascal.
Bahasa sering digunakan karena kecepatan prosesnya yang super-super cepat. Dapat diibaratkan, bahasa C++ adalah seorang pelari sprinter yang mampu berlari sangat cepat tanpa takut didahului oleh lawan.
Bahasa C++ biasa digunakan untuk membuat berbagai aplikasi yang basisnya teks (TUI), biasanya program yang dibangun menggunakan bahasa C++ tampilannya memang tidak terlalu menarik karena hanya hitam putih, namun untuk kecepatan, tidak bisa diragukan.
Beberapa aplikasi yang bisa dibangun secara mudah dengan bahasa C++ adalah seperti kalkulator, ataupun yang lain.
Kali ini, Baris Koding ingin berbagi syntax untuk membuat aplikasi rental mobil bernama "Simply Rent Car". Aplikasi ini dibangun cukup kompleks untuk menangani berbagai proses yang terjadi pada peminjaman mobil, seperti untuk mengelola mobil, mengelola karyawan, mengelola peminjaman, hinga mengelola data konsumen.
Pada aplikasi ini, diterapkan pengunaan struktur data bertipe linked list, konsep linked list sendiri adalah sebuah tipe data dimana tipe data tersebut memiliki dua bagian yaitu bagian info yang memuat nilai dari data tersebut, dan bagian next yang berisi alamat memori dari data selanjutnya.
Nah, bagaimana baris kodingnya? Ini dia.

#include <cstring>
#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

struct mobil
{
    string noTNKB;
    string merk;
    string warna;
    string tahun;
    int tarif;
    bool status;
};

struct driver
{
    string KTP;
    string nama;
    string alamat;
    string usia;
    bool status;
};

struct konsumen
{
    string KTP;
    string nama;
    string alamat;
};

struct sewa
{
    string nama;
    string alamat;
    string TNKB;
    string namadriver;
    int harimasuk;
    int bulanmasuk;
    int tahunmasuk;
    int harikeluar;
    int bulankeluar;
    int tahunkeluar;
    int harireal;
    int bulanreal;
    int tahunreal;
    int denda;
    int totalbiaya;
};

typedef mobil infotypeMobil;
typedef struct tNodeMobil *addressMobil;
typedef struct tNodeMobil
{
 infotypeMobil Info;
 addressMobil Next;
}NodeMobil;
typedef NodeMobil *ListMobil;

typedef driver infotypeDriver;
typedef struct tNodeDriver *addressDriver;
typedef struct tNodeDriver
{
 infotypeDriver Info;
 addressDriver Next;
}NodeDriver;
typedef NodeDriver *ListDriver;

typedef konsumen infotypeKonsumen;
typedef struct tNodeKonsumen *addressKonsumen;
typedef struct tNodeKonsumen
{
 infotypeKonsumen Info;
 addressKonsumen Next;
}NodeKonsumen;
typedef NodeKonsumen *ListKonsumen;

typedef sewa infotypeSewa;
typedef struct tNodeSewa *addressSewa;
typedef struct tNodeSewa
{
 infotypeSewa Info;
 addressSewa Next;
}NodeSewa;
typedef NodeSewa *ListSewa;

void loading();
void TambahMobil(ListMobil &L, addressMobil P);
void CreateEmptyMobil(ListMobil &L);
bool IsEmptyMobil(ListMobil L);
bool IsOneElmtMobil(ListMobil L);
addressMobil AlokasiMobil(infotypeMobil X);
void PrintInfoMobil(ListMobil L,int i);
void PrintInfoMobilAvailable(ListMobil L,int i,int &nomor);
void TampilData(mobil Data,int i);
bool IsAvailableMobil(ListMobil L);
void TambahDriver(ListDriver &L, addressDriver P);
void CreateEmptyDriver(ListDriver &L);
bool IsEmptyDriver(ListDriver L);
bool IsOneElmtDriver(ListDriver L);
addressDriver AlokasiDriver(infotypeDriver X);
void PrintInfoDriver(ListDriver L, int i);
void PrintInfoDriverAvailable(ListDriver L, int i, int &iterasi);
void TampilDataDriver(driver Data, int i);
bool IsAvailableDriver(ListDriver L);
void TambahKonsumen(ListKonsumen &L, addressKonsumen P);
void CreateEmptyKonsumen(ListKonsumen &L);
bool IsEmptyKonsumen(ListKonsumen L);
bool IsOneElmtKonsumen(ListKonsumen L);
addressKonsumen AlokasiKonsumen(infotypeKonsumen X);
void PrintInfoKonsumen(ListKonsumen L, int i, int &iterasi);
void TampilDataKonsumen(konsumen Data, int i);
void TambahSewa(ListSewa &L, addressSewa P);
void CreateEmptySewa(ListSewa &L);
bool IsEmptySewa(ListSewa L);
bool IsOneElmtSewa(ListSewa L);
addressSewa AlokasiSewa(infotypeSewa X);
void PrintInfoSewa(ListSewa L, int i);
void TampilDataSewa(sewa Data, int i);
void pilihkonsumen(int no, ListKonsumen dafKonsumen, sewa &X);
void pilihdriver(int no, ListDriver dafDriver, sewa &X);
void pilihmobil(int no, ListMobil dafMobil, sewa &X);
void ubahStatusMobil(sewa X, ListMobil &L);
void ubahStatusDriver(sewa X, ListDriver &L);
void DapatkanData(int no, ListSewa Data, sewa &X);
int hitungHari(int first_date_month,int first_date_days,int first_date_year,int second_date_month,int second_date_days,int second_date_year);
int dapatkanHargaSewa(string TNKB,ListMobil L);
void simpanTransaksiSelesai(ListSewa &L, sewa Data);

int main()
{
    system("MODE CON COLS=100");
    addressMobil simpulbarumobil;
    ListMobil DaftarMobil;
    mobil DataMobil;
    CreateEmptyMobil(DaftarMobil);
    addressDriver simpulbarudriver;
    ListDriver DaftarDriver;
    driver DataDriver;
    CreateEmptyDriver(DaftarDriver);
    addressKonsumen simpulbaruKonsumen;
    ListKonsumen DaftarKonsumen;
    konsumen DataKonsumen;
    CreateEmptyKonsumen(DaftarKonsumen);
    addressSewa simpulbaruSewa;
    ListSewa DaftarSewa;
    sewa DataSewa;
    CreateEmptySewa(DaftarSewa);
    char pilihan;
    int nomor,haritelat,iterasi,haritotal,harikembali;
    loading();
    menuUtama:
        system("cls");
        cout<<"\n======================================";
        cout<<"\n          SIMPLY RENT A CAR";
        cout<<"\n======================================";
        cout<<"\n\nMenu:";
        cout<<"\n1. Kelola Mobil";
        cout<<"\n2. Kelola Driver";
        cout<<"\n3. Kelola Konsumen";
        cout<<"\n4. Kelola Penyewaan";
        cout<<"\n0. Keluar";
        cout<<"\n\n\nMasukkan pilihan menu: ";
        cin>>pilihan;
        switch(pilihan)
        {
            case '0':
                exit(0);
            case '1':
                menuMobil:
                    system("cls");
                    cout<<"\n======================================";
                    cout<<"\n          SIMPLY RENT A CAR";
                    cout<<"\n======================================";
                    cout<<"\n          Pengelolaan Mobil";
                    cout<<"\n\nMenu:";
                    cout<<"\n1. Tambah Mobil";
                    cout<<"\n2. Tampilkan Mobil";
                    cout<<"\n0. Kembali Ke Menu Utama";
                    cout<<"\n\n Masukkan Pilihan menu: ";
                    cin>>pilihan;
                    switch(pilihan)
                    {
                        case '0':
                            goto menuUtama;
                        case '1':
                            system("cls");
                            cout<<"\n======================================";
                            cout<<"\n          SIMPLY RENT A CAR";
                            cout<<"\n======================================";
                            cout<<"\n          Tambah Data Mobil";
                            cout<<"\n\nMasukkan Nomor TNKB    : ";
                            cin>>DataMobil.noTNKB;
                            cout<<"Masukkan Merk          : ";
                            cin>> DataMobil.merk;
                            cout<<"Masukkan Warna         : ";
                            cin>>DataMobil.warna;
                            cout<<"Masukkan Tahun         : ";
                            cin>>DataMobil.tahun;
                            cout<<"Masukkan Tarif         : Rp.";
                            cin>>DataMobil.tarif;
                            DataMobil.status=TRUE;
                            simpulbarumobil=AlokasiMobil(DataMobil);
                            TambahMobil(DaftarMobil,simpulbarumobil);
                            cout<<"\n\n\nData Untuk Mobil "<<DataMobil.merk<<" Berwarna "<<DataMobil.warna<<" Sudah Ditambahkan";
                            cout<<"\n\nPress any key to continue...";
                            getch();
                            goto menuMobil;
                        case '2':
                            system("cls");
                            cout<<"\n======================================";
                            cout<<"\n          SIMPLY RENT A CAR";
                            cout<<"\n======================================";
                            cout<<"\n        Menampilkan Data Mobil";
                            cout<<"\n\n";
                            cout<<"=================================================================================================\n";
                            cout<<"|No\t|NO TNKB\t|Merk\t\t|Tahun\t|Tarif[Rp.]\t|Warna\t\t|Ketersediaan\t|\n";
                            cout<<"=================================================================================================\n";
                            PrintInfoMobil(DaftarMobil,0);
                            cout<<"=================================================================================================\n";
                            cout<<"\n\nPress any key to continue...";
                            getch();
                            goto menuMobil;
                        default:
                            cout<<"Pilihan Salah";
                            cout<<"\n\nPress any key to continue...";
                            getch();
                            goto menuMobil;
                    }
            case '2':
                menuDriver:
                    system("cls");
                    cout<<"\n======================================";
                    cout<<"\n          SIMPLY RENT A CAR";
                    cout<<"\n======================================";
                    cout<<"\n          Pengelolaan Driver";
                    cout<<"\n\nMenu:";
                    cout<<"\n1. Tambah Driver";
                    cout<<"\n2. Tampilkan Driver";
                    cout<<"\n0. Kembali Ke Menu Utama";
                    cout<<"\n\n Masukkan Pilihan menu: ";
                    cin>>pilihan;
                    switch(pilihan)
                    {
                        case '0':
                            goto menuUtama;
                        case '1':
                            system("cls");
                            cout<<"\n======================================";
                            cout<<"\n          SIMPLY RENT A CAR";
                            cout<<"\n======================================";
                            cout<<"\n          Tambah Data Driver";
                            cout<<"\n\nNama\t\t: ";
                            cin>>DataDriver.nama;
                            cout<<"No KTP\t\t: ";
                            cin>> DataDriver.KTP;
                            cout<<"Alamat\t\t: ";
                            cin>>DataDriver.alamat;
                            cout<<"Usia\t\t: ";
                            cin>>DataDriver.usia;
                            DataDriver.status=TRUE;
                            simpulbarudriver=AlokasiDriver(DataDriver);
                            TambahDriver(DaftarDriver,simpulbarudriver);
                            cout<<"\n\nData Driver baru Atas Nama "<<DataDriver.nama<<" Telah Ditambahkan";
                            cout<<"\n\nPress any key to continue...";
                            getch();
                            goto menuDriver;
                        case '2':
                            system("cls");
                            cout<<"\n======================================";
                            cout<<"\n          SIMPLY RENT A CAR";
                            cout<<"\n======================================";
                            cout<<"\n          Tampil Data Driver\n\n";
                            cout<<"=================================================================================\n";
                            cout<<"|NO\t|No KTP\t\t\t|Nama\t|Alamat\t\t|Usia\t|Status\t\t|\n";
                            cout<<"=================================================================================\n";
                            PrintInfoDriver(DaftarDriver,0);
                            cout<<"=================================================================================\n";
                            cout<<"\n\nPress any key to continue...";
                            getch();
                            goto menuDriver;
                        default:
                            cout<<"Pilihan Salah!";
                            cout<<"\n\nPress any key to continue...";
                            getch();
                            goto menuDriver;
                    }
            case '3':
                MenuKonsumen:
                    system("cls");
                    cout<<"\n======================================";
                    cout<<"\n          SIMPLY RENT A CAR";
                    cout<<"\n======================================";
                    cout<<"\n          Pengelolaan Konsumen";
                    cout<<"\n\nMenu:";
                    cout<<"\n1. Tambah Konsumen";
                    cout<<"\n2. Tampilkan Konsumen";
                    cout<<"\n0. Kembali Ke Menu Utama";
                    cout<<"\n\n Masukkan Pilihan menu: ";
                    cin>>pilihan;
                    switch(pilihan)
                    {
                        case '0':
                            goto menuUtama;
                        case '1':
                            system("cls");
                            cout<<"\n======================================";
                            cout<<"\n          SIMPLY RENT A CAR";
                            cout<<"\n======================================";
                            cout<<"\n         Tambah Data Konsumen\n\n";
                            cout<<"Nama      : ";
                            cin>>DataKonsumen.nama;
                            cout<<"No KTP    : ";
                            cin>> DataKonsumen.KTP;
                            cout<<"Alamat    : ";
                            cin>>DataKonsumen.alamat;
                            simpulbaruKonsumen=AlokasiKonsumen(DataKonsumen);
                            TambahKonsumen(DaftarKonsumen,simpulbaruKonsumen);
                            cout<<"\n\nData Konsumen atas nama "<<DataKonsumen.nama<<" Sudah ditambahkan";
                            cout<<"\n\nPress any key to continue...";
                            getch();
                            goto MenuKonsumen;
                        case '2':
                            system("cls");
                            cout<<"\n======================================";
                            cout<<"\n          SIMPLY RENT A CAR";
                            cout<<"\n======================================";
                            cout<<"\n         Tampil Data Konsumen\n\n";
                            cout<<"=========================================================";
                            cout<<"\n|No\t|Nama\t|No KTP\t\t\t|Alamat\t\t|\n";
                            cout<<"=========================================================\n";
                            if(!IsEmptyKonsumen(DaftarKonsumen))
                            PrintInfoKonsumen(DaftarKonsumen,0,iterasi);
                                else
                                cout<<"|             K   O   S   O   N   G                     |\n";
                            cout<<"=========================================================\n";
                            cout<<"\n\nPress any key to continue...";
                            getch();
                            goto MenuKonsumen;
                        default:
                            cout<<"Pilihan salah!";
                            cout<<"\n\nPress any key to continue...";
                            getch();
                            goto MenuKonsumen;
                    }
            case '4':
                MenuSewa:
                    system("cls");
                    cout<<"\n======================================";
                    cout<<"\n          SIMPLY RENT A CAR";
                    cout<<"\n======================================";
                    cout<<"\n          Pengelolaan Sewa";
                    cout<<"\n\nMenu:";
                    cout<<"\n1. Peminjaman Mobil";
                    cout<<"\n2. Pengembalian Mobil";
                    cout<<"\n3. Tampilkan Rekap Sewa";
                    cout<<"\n0. Kembali ke menu utama";
                    cout<<"\n\n Masukkan Pilihan menu: ";
                    cin>>pilihan;
                    switch(pilihan)
                    {
                        case '0':
                            goto menuUtama;
                        case '1':
                            system("cls");
                            cout<<"\n======================================";
                            cout<<"\n          SIMPLY RENT A CAR";
                            cout<<"\n======================================";
                            cout<<"\n          Peminjaman Sewa";
                            if(!IsAvailableMobil(DaftarMobil))
                            {
                                if(!IsEmptyMobil(DaftarMobil))
                                cout<<"\n\nSemua Mobil telah disewa!\nMasukkan Data Terlebih Dahulu";
                                else
                                    cout<<"\n\nTidak Ada Data Mobil!\nMasukkan Data Terlebih Dahulu";
                                cout<<"\n\nPress any key to continue...";
                                getch();
                                goto MenuSewa;
                                }
                            if(IsEmptyKonsumen(DaftarKonsumen))
                            {
                                cout<<"\n\nData Konsumen tidak ada!!\nMasukkan Data Terlebih Dahulu";
                                cout<<"\n\nPress any key to continue...";
                                getch();
                                goto MenuSewa;
                                }
                            if(!IsAvailableDriver(DaftarDriver))
                            {
                                cout<<"\n\nTidak Ada Driver Yang Tersedia!!\nIngin tanpa driver? (Y/N)";
                                cin>>pilihan;
                                if(pilihan=='n'||pilihan=='N')
                                {
                                    cout<<"Kembali ke menu sewa!";
                                    cout<<"\n\nPress any key to continue...";
                                    getch();
                                    goto MenuSewa;
                                }
                                DataSewa.namadriver="-";
                            };
                            cout<<"\n\n1. Pilih Konsumen\n";
                            cout<<"=========================================================";
                            cout<<"\n|No\t|Nama\t|No KTP\t\t\t|Alamat\t\t|\n";
                            cout<<"=========================================================\n";
                            if (!IsEmptyKonsumen(DaftarKonsumen))
                                {
                                    PrintInfoKonsumen(DaftarKonsumen,0,iterasi);
                                    cout<<"=========================================================\n";
                                }
                            else
                                {
                                    cout<<"|                K   O   S   O   N   G                  |";
                                    cout<<"\n=========================================================\n";
                                    cout<<"\n\nMasukkan dahulu nama konsumen di Pengolahan Konsumen";
                                    getch();
                                    goto menuUtama;
                                }
                            do{
                                cout<<"Masukkan nomor Konsumen (0 untuk batal): ";
                                cin>>nomor;
                                }while (nomor>iterasi);
                            if (nomor==0)
                                goto MenuSewa;
                            pilihkonsumen(nomor, DaftarKonsumen, DataSewa);
                            cout<<"\nKonsumen yang akan meminjam mobil adalah: "<<DataSewa.nama;
                            cout<<"\n\n2. Pilih Mobil\n";
                            cout<<"=================================================================================================\n";
                            cout<<"|No\t|NO TNKB\t|Merk\t\t|Tahun\t|Tarif[Rp.]\t|Warna\t\t|Ketersediaan\t|\n";
                            cout<<"=================================================================================================\n";
                            if(!IsEmptyMobil(DaftarMobil))
                            {
                                if(IsAvailableMobil(DaftarMobil))
                                {
                                    PrintInfoMobilAvailable(DaftarMobil,0, iterasi);
                                    cout<<"=================================================================================================\n";
                                }
                                else
                                {
                                    cout<<"|                               T I D A K   A D A   Y A N G   T E R S E D I A                   |";
                                    cout<<"\n=================================================================================================\n";
                                    getch();
                                    goto MenuSewa;
                                }
                            }
                            else
                                {
                                    cout<<"|                                     K O S O N G                                               |\n";
                                    cout<<"\n=================================================================================================\n";
                                    getch();
                                    goto MenuSewa;
                                }
                                do{
                                    if(nomor>iterasi)
                                    cout<<"\nTidak Ada Mobil dengan nomor urut tersebut! Ulangi lagi!";
                                    cout<<"\n\nMasukkan Nomor Mobil (0 untuk batal): ";
                                    cin>>nomor;
                                } while (nomor>iterasi);
                            if(nomor==0)
                                goto MenuSewa;
                            pilihmobil(nomor, DaftarMobil, DataSewa);
                            cout<<"\nMobil yang dipilih ber-PLAT NOMOR: ="<<DataSewa.TNKB;
                            if(IsAvailableDriver(DaftarDriver))
                                {
                                    cout<<"\n\n3.Pilih Driver";
                                    cout<<"\nApakah hendak menyewa driver? (y/n)";
                                    cin>>pilihan;
                                    if(pilihan=='y' || pilihan =='Y')
                                        {
                                            cout<<"=================================================================================\n";
                                            cout<<"|NO\t|No KTP\t\t\t|Nama\t|Alamat\t\t|Usia\t|Status\t\t|\n";
                                            cout<<"=================================================================================\n";
                                            if(!IsEmptyDriver(DaftarDriver))
                                            {
                                                if(IsAvailableDriver(DaftarDriver))
                                                {
                                                    PrintInfoDriverAvailable(DaftarDriver,0,iterasi);
                                                    cout<<"=================================================================================\n";
                                                }
                                                else
                                                {
                                                    cout<<"|                    T I D A K   A D A   Y A N G   T E R S E D I A                |";
                                                    cout<<"\n=================================================================================\n";
                                                    getch();
                                                    goto MenuSewa;
                                                }
                                            }
                                            else
                                                {
                                                    cout<<"|                                     K O S O N G                                |";
                                                    cout<<"\n=================================================================================\n";
                                                    getch();
                                                    goto MenuSewa;
                                                }
                                            do{
                                                cout<<"Masukkan nomor Driver(0 untuk batal): ";
                                                cin>>nomor;
                                                }while (nomor>iterasi);
                                            if(nomor==0)
                                                goto MenuSewa;
                                            pilihdriver(nomor, DaftarDriver, DataSewa);
                                            cout<<"\nSopir yang dipilih adalah: "<<DataSewa.namadriver;
                                        }
                                        else
                                        {
                                            DataSewa.namadriver="-";
                                        }
                                }
                            cout<<"\n\n4. Masukkan tanggal sewa (HH BB TTTT): ";
                            cin>>DataSewa.harimasuk>>DataSewa.bulanmasuk>>DataSewa.tahunmasuk;
                            cout<<"\n\n5. Masukkan tanggal kembali (HH BB TTTT): ";
                            cin>>DataSewa.harikeluar>>DataSewa.bulankeluar>>DataSewa.tahunkeluar;
                            DataSewa.denda=0;
                            DataSewa.totalbiaya=0;
                            DataSewa.harireal=DataSewa.bulanreal=DataSewa.tahunreal=0;
                            system("cls");
                            cout<<"\n======================================";
                            cout<<"\n|         SIMPLY RENT A CAR          |";
                            cout<<"\n======================================";
                            cout<<"\n|        Rangkuman penyewaan         |";
                            cout<<"\n======================================";
                            cout<<"\n|Nama      :"<<DataSewa.nama;
                            cout<<"\n|Alamat    :"<<DataSewa.alamat;
                            cout<<"\n|Plat      :"<<DataSewa.TNKB;
                            if(DataSewa.namadriver!="-")
                            cout<<"\n|Driver    :"<<DataSewa.namadriver;
                            cout<<"\n|Dari      :"<<DataSewa.harimasuk<<"-"<<DataSewa.bulanmasuk<<"-"<<DataSewa.tahunmasuk;
                            cout<<"\n|Hingga    :"<<DataSewa.harikeluar<<"-"<<DataSewa.bulankeluar<<"-"<<DataSewa.tahunkeluar;
                            cout<<"\n======================================";
                            cout<<"\n\nApakah Data Yang Dimasukkan Sudah Benar (Y/N)? \nN untuk kembali ke menu utama dan membatalkan transaksi\nMasukkan Pilihan: ";
                            cin>>pilihan;
                            if(pilihan=='N' || pilihan == 'n')
                                goto MenuSewa;
                            simpulbaruSewa=AlokasiSewa(DataSewa);
                            TambahSewa(DaftarSewa,simpulbaruSewa);
                            ubahStatusMobil(DataSewa,DaftarMobil);
                            if(DataSewa.namadriver!="-")
                            ubahStatusDriver(DataSewa,DaftarDriver);
                            cout<<"\n\nProses penyewaan telah selesai.!";
                            cout<<"\n\nPress any key to continue...";
                            getch();
                            goto MenuSewa;
                        case '2':
                            system("cls");
                            cout<<"\n======================================";
                            cout<<"\n          SIMPLY RENT A CAR";
                            cout<<"\n======================================";
                            cout<<"\n          Pengembalian Sewa";
                            if(IsEmptyKonsumen(DaftarKonsumen)==TRUE)
                            {
                                cout<<"\n\nData penyewa tidak ada!!";
                                cout<<"\n\nPress any key to continue...";
                                getch();
                                goto MenuSewa;
                            };
                            cout<<"\n\n1. Pilih Data Penyewaan\n";
                            cout<<"=================================================================================================\n";
                            cout<<"|No\t|Nama\t|TNKB\t\t|Alamat\t\t|Masuk\t\t|Kembali\t|Status\t\t|\n";
                            cout<<"=================================================================================================\n";
                            if(!IsEmptySewa(DaftarSewa))
                            PrintInfoSewa(DaftarSewa,0);
                            else
                            cout<<"|                    K      O       S       O       N       G                                   |\n";
                            cout<<"=================================================================================================";
                            cout<<"\n\nMasukkan nomor urut sewa: ";
                            cin>>nomor;
                            DapatkanData(nomor,DaftarSewa,DataSewa);
                            cout<<"\n2. Masukkan Tanggal Kembali (HH-BB-TTTT): ";
                            cin>>DataSewa.harireal>>DataSewa.bulanreal>>DataSewa.tahunreal;
                            haritotal=hitungHari(DataSewa.bulanmasuk,DataSewa.harimasuk,DataSewa.tahunmasuk,DataSewa.bulanreal,DataSewa.harireal,DataSewa.tahunreal);
                            harikembali=hitungHari(DataSewa.bulanmasuk,DataSewa.harimasuk,DataSewa.tahunmasuk,DataSewa.bulankeluar,DataSewa.harikeluar,DataSewa.tahunkeluar);
                            haritelat=haritotal-harikembali;
                            if(haritotal!=harikembali)
                            {
                                cout<<"\n\nPemakaian melebihi Hari yang diharuskan.";
                                cout<<"\nTerlambat selama "<<haritelat<<" Hari";
                                cout<<"\nTentukan Besaran Denda/hari: Rp.";
                                cin>>DataSewa.denda;
                                DataSewa.totalbiaya+=DataSewa.denda*haritelat;
                            }
                            DataSewa.totalbiaya+=((haritotal+1)*dapatkanHargaSewa(DataSewa.TNKB,DaftarMobil));
                            if (DataSewa.namadriver!="-")
                                DataSewa.totalbiaya+=200000;
                            system("cls");
                            cout<<"\n======================================";
                            cout<<"\n          SIMPLY RENT A CAR";
                            cout<<"\n======================================";
                            cout<<"\n          REKAP BIAYA";
                            cout<<"\n======================================";
                            cout<<"\nNama konsumen : "<<DataSewa.nama;
                            cout<<"\nno TNKB       : "<<DataSewa.TNKB;
                            cout<<"\nNama Driver   : "<<DataSewa.namadriver;
                            cout<<"\nTanggal Masuk : "<<DataSewa.harimasuk<<"-"<<DataSewa.bulanmasuk<<"-"<<DataSewa.tahunmasuk;
                            cout<<"\nTanggal Keluar: "<<DataSewa.harireal<<"-"<<DataSewa.bulanreal<<"-"<<DataSewa.tahunkeluar;
                            cout<<"\nLama Sewa      : "<<haritotal+1;
                            cout<<"\nBiaya Sewa/hr : "<<dapatkanHargaSewa(DataSewa.TNKB,DaftarMobil);
                            cout<<"\nKeterlambatan : "<<haritelat;
                            cout<<"\nDenda/hari    : "<<DataSewa.denda;
                            cout<<"\n======================================";
                            cout<<"\nTotal Rp.     : "<<DataSewa.totalbiaya;
                            ubahStatusMobil(DataSewa,DaftarMobil);
                            if(DataSewa.namadriver!="-")
                            ubahStatusDriver(DataSewa,DaftarDriver);
                            simpanTransaksiSelesai(DaftarSewa,DataSewa);
                            cout<<"\n\nPress any key to continue...";
                            getch();
                            goto MenuSewa;
                        case '3':
                            system("cls");
                            cout<<"\n======================================";
                            cout<<"\n          SIMPLY RENT A CAR";
                            cout<<"\n======================================";
                            cout<<"\n          Daftar Sewa\n";
                            cout<<"=================================================================================================\n";
                            cout<<"|No\t|Nama\t|TNKB\t\t|Alamat\t\t|Masuk\t\t|Kembali\t|Status\t\t|\n";
                            cout<<"=================================================================================================\n";
                            if(!IsEmptySewa(DaftarSewa))
                            PrintInfoSewa(DaftarSewa,0);
                            else
                            cout<<"|                    K      O       S       O       N       G                                   |\n";
                            cout<<"=================================================================================================";
                            getch();
                            goto MenuSewa;
                        default:
                            cout<<"pilihan salah!";
                            getch();
                            goto MenuSewa;
                    }

            default:
                cout<<"Pilihan Salah";
                getch();
                goto menuUtama;
        }
    return 0;
}

void TambahMobil(ListMobil &L, addressMobil P)
{
    P->Next=L;
    L=P;
}

void CreateEmptyMobil(ListMobil &L)
{
 L = NULL;
}

bool IsAvailableMobil(ListMobil L)
{
    if(IsEmptyMobil(L))
        return FALSE;
    if(L->Info.status==TRUE)
    {
        return TRUE;
    }
    else if (L->Next!=NULL)
    {
        IsAvailableMobil(L->Next);
    }
}

bool IsEmptyMobil(ListMobil L)
{
 return(L == NULL);
}

bool IsOneElmtMobil(ListMobil L)
{
 return(IsEmptyMobil(L->Next));
}

addressMobil AlokasiMobil(infotypeMobil X)
{
 addressMobil P = new(NodeMobil);
 if (P == NULL)
  return NULL;
 else
 {
  P->Info = X;
  P->Next = NULL;
  return P;
 }
}

void PrintInfoMobil(ListMobil L, int i)
{
    i++;
 if (IsEmptyMobil(L))
 {
 }
 else
 {
     TampilData(L->Info,i);
     cout<<endl;
  PrintInfoMobil(L->Next,i);
 }
}

void PrintInfoMobilAvailable(ListMobil L,int i,int &iterasi)
{
 if (IsEmptyMobil(L))
 {
 }
 else
 {
     if(L->Info.status==TRUE)
        {
            i++;
            iterasi=i;
            TampilData(L->Info,i);
            cout<<endl;
        }
        PrintInfoMobilAvailable(L->Next,i,iterasi);
 }
}

void TampilData(mobil Data, int i)
{
    cout<<"|"<<i<<"\t|"<<Data.noTNKB<<"\t|"<<Data.merk<<"\t\t|"<<Data.tahun<<"\t|"<<Data.tarif<<"\t\t|"<<Data.warna<<"\t\t|";
    if (Data.status)
        cout<<"Tersedia\t|";
    else
        cout<<"Disewakan\t|";
}

void TambahDriver(ListDriver &L, addressDriver P)
{
    P->Next=L;
    L=P;
}

void CreateEmptyDriver(ListDriver &L)
{
 L = NULL;
}

bool IsEmptyDriver(ListDriver L)
{
 return(L == NULL);
}

bool IsAvailableDriver(ListDriver L)
{
    if(IsEmptyDriver(L))
        return FALSE;
    if(L->Info.status==TRUE)
    {
        return TRUE;
    }
    else if (L->Next!=NULL)
    {
        IsAvailableDriver(L->Next);
    }
}

bool IsOneElmtDriver(ListDriver L)
{
 return(IsEmptyDriver(L->Next));
}

addressDriver AlokasiDriver(infotypeDriver X)
{
 addressDriver P = new(NodeDriver);
 if (P == NULL)
  return NULL;
 else
 {
  P->Info = X;
  P->Next = NULL;
  return P;
 }
}

void PrintInfoDriver(ListDriver L, int i)
{
    i++;
 if (IsEmptyDriver(L))
 {
 }
 else
 {
     TampilDataDriver(L->Info, i);
  cout<<endl;
  PrintInfoDriver(L->Next, i);
 }
}

void PrintInfoDriverAvailable(ListDriver L, int i, int &iterasi)
{
 if (IsEmptyDriver(L))
 {
 }
 else
 {
     if(L->Info.status==TRUE)
        {
            i++;
            iterasi=i;
            TampilDataDriver(L->Info, i);
            cout<<endl;
        }
        PrintInfoDriverAvailable(L->Next, i, iterasi);
 }
}

void TampilDataDriver(driver Data, int i)
{
    cout<<"|"<<i<<"\t|"<<Data.KTP<<"\t|"<<Data.nama<<"\t|"<<Data.alamat<<"\t|"<<Data.usia<<"\t|";
    if (Data.status)
        cout<<"Tersedia\t|";
    else
        cout<<"Bertugas\t|";
}

void TambahKonsumen(ListKonsumen &L, addressKonsumen P)
{
    P->Next=L;
    L=P;
}

void CreateEmptyKonsumen(ListKonsumen &L)
{
 L = NULL;
}

bool IsEmptyKonsumen(ListKonsumen L)
{
 return(L == NULL);
}

bool IsOneElmtKonsumen(ListKonsumen L)
{
 return(IsEmptyKonsumen(L->Next));
}

addressKonsumen AlokasiKonsumen(infotypeKonsumen X)
{
 addressKonsumen P = new(NodeKonsumen);
 if (P == NULL)
  return NULL;
 else
 {
  P->Info = X;
  P->Next = NULL;
  return P;
 }
}

void PrintInfoKonsumen(ListKonsumen L,int i, int &iterasi)
{

 if (IsEmptyKonsumen(L))
 {
 }
 else
 {
     i++;
     TampilDataKonsumen(L->Info, i);
  cout<<endl;
  PrintInfoKonsumen(L->Next,i,iterasi);
 }
}

void TampilDataKonsumen(konsumen Data, int i)
{
    cout<<"|"<<i<<"\t|"<<Data.nama<<"\t|"<<Data.KTP<<"\t|"<<Data.alamat<<"\t|";
}

void TambahSewa(ListSewa &L, addressSewa P)
{
    P->Next=L;
    L=P;
}

void CreateEmptySewa(ListSewa &L)
{
 L = NULL;
}

bool IsEmptySewa(ListSewa L)
{
 return(L == NULL);
}

bool IsOneElmtSewa(ListSewa L)
{
 return(IsEmptySewa(L->Next));
}

addressSewa AlokasiSewa(infotypeSewa X)
{
 addressSewa P = new(NodeSewa);
 if (P == NULL)
  return NULL;
 else
 {
  P->Info = X;
  P->Next = NULL;
  return P;
 }
}

void PrintInfoSewa(ListSewa L,int i)
{
    i++;
 if (IsEmptySewa(L))
 {
 }
 else
 {
     TampilDataSewa(L->Info, i);
  cout<<endl;
  PrintInfoSewa(L->Next,i);
 }
}

void TampilDataSewa(sewa Data, int i)
{
    cout<<"|"<<i<<"\t|"<<Data.nama<<"\t|"<<Data.TNKB<<"\t|"<<Data.alamat<<"\t|"<<Data.harimasuk<<"-"<<Data.bulanmasuk<<"-"<<Data.tahunmasuk<<"\t|"<<Data.harikeluar<<"-"<<Data.bulankeluar<<"-"<<Data.tahunkeluar;
    if(Data.tahunreal==0 && Data.bulanreal==0 && Data.harireal==0)
    {
        cout<<"\t|BELUM KEMBALI\t|";
    }
    else
        cout<<"\t|SUDAH KEMBALI\t|";
}

void pilihkonsumen(int no, ListKonsumen dafKonsumen, sewa &X)
{
    for (int i=1;i<no;i++)
    {
        dafKonsumen=dafKonsumen->Next;
    }
    X.nama=dafKonsumen->Info.nama;
    X.alamat=dafKonsumen->Info.alamat;
}

void pilihdriver(int no, ListDriver dafDriver, sewa &X)
{
    int i=0;
    while(i<no)
    {
        if (dafDriver->Info.status==TRUE)
            i++;
        if (i<no)
            dafDriver=dafDriver->Next;
    }
    X.namadriver=dafDriver->Info.nama;
}

void pilihmobil(int no, ListMobil dafMobil, sewa &X)
{
    int i=0;
    while (i<no)
        {
            if (dafMobil->Info.status==TRUE)
                i++;
            if(i<no)
                dafMobil=dafMobil->Next;
        }
        X.TNKB=dafMobil->Info.noTNKB;
}

void ubahStatusMobil(sewa X, ListMobil &L)
{
    if (L->Info.noTNKB==X.TNKB)
    {
        if(L->Info.status==TRUE)
        L->Info.status=FALSE;
        else if(L->Info.status==FALSE)
            L->Info.status=TRUE;
    }
    else
    {
        ubahStatusMobil(X, L->Next);
    }
}

void ubahStatusDriver(sewa X, ListDriver &L)
{
    if(L->Info.nama==X.namadriver)
    {
        if(L->Info.status==TRUE)
        L->Info.status=FALSE;
        else if(L->Info.status==FALSE)
            L->Info.status=TRUE;
    }
    else
    {
        ubahStatusDriver(X,L->Next);
    }
}

void DapatkanData(int no, ListSewa Data, sewa &X)
{
    for (int i=1;i<no;i++)
    {
        Data=Data->Next;
    }

    X=Data->Info;
}

int hitungHari(int first_date_month,int first_date_days,int first_date_year,int second_date_month,int second_date_days,int second_date_year)
{
    int days=0;
    int month_days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
    if(first_date_year == second_date_year)
    {
        if(first_date_month == second_date_month)
            days = second_date_days - first_date_days;
        else
        {
            for(int i = first_date_month; i < second_date_month-1;i++)
                days += month_days[i];
            days += month_days[first_date_month-1] - first_date_days + second_date_days;
        }
    }
    else
    {
        for(int i = 0; i < second_date_month-1; i++)
            days += month_days[i];
        for(int i = first_date_month; i < 12; i++)
            days += month_days[i];
        if(second_date_year - first_date_year >= 0)
        days += (second_date_year - first_date_year - 1)*365 +
            month_days[first_date_month-1] - first_date_days + second_date_days;
    }
    return days;
}

int dapatkanHargaSewa(string TNKB,ListMobil L)
{
    if(L->Info.noTNKB==TNKB)
    {
        return L->Info.tarif;
    }
    else
        dapatkanHargaSewa(TNKB,L->Next);
}

void simpanTransaksiSelesai(ListSewa &L, sewa Data)
{
    if (L->Info.TNKB==Data.TNKB)
    {
        L->Info=Data;
    }
    else
    {
        simpanTransaksiSelesai(L->Next, Data);
    }
}

void loading()
{
     system("color 0a");
     cout<<"\n\n\n\tPlease wait\n\n";
     char a=177, b=219;
     cout<<"\t";
     for (int i=0;i<=15;i++)
        cout<<a;
     cout<<"\r";
     cout<<"\t";
     for (int i=0;i<=15;i++)
     {
        cout<<b;
        for (int j=0;j<=1e6;j++);
     }
     system("cls");
}

Nah, itu tadi baris koding untuk aplikasi rental mobil sederhana dengan bahasa C++ semoga bermanfaat

Komentar

Postingan populer dari blog ini

Membuat Counter Sederhana dengan PHP

Kalkulator CASIO Sederhana dengan PHP tanpa Javascript