Pages

Contoh Program C++ Part II

Postingan kali ini saya akan share beberapa contoh program C++

1. Contoh Program Penjualan Kue
-- Listing Program

#include <iostream>
using namespace std;
int main() {
    int jkue,tot,tbay,hkue;
    char nama [30];
    char kode;
string nk;
double diskon;
    cout<<"                                         " << endl;
    cout<<"      DAFTAR MENU TOKO KUE SEDAP        " << endl;
    cout<<" ______ ____________________ ___________ " << endl;
    cout<<"| Kode |    Daftar Kue      |    Harga  |" << endl;
    cout<<"|   1  | Bolu Black Forest  |    60000  |" << endl;
    cout<<"|   2  | Chesse Cake        |    45000  |" << endl;
    cout<<"|   3  | Banana Cake        |    25500  |" << endl;
    cout<<"|   4  | Strawberry Cake    |    35000  |" << endl;
    cout<<"|______|____________________|___________|" << endl;
    cout<<endl;
    cout<<"Nama Pembeli      : " ;cin>>nama;
    cout<<"Kode Kue (1/2/3/4): " ;cin>>kode;
    cout<<"Jumlah Kue        : " ;cin>>jkue;
cout<<"-----------------------------------------"<<endl;
cout<<endl;
cout<<"=====STRUK PEMBAYARAN TOKO KUE SEDAP====="<<endl;
cout<<endl;
  if (kode=='1') {
    hkue=60000;
nk="Bolu Black Forest";
    }
    else if (kode=='2') {
    hkue=45000;
nk="Chesse Cake";
    }
    else if (kode=='3') {
    hkue=25500;
nk="Banana Cake";
    }
    else if (kode=='4') {
    hkue=35000;
nk="Stawberry Cake";
}
 else {
    cout<<"Menu "<<kode<<" tidak ada di daftar menu";
    cout<<endl;
}
 tot=jkue*hkue;
        if (jkue>=20) (diskon=tot*0.2);
if (jkue>=10) (diskon=tot*0.05);
        else (diskon=tot*0);
    tbay=tot-diskon;
    cout << "Nama Pembeli     : " <<nama<< endl;
    cout << "Kode Kue         : " <<kode<< endl;
    cout << "Nama Kue         : " <<nk<< endl;
    cout << "Harga Kue        : Rp." <<hkue<< endl;
    cout << "Jumlah Kue       : " <<jkue<< endl;
    cout << "Total Harga      : Rp." <<tot<<",-"<< endl;
    cout<<"-----------------------------------------"<<endl;
    cout << "Diskon           : Rp." <<diskon<<",-"<< endl;
    cout<<"-----------------------------------------"<<endl;
    cout << "Total Bayar      : Rp." <<tbay<<",-"<< endl;

     return 0;
}

-- Hasil Running


2. Contoh Program Penginapan/Hotel 
-- Listing Program

#include <iostream>
using namespace std;
int main() {
    int durasi,adm,tot,tbay,hk;
    char nam[30];
    char km,kk;
string souv,nk,kt;
    cout<<"                                                               " << endl;
    cout<<"                HOTEL PONDOK INDAH                  " << endl;
    cout<<" ________________________________________________" << endl;
    cout<<"| Kode|  Kamar  | Kelas | Kategori | Harga/Malam |" << endl;
    cout<<"|     | ANYELIR |   1   | VIP      | 350.000     |" << endl;
cout<<"|  A  |         |   2   | KELAS 1  | 250.OOO     |" << endl;
    cout<<"|     |         |   3   | KELAS 2  | 150.000     |" << endl;
cout<<"|_____|_________|_______|__________|_____________|" << endl;
cout<<"|     | CEMPAKA |   1   | VIP      | 350.000     |" << endl;
cout<<"|  C  |         |   2   | KELAS 1  | 250.OOO     |" << endl;
    cout<<"|     |         |   3   | KELAS 2  | 150.000     |" << endl;
cout<<"|_____|_________|_______|__________|_____________|" << endl;
cout<<"|     | MELATI  |   1   | VIP      | 350.000     |" << endl;
cout<<"|  M  | |   2   | KELAS 1  | 250.OOO     |" << endl;
    cout<<"|     |         |   3   | KELAS 2  | 150.000     |" << endl;
    cout<<"|_____|_________|_______|__________|_____________|" << endl;
    cout<<endl;
cout<<"Nama Penyewa      : " ;cin>>nam;
    cout<<"Kode Kamar (A/C/M): " ;cin>>km;
    cout<<"Kode Kelas (1/2/3): " ;cin>>kk;
cout<<"Lama Menginap : " ;cin>>durasi;
cout<<"-----------------------------------------"<<endl;
cout<<endl;
switch (km)
{
case 'a':
case 'A':
cout<<endl;
if (km=='a'||km=='A'||kk=='1');
hk=350000;
adm=75000;
nk="Anyelir";
kt="VIP";
if (km=='a'||km=='A'||kk=='2');
hk=250000;
adm=75000;
nk="Anyelir";
kt="Kelas 1";
if (km=='a'||km=='A'||kk=='3');
hk=150000;
adm=75000;
nk="Anyelir";
kt="Kelas 2";
break;
case 'c':
case 'C':
cout<<endl;
if (km=='c'||km=='C'||kk=='1');
hk=350000;
adm=75000;
nk="Cempaka";
kt="VIP";
if (km=='c'||km=='C'||kk=='2');
hk=250000;
adm=75000;
nk="Cempaka";
kt="Kelas 1";
if (km=='c'||km=='C'||kk=='3');
hk=150000;
adm=75000;
nk="Cempaka";
kt="Kelas 2";
break;
case 'm':
case 'M':
cout<<endl;
if (km=='m'||km=='M'||kk=='1');
hk=350000;
adm=75000;
nk="Mawar";
kt="VIP";
if (km=='m'||km=='M'||kk=='2');
hk=250000;
adm=75000;
nk="Mawar";
kt="Kelas 1";
if (km=='m'||km=='M'||kk=='3');
hk=150000;
adm=75000;
nk="Mawar";
kt="Kelas 2";
break;
default:
    cout<<"Pilihan tidak ada";
    cout<<endl;
}
tot=hk*durasi;
cout << "Nama Penyewa       : " <<nam<< endl;
    cout << "Kode Kamar         : " <<km<< endl;
    cout << "Nama Kamar/Kelas   : "<<nk<<"/"<<kk<<endl;
cout << "Nama Kategori      : "<<kt<<endl;
    cout << "Harga Kamar/malam  : Rp." <<hk<< endl;
    cout << "Lama Menginap      : "<<durasi<<" Hari"<<endl;
    cout << "Total Harga        : Rp." <<tot<<",-"<< endl;
cout << "Biaya Administrasi : Rp."<<adm<<",-"<<endl;

tbay=tot+adm;
if (durasi>=7) (souv="Free Lunch");
else (souv="No Souvenir");
    cout << "Total Bayar        : Rp." <<tbay<<",-"<< endl;
    cout<<"-----------------------------------------"<<endl;
cout << "Souvenir           : "<<souv<<endl;
return 0;
}

-- Hasil Running


3. Contoh Program Penjualan Toko Bunga
-- Listing Program
#include <iostream>
using namespace std;
int main() {
    int durasi,adm,tot,tbay,hk;
    char nam[30];
    char km,kk;
string souv,nk,kt;
    cout<<"                                                               " << endl;
    cout<<"                HOTEL PONDOK INDAH                  " << endl;
    cout<<" ________________________________________________" << endl;
    cout<<"| Kode|  Kamar  | Kelas | Kategori | Harga/Malam |" << endl;
    cout<<"|     | ANYELIR |   1   | VIP      | 350.000     |" << endl;
cout<<"|  A  |         |   2   | KELAS 1  | 250.OOO     |" << endl;
    cout<<"|     |         |   3   | KELAS 2  | 150.000     |" << endl;
cout<<"|_____|_________|_______|__________|_____________|" << endl;
cout<<"|     | CEMPAKA |   1   | VIP      | 350.000     |" << endl;
cout<<"|  C  |         |   2   | KELAS 1  | 250.OOO     |" << endl;
    cout<<"|     |         |   3   | KELAS 2  | 150.000     |" << endl;
cout<<"|_____|_________|_______|__________|_____________|" << endl;
cout<<"|     | MELATI  |   1   | VIP      | 350.000     |" << endl;
cout<<"|  M  | |   2   | KELAS 1  | 250.OOO     |" << endl;
    cout<<"|     |         |   3   | KELAS 2  | 150.000     |" << endl;
    cout<<"|_____|_________|_______|__________|_____________|" << endl;
    cout<<endl;
cout<<"Nama Penyewa      : " ;cin>>nam;
    cout<<"Kode Kamar (A/C/M): " ;cin>>km;
    cout<<"Kode Kelas (1/2/3): " ;cin>>kk;
cout<<"Lama Menginap : " ;cin>>durasi;
cout<<"-----------------------------------------"<<endl;
cout<<endl;
switch (km)
{
case 'a':
case 'A':
cout<<endl;
if (km=='a'||km=='A'||kk=='1');
hk=350000;
adm=75000;
nk="Anyelir";
kt="VIP";
if (km=='a'||km=='A'||kk=='2');
hk=250000;
adm=75000;
nk="Anyelir";
kt="Kelas 1";
if (km=='a'||km=='A'||kk=='3');
hk=150000;
adm=75000;
nk="Anyelir";
kt="Kelas 2";
break;
case 'c':
case 'C':
cout<<endl;
if (km=='c'||km=='C'||kk=='1');
hk=350000;
adm=75000;
nk="Cempaka";
kt="VIP";
if (km=='c'||km=='C'||kk=='2');
hk=250000;
adm=75000;
nk="Cempaka";
kt="Kelas 1";
if (km=='c'||km=='C'||kk=='3');
hk=150000;
adm=75000;
nk="Cempaka";
kt="Kelas 2";
break;
case 'm':
case 'M':
cout<<endl;
if (km=='m'||km=='M'||kk=='1');
hk=350000;
adm=75000;
nk="Mawar";
kt="VIP";
if (km=='m'||km=='M'||kk=='2');
hk=250000;
adm=75000;
nk="Mawar";
kt="Kelas 1";
if (km=='m'||km=='M'||kk=='3');
hk=150000;
adm=75000;
nk="Mawar";
kt="Kelas 2";
break;
default:
    cout<<"Pilihan tidak ada";
    cout<<endl;
}
tot=hk*durasi;
cout << "Nama Penyewa       : " <<nam<< endl;
    cout << "Kode Kamar         : " <<km<< endl;
    cout << "Nama Kamar/Kelas   : "<<nk<<"/"<<kk<<endl;
cout << "Nama Kategori      : "<<kt<<endl;
    cout << "Harga Kamar/malam  : Rp." <<hk<< endl;
    cout << "Lama Menginap      : "<<durasi<<" Hari"<<endl;
    cout << "Total Harga        : Rp." <<tot<<",-"<< endl;
cout << "Biaya Administrasi : Rp."<<adm<<",-"<<endl;

tbay=tot+adm;
if (durasi>=7) (souv="Free Lunch");
else (souv="No Souvenir");
    cout << "Total Bayar        : Rp." <<tbay<<",-"<< endl;
    cout<<"-----------------------------------------"<<endl;
cout << "Souvenir           : "<<souv<<endl;
return 0;
}

-- Hasil Running

4. Contoh Program Rental Mobil 
-- Listing Program

#include <iostream>
using namespace std;
int main()
{
char kode,lagi;
char nama[20];
string mobil;
int durasi,harga,stot,tot,bayar,kmb;
double diskon;
awal:
cout<<"               Rental Mobil    "<<endl;
cout<<"========================================"<<endl;
cout<<"Kode     Jenis Mobil     Hrg Sewa/Hari"<<endl;
cout<<" 1.      Sedan           350000"<<endl;
cout<<" 2.      Mini Bus        500000"<<endl;
cout<<" 3.      Bus             800000"<<endl;
cout<<"========================================"<<endl;
cout<<endl;
cout<<"Nama Penyewa          : ";cin>>nama;
cout<<"Kode Mobil [1/2/3]    : ";cin>>kode;
cout<<"Lama Sewa             : ";cin>>durasi;
cout<<endl;
if (kode=='1'){
harga=350000;
mobil="Sedan";
}
else if (kode=='2'){
harga=500000;
mobil="Mini Bus";
}
else if (kode=='3'){
harga=800000;
mobil="Bus";
}
else {
cout<<"Pilihan Tidak Ada"<<endl;
goto akhir;
}
stot=harga*durasi;
cout<<"Nama Penyewa          : "<<nama<<endl;
cout<<"Kode Mobil [1/2/3]    : "<<kode<<endl;
cout<<"Jenis Mobil           : "<<mobil<<endl;
cout<<"Harga Sewa/hari       : "<<harga<<endl;
cout<<"Lama Sewa             : "<<durasi<<" Hari"<<endl;
cout<<"Sub Total             : "<<stot<<endl;
 if (durasi>=14) (diskon=stot*0.3);
 if (durasi>=7) (diskon=stot*0.2);
 if (durasi>=3) (diskon=stot*0.1);
        else (diskon=stot*0);
cout<<"Diskon                : "<<diskon<<endl;
tot=stot-diskon;
cout<<"Total Bayar           : "<<tot<<endl;
cout<<"========================================="<<endl;
cout<<"Uang Bayar            : ";cin>>bayar;
kmb=bayar-tot;
cout<<"Uang Kembali          : "<<kmb<<endl;
cout<<"========================================="<<endl;
cout<<"Mau Isi Data Lagi?[Y/T]";cin>>lagi;
cout<<endl;
if(lagi=='Y'||lagi=='y')
goto awal;
else
goto akhir;
akhir:
cout<<"Terima Kasih";
return 0;
}

-- Hasil Running

5. Contoh Program Penjualan Koran
-- Listing Program

#include <iostream>
using namespace std;
int main() {
    int harga,ja,jk,jt,tot;
    char kode,lagi;
string nh,hari,agen;
    cout<<"                                         " << endl;
    cout<<"                STRUKTUR KORAN        " << endl;
    cout<<" ______________________________________________ " << endl;
    cout<<"| Kode Harian|    Nama Harian     |    Harga  |" << endl;
    cout<<"|      1     | Kompas             |    4000   |" << endl;
    cout<<"|      2     | Bola               |    6000   |" << endl;
    cout<<"|      3     | Tempo              |    3000   |" << endl;
    cout<<"|____________|____________________|___________|" << endl;
    cout<<endl;
awal:
cout<<"Hari                   : ";cin>>hari;
cout<<"========================================"<<endl;
    cout<<"Nama Agen              : " ;cin>>agen;
    cout<<"Kode Harian (1/2/3)    : " ;cin>>kode;
if (kode=='1'){
nh="Kompas";
harga=4000;
}
else if (kode=='2'){
nh="Bola";
harga=6000;
}
else if (kode=='3'){
nh="Tempo";
harga=3000;
}
else {
cout<<"Maaf Kode Harian "<<kode<<" tidak ada dalam daftar"<<endl;
goto akhir;
}
    cout<<"Jumlah Ambil           : " ;cin>>ja;
cout<<"Jumlah Kembali         : " ;cin>>jk;
cout<<"-----------------------------------------"<<endl;
jt=ja-jk;
tot=jt*harga;
cout<<"            AGEN DISTRIBUTOR KORAN"<<endl;
cout<<"            TRIBUN TIMUR          "<<endl;
cout<<"==========================================="<<endl;
cout<<"Hari            : "<<hari<<endl;
cout<<"Nama Agen       : "<<agen<<endl;
cout<<"==========================================="<<endl;
cout<<"Nama Harian     : "<<nh<<endl;
cout<<"Harga           : "<<harga<<endl;
cout<<"Jumlah Ambil    : "<<ja<<endl;
cout<<"Jumlah Kembali  : "<<jk<<endl;
cout<<"Jumlah Terjual  : "<<jt<<endl;
cout<<"==========================================="<<endl;
cout<<"Total Pembayaran: Rp. "<<tot<<endl;
cout<<"==========================================="<<endl;
cout<<"Mau Isi Data Lagi?[Y/T]";cin>>lagi;
cout<<endl;
if(lagi=='Y'||lagi=='y')
goto awal;
else
goto akhir;
akhir:
cout<<"Terima Kasih";
return 0;
}

-- Hasil Running

sekian 5 contoh program c++ dari saya
terima kasih


penulis

Muhammad Iqbal Ramadhan
3 Komentar untuk "Contoh Program C++ Part II"

Back To Top