Jumat, 08 April 2016

bab 4

kasus 1 program mencari bil terbesar 

#include <iostream>

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

    class Banding
    {
        friend istream& operator>>(istream&, Banding&);
        public:
        Banding() {};
        void bandingkan()
        {
            int maks = x;
            if (y > maks) maks = y;
            if (z > maks) maks = z;
            cout << endl << endl << "Bilangan terbesar : " << maks;
        }
        private:
        int x, y, z;
    };
    istream& operator>>(istream& in, Banding& bilangan)
    {
        cout << "Bilangan pertama = ";
        cin >> bilangan.x;
        cout << "Bilangan kedua   = ";
        cin >> bilangan.y;
        cout << "Bilangan ketiga  = ";
        cin >> bilangan.z;
        return in;
    };

int main(int argc, char** argv) {

    Banding bilangan;
    cin >> bilangan;
    bilangan.bandingkan();
   
   
    return 0;
}

raptor




















kasus 2 program menghitungpersamaan kuadrat

#include <iostream>
#include <math.h>
#include <conio.h>

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

class Akar {
    friend ostream& operator<<(ostream&, Akar&);
    friend istream& operator>>(istream&, Akar&);
    public:
    Akar();
    int disk() { return B*B-4*A*C; }
    float akar1() {return (-B+sqrt(disk()))/(2*A); }
    float akar2() {return (-B-sqrt(disk()))/(2*A); }
    void hitung_akar();
    void cetak_disk() {
         cout << "diskriminan = " << disk() << endl; }
    void cetak_akar() {
        cout << "x1 = " << akar1() << endl;
        cout << "x2 = " << akar2() << endl;
    }
private:
    int A, B, C; // input
    float x1, x2; // akar 1 dan akar 2
};
ostream& operator<<(ostream& out, Akar& keluaran) {
    keluaran.cetak_disk();
    if (keluaran.disk() >= 0) keluaran.cetak_akar();
    else out << "Akar imajiner";
    return out;
}
istream& operator>>(istream& in, Akar& masukan) {
    cout << "Koefisien pangkat 2 : "; cin >> masukan.A;
    cout << "Koefisien pangkat 1 : "; cin >> masukan.B;
    cout << "Koefisien pangkat 0 : "; cin >> masukan.C;
return in;
}
Akar::Akar() {
    cout << "Menghitung akar persamaan kuadrat "<<endl<<endl;
}

void Akar::hitung_akar() {
    if (A == 0) {
    cout << "bukan pers. kuadrat.\n";
    cout << "Harga akar = " << -C/B; } else {
    if (disk() > 0) {
        x1 = akar1();
        x2 = akar2();
        }   
    else if (disk() == 0) {
        x1 = akar1();
        x2 = x1;
        }
    }   
}

int main(int argc, char** argv) {
    Akar kasus;
    cin >> kasus;
    kasus.hitung_akar();
    cout << kasus;
    return 0;
}

raptor


























kasus 3 program menentukan nilai angka ke huruf
#include <iostream>

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
    int nilai;
   
    cout << " Menentukan Nilai Angka " << endl << endl;
   
    cout << " Masukan Nilai Angka : "; cin >> nilai;
    cout << endl;
   
    switch (nilai)
    {
   
    case 81 ... 100 :
   
        cout << nilai << " Nilai hurufnya adalah A " << endl;
    break;
    case 61 ... 80 :
   
        cout << nilai << " Nilai hurufnya adalah B " << endl;
    break;
    case 41 ... 60 :
   
        cout << nilai << " Nilai hurufnya adalah C " << endl;
    break;
    case 21 ... 40 :
   
        cout << nilai << " Nilai hurufnya adalah D " << endl;
    break;
    case 0 ... 20 :
   
        cout << nilai << " Nilai hurufnya adalah E " << endl;
    break;
}
   
    return 0;
}
raptor


















kasus 5 program
#include <iostream>
#include <conio.h>

using namespace std;

int main(){
   
    int tahun, bulan,bil;

    cout << " Masukkan Tahun    : "; cin >> tahun;
    cout << " Masukkan Bulan ke : "; cin >> bulan;

    switch (bulan)
    {
        case 2:
            if ((tahun%100==0)||(tahun%100!=0)&&(tahun%400==0))
            {
                for(int i=1; i<=29; i++)
                {
                cout<<i<<" ";
                }
            }
            else
            {
                for(int i=1; i<=28; i++)
                {
                    cout<<i<<" ";
                }
            }
        break;

        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
        {
            for(int i=1; i<=31; i++)
            {
                cout<<i<<" ";
            }
        }
        break;

        case 4:
        case 6:
        case 9:
        case 11:
        {
            for(int i=1; i<=30; i++)
            {
                cout<<i<<" ";
            }
        }
        break;
        default:
        cout<<"salah kode bulan\n";
    }
   
getch();
}
raptor 




















kasus 6 program koversi bil menjadi kode ASCII





















kasus 7 program menetukan nilai angka


















raptor

















kasus 8 program memecah uang

#include<iostream>
using namespace std;
int main()
{
    long uang,sisa;
    int u100rb,u50rb,u20rb;
    int u10rb,u5rb,u2rb,u1rb,u5ratus;
    cout<<"    Program Memecah Uang   "<<endl;
    cout<<"______________________________"<<endl;
    cout<<" Masukan Jumlah Uang Rp."; cin>>uang;
   
    u100rb=uang/100000;
    sisa=uang%100000;
   
    u50rb=sisa/50000;
    sisa=sisa%50000;
   
    u20rb=sisa/20000;
    sisa=sisa%20000;
   
    u10rb=sisa/10000;
    sisa=sisa%10000;
   
    u5rb=sisa/5000;
    sisa=sisa%5000;
   
    u2rb=sisa/2000;
    sisa=sisa%2000;
   
    u1rb=sisa/1000;
    sisa=sisa%1000;
   
    u5ratus=sisa/500;
   
    cout << endl <<endl;
    cout <<" Uang anda Rp. "<<uang<<endl;
    cout <<" Terdiri dari  : "<<endl;
    cout <<" _______________ "<<endl;
   
    if (u100rb > 0)
        cout<<u100rb<<" lembar Rp.100.000"<<endl<<endl;
    if (u50rb > 0)
        cout<<u50rb<<" lembar Rp.50.000"<<endl<<endl;
    if (u20rb > 0)
        cout<<u20rb<<" lembar Rp.20.000"<<endl<<endl;
    if (u10rb > 0)
        cout<<u10rb<<" lembar Rp.10.000"<<endl<<endl;
    if (u5rb > 0)
        cout<<u5rb<<" lembar Rp.5.000"<<endl<<endl;
    if (u2rb > 0)
        cout<<u2rb<<" lembar Rp.2.000"<<endl<<endl;
    if (u1rb > 0)
        cout<<u1rb<<" lembar Rp.1.000"<<endl<<endl;
    if (u5ratus > 0)
        cout<<u5ratus<<" keping Rp.500"<<endl<<endl;

}
raptor


























kasus 9 program menampilkan
#include <iostream>


using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
   
    int bulan;
   
    cout << " ___ UANG LEMBUR 2016 ___ " <<endl;
    cout << " ======================== " <<endl<<endl;
    cout << " Uang lembur yang diperoleh pada bulan ke- "; cin >> bulan;
    cout << endl;
    cout << " =================================================== " << endl;
    switch(bulan)
    {
        case 1:
            cout << " --- Januari --- "<<endl;
            int gaji, jam1, jam2;
            float total;
           
            jam1 = 16*8;
            jam2 = 5*3;
            total= jam1+jam2;
            cout << " Jam Kerja Selama Bulan Januari (31 Hari) adalah : "<< total <<" jam"<< endl;
            if (total > 30)
            {
                gaji=(total/5)*30000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;
            }
            else
            {
                gaji=total*4000;   
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;   
            }   
        break;   
        case 2:
            cout << " --- Februari --- "<<endl;
                       
            jam1 = 17*8;
            jam2 = 4*3;
            total= jam1+jam2;
            cout << " Jam Kerja Selama Bulan Februari (29 Hari) adalah : "<< total <<" jam"<< endl;
            if (total > 30)
            {
                gaji=(total/5)*30000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;
            }
            else
            {
                gaji=total*4000;   
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;   
            }   
        break;
        case 3:
            cout << " --- Maret --- "<<endl;
                       
            jam1 = 19*8;
            jam2 = 4*3;
            total= jam1+jam2;
            cout << " Jam Kerja Selama Bulan Maret (31 Hari) adalah : "<< total <<" jam"<< endl;
            if (total > 30)
            {
                gaji=(total/5)*30000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;
            }
            else
            {
                gaji=total*4000;   
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;   
            }   
        break;
        case 4:
            cout << " --- April --- "<<endl;
                       
            jam1 = 16*8;
            jam2 = 5*3;
            total= jam1+jam2;
            cout << " Jam Kerja Selama Bulan April (30 Hari) adalah : "<< total <<" jam"<< endl;
            if (total > 30)
            {
                gaji=(total/5)*30000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;
            }
            else
            {
                gaji=total*4000;   
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;   
            }   
        break;
        case 5:
            cout << " --- Mei --- "<<endl;
           
            jam1 = 18*8;
            jam2 = 4*3;
            total= jam1+jam2;
            cout << " Jam Kerja Selama Bulan Mei (31 Hari) adalah : "<< total <<" jam"<< endl;
            if (total > 30)
            {
                gaji=(total/5)*30000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;
            }
            else
            {
                gaji=total*4000;   
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;   
            }   
        break;
        case 6:
            cout << " --- Juni --- "<<endl;
           
            jam1 = 18*8;
            jam2 = 4*3;
            total= jam1+jam2;
            cout << " Jam Kerja Selama Bulan Juni (30 Hari) adalah : "<< total <<" jam"<< endl;
            if (total > 30)
            {
                gaji=(total/5)*30000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;
            }
            else
            {
                gaji=total*4000;   
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;   
            }   
        break;
        case 7:
            cout << " --- Juli --- "<<endl;
           
            jam1 = 16*8;
            jam2 = 5*3;
            total= jam1+jam2;
            cout << " Jam Kerja Selama Bulan Juli (31 Hari) adalah : "<< total <<" jam"<< endl;
            if (total > 30)
            {
                gaji=(total/5)*30000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;
            }
            else
            {
                gaji=total*4000;   
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;   
            }   
        break;
        case 8:
            cout << " --- Agustus --- "<<endl;
                       
            jam1 = 19*8;
            jam2 = 4*3;
            total= jam1+jam2;
            cout << " Jam Kerja Selama Bulan Agustus (31 Hari) adalah : "<< total <<" jam"<< endl;
            if (total > 30)
            {
                gaji=(total/5)*30000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;
            }
            else
            {
                gaji=total*4000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;   
            }   
        break;
        case 9:
            cout << " --- September --- "<<endl;
                       
            jam1 = 17*8;
            jam2 = 5*3;
            total= jam1+jam2;
            cout << " Jam Kerja Selama Bulan September (30 Hari) adalah : "<< total <<" jam"<< endl;
            if (total > 30)
            {
                gaji=(total/5)*30000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;
            }
            else
            {
                gaji=total*4000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;   
            }
        break;
        case 10:
            cout << " --- Oktober --- "<<endl;
                       
            jam1 = 17*8;
            jam2 = 4*3;
            total= jam1+jam2;
            cout << " Jam Kerja Selama Bulan Oktober (31 Hari) adalah : "<< total <<" jam"<< endl;
            if (total > 30)
            {
                gaji=(total/5)*30000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;
            }
            else
            {
                gaji=total*4000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;   
            }
        break;
        case 11:
            cout << " --- November --- "<<endl;
                       
            jam1 = 18*8;
            jam2 = 4*3;
            total= jam1+jam2;
            cout << " Jam Kerja Selama Bulan November (30 Hari) adalah : "<< total <<" jam"<< endl;
            if (total > 30)
            {
                gaji=(total/5)*30000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;
            }
            else
            {
                gaji=total*4000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;   
            }                                   
        break;
        case 12:
            cout << " --- Desember --- "<<endl;
                       
            jam1 = 17*8;
            jam2 = 5*3;
            total= jam1+jam2;
            cout << " Jam Kerja Selama Bulan Agustus (31 Hari) adalah : "<< total <<" jam"<< endl;
            if (total > 30)
            {
                gaji=(total/5)*30000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;
            }
            else
            {
                gaji=total*4000;
                cout << " Uang Lembur Yang Diperoleh Rp."<<gaji<<endl;   
            }   
        break;
    }
   
   
    return 0;
}
raptor 










































Tidak ada komentar:

Posting Komentar