Laman

Senin, 10 Agustus 2015

Program Grosir Lele - C++ (Abstract - Interface - Innerclass - Enkapsulasi)


Program Grosir Lele berikut saya posting untuk memenuhi tugas UAS Semester 4 mata kuliah OOP 2. Program terdiri dari beberapa class dengan masing-masing type OOP.

Kodingnya sebagai berikut :


#include <iostream>

using namespace std;

class rinci_interface
{
    void perkg();
};

class rinci : rinci_interface
{
    public :

    int hargaperkg;
    int kode;

    virtual void perkg()
    {
        if (kode == 1)
        {
            cout<<"Isi 12 ekor per KG"<<endl;
        }
        else if (kode == 2)
        {
            cout<<"Isi 8 ekor per KG"<<endl;
        }
        else if (kode == 3)
        {
            cout<<"Isi 5 ekor per KG"<<endl;
        }

    }

    class umurikan
    {
        public :

        void umur(int kode)
        {
            if (kode == 1)
            {
                cout<<"Umur 4 Bulan"<<endl;
            }
            else if (kode == 2)
            {
                cout<<"Umur 8 Bulan"<<endl;
            }
            else if (kode == 3)
            {
                cout<<"Umur 10 Bulan"<<endl;
            }
        }
    };
};

class total_abstract
{
    public :

    void totalh_abstract (int jumlahkg, int kode);
};

class totalh : total_abstract
{
    public :

    int totalhrg;

    virtual void totalh_abstract (int jumlahkg, int kode)
    {
        int hargaperkg = 0;

        if (kode == 1)
        {
            hargaperkg = 6000;
        }
        else if (kode == 2)
        {
            hargaperkg = 10000;
        }
        else if (kode == 3)
        {
            hargaperkg = 12000;
        }

        totalhrg = hargaperkg * jumlahkg;
    }
};

class diskon_enkapsulasi
{
    public :

    int jdiskon;

    void Setdisk(int value)
    {
        if (value < 500000)
        {
            value = value * 5 / 100;
        }

        else if (value >= 500000 && value < 1000000)
        {
            value = value * 10 / 100;
        }

        else if (value >= 1000000 && value < 5000000)
        {
            value = value * 15 / 100;
        }

        else if (value >= 5000000)
        {
            value = value * 20 / 100;
        }

        jdiskon = value;
    }

    int Getdisk()
    {
        return jdiskon;
    }
};

int main()
{
    rinci rc;
    int berat;

    cout<<"Penjualan Ikan Lele Grosir"<<endl;
    cout<<"Masukkan kode 1, 2 atau 3 : ";
    cin>>rc.kode;
    cout<<"Masukkan Berat Pesanan : ";
    cin>>berat;
    cout<<rc.kode;

    rc.perkg ();

    rinci::umurikan ui = rinci::umurikan();
    ui.umur (rc.kode);

    totalh th;
    th.totalh_abstract(berat,rc.kode);

    cout<<"Harga Awal : Rp "<<th.totalhrg<<endl;

    diskon_enkapsulasi dsk;
    dsk.Setdisk(th.totalhrg);

    cout<<"Dapat Diskon : Rp "<<dsk.Getdisk()<<endl;
    cout<<"Harga Akhir : Rp "<<th.totalhrg - dsk.Getdisk()<<endl;

    return 0;
}
Program memang sangat sederhana, namun terdiri dari berbagai teknik pemrograman dalam object oriented programing. Mohon koreksi.

Gambarnya sebagai berikut :

contoh abstract oop, contoh enkapsulasi, contoh inner class, contoh interface, enkapsulasi oop 2, oo, oop innerclass, oop2

Tidak ada komentar: