zamsyh.dev@gmail.com

Simple membuat program tiket bus menggunakan C++ OOP
mail@pastecode.io avatar
unknown
c_cpp
2 years ago
4.6 kB
68
Indexable
Never
#include <cctype>
#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;

/*
    Author: Zamzam Saputra
    Title: Simple Ticket Bus Program Using C++
    Build: C++ OOP (Object Oriented Programming)
*/

class Bus{
    public:
        int price;
        int subtotal;
        int kembalian;

        void header(){
            
            cout << "---------------------------" << endl;
            cout << "Kode: R, S, H" << endl; 
            cout << "Nama Bus: Rosalia, Sinar Jaya, Hiba Utama" << endl;
            cout << "Tujuan & Harga : " << endl;
            cout << "SBY (300000)" << endl;
            cout << "MLG (400000)" << endl;
            cout << "SLO (200000)" << endl;
            cout << "TGL (250000)" << endl;
            cout << "LMP (350000)" << endl;
            cout << "JGY (400000)" << endl;
            cout << "---------------------------" << endl;

        };

        void busConditional(string desc){

            if (desc == "SBY" || desc == "sby"){
                price = 300000;
                cout << "Harga Tiket : " << price << endl;
                cout << "Tujuan : Surabaya" << endl;  
            }else if (desc == "MLG" || desc == "mlg"){
                price = 400000;
                cout << "Harga Tiket : " << price << endl;
                cout << "Tujuan : Malang" << endl;  
            }else if(desc == "SLO" || desc == "slo"){
                price = 200000;
                cout << "Harga Tiket : "<< price << endl;
                cout << "Tujuan : Solo" << endl;  
            }else if(desc == "TGL" || desc == "tgl"){
                price = 250000;
                cout << "Harga Tiket : 250000"<< price << endl;
                cout << "Tujuan : Tegal" << endl;  
            }else if(desc == "LMP" || desc == "lmp"){
                price = 350000;
                cout << "Harga Tiket : 350000" << price << endl;
                cout << "Tujuan : Lampung" << endl;  
            }else if (desc == "JGY" || desc == "jgy")
            {   
                price = 400000;
                cout << "Harga Tiket : 400000" << price << endl;
                cout << "Tujuan : Jogjakarta" << endl;  
            }else{
                cout << "Tidak ada kode tujuan : " << desc << endl;
                exit(0);
            }
        }

        void selectBus(char kodeBus){
            if (kodeBus == 'R' || kodeBus == 'r') 
            {
                cout << "Rosalia";
            }else if(kodeBus == 'S' || kodeBus == 's'){
                cout << "Sinar Jaya";
            }else if(kodeBus == 'H' || kodeBus == 'h'){
                cout << "Hiba Utama";
            }else{
                cout << "Bus Tidak Ada";
                exit(0);
            }
            
        };

  
        void countPrice(int jumlah){
            
            
            int total = price * jumlah;
            int subtotal =  total + ( 0.5 * total / 10);
    
            cout << "Total Harga : " << total << endl;
            if (jumlah >= 3)
            {
                cout << "Hadiah : Jam tangan" << endl;
            }else{
                cout << "Hadiah : " << endl;
            }
            cout << "PPN : 5%" << endl;
            cout << "Total Bayar : " << subtotal << endl;
            
            
            
        }      


            
};







int main(int argc, char const *argv[]){

    int total, subtotal, bayar, harga, kembalian, jumlah;
    char nama[50], kode, ppn, nama_bus;
    string tujuan;
    Bus myObject;

    myObject.header();
    cout << "" << endl;

    cout << "Masukkan Nama Penumpang : ";  cin >> nama;
    cout << "Masukkan Kode Bus [R/S/H] : "; cin >> kode;
    cout << "Masukkan Tujuan Pewasat : "; cin >> tujuan;
    cout << "" << endl;
    cout << "*******************************************" << endl;
    cout << "" << endl;


    cout << "Nama Penumpang : " << nama << endl;
    cout << "Nama Bus : ";  cout << (char) toupper(kode) << " - "; myObject.selectBus(kode); cout << "" << endl;
    myObject.busConditional(tujuan);
    cout << "Masukkan jumlah beli : "; cin >> jumlah;
    cout << "" << endl;
    cout << "*******************************************" << endl;

    myObject.countPrice(jumlah);

    cout << "*******************************************" << endl;

    cout << "Masukkan pembayaran : "; cin >> bayar;
    // cout << "Kembalian : " << bayar - myObject.price * jumlah + (0.5 * myObject.price * jumlah / 10) << endl;
    total = myObject.price * jumlah;
    subtotal =  total + ( 0.5 * total / 10);
    cout << "Kembalian : " << bayar - subtotal << endl;

    return 0;
}