Sunday, October 14, 2018

PERTEMUAN 4 : Seleksi Kondisi (If Else & Switch Case)

Tugas :
1.

2.
3.
#include <conio.h>
#include <iostream.h>
main()
{
char kobar, buku, bns, beli, lagi, yt;
float totbay, jumbel, totbel, potongan, harga, grandtot, ppn;
kembali:
clrscr();
cout<<""<<endl;
cout<<" Masukkan Kode Buku [1..3]  : ";cin>>kobar;
cout<<" Jumlah Pembelian Buku Anda : ";cin>>jumbel;
clrscr();
cout<<"\n ";
cout<<"\t *** TOKO BUKU ALFAN KHUDORI *** \n";
cout<<"\t    JL.Nebula , Milky Way \n";
cout<<" -------------------------------------------";
cout<<""<<endl;
cout<<" Nama Buku yang Anda Beli     :"<<buku;
switch(kobar)
 {
  case ('1') :
      {
      cout<<"Sukses Belajar Borland C++"<<buku;
      harga= 50000*jumbel ;
      }
      break;
  case ('2') :
      {
      cout<<"Kunci Pribadi Yang Sukses"<<buku;
      harga= 35000*jumbel;
      }
      break;
  case ('3') :
      {
      cout<<"Mencari Mutiara Didasar Hati"<<buku;
      harga= 45000*jumbel;
      }
      break;
 }
cout<<endl;
cout<<" Harga Buku yang Anda Beli    : Rp."<<harga<<endl;
    if (jumbel >5)
  {
   potongan = 0.1*harga;
  }
  else
  {
   potongan= 0;
  }
cout<<" Jumlah Buku yang Anda Beli   : "<<jumbel<<endl;
cout<<" Total Harga                  : Rp."<<harga<<endl;
cout<<" Potongan Harga               : Rp."<<potongan<<endl;
totbay= harga-potongan;
ppn= totbay*0.1;
grandtot= totbay+ppn;
cout<<" ---------------------------------------------"<<endl;
cout<<" Total Bayar                  : Rp."<<totbay<<endl;
cout<<" PPN         : Rp."<<ppn<<endl;
cout<<" Grand Total                  : Rp."<<grandtot<<endl;
cout<<" Bonus yang Anda Dapatkan     :"<<bns;
     if (jumbel >5)
  {
  cout<<"Note Book"<<bns;
  }
   else
  {
   cout<<"Maaf Tidak Dapat Bonus"<<bns;
  }
  cout<<endl;
cout<<" \n ";
cout<<"---------------------------------------------"<<endl;
cout<<"\t **** TERIMA KASIH ****        ";
cout<<endl;
cout<<" Apa Mau Input Data Lagi ? [Y/T] : ";cin>>yt;
cout<<endl;
clrscr();
if(yt=='Y' || yt=='y')
{goto kembali;}
if(yt=='T' || yt=='t')
{goto selesai;}
selesai:
cout<<endl;
cout<<"\t******* Terima Kasih *******"<<endl;
getch();
}
Output :
 
2. Program Tiket Kereta

Input :
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
main()
{
char kk[10],kls,kelas_krt[10],nama[10],lagi;
int kode,jmlh_tket=0,bt;
long dskn,harga,asuransi,pembayaran,total,ub,uk;
clrscr();
awal:
printf("\t\tPROGRAM TIKET KERETA\n");
printf("==================================\n");
printf("Masukan Kode Kereta [AG/AL/PH]:");scanf("%s",&kode);
printf("Pilih kelas [1/2/3]\n");
printf("1.Executive\n");
printf("2.Bisnis\n");
printf("3.Ekonomi\n");
printf("Masukan Kelas Kereta [1/2/3]:");scanf("%s",&kls);
switch(kode)
{
case strcmp,'AG':
case strcmp,'ag':
strcpy(kk,"AGRA");
if(kls=='1')
{strcpy(kelas_krt,"Executive");
harga=300000;
bt=10000;
}
else
if(kls=='2')
{strcpy(kelas_krt,"Bisnis");
harga=250000;
bt=10000;
}
else
{strcpy(kelas_krt,"Ekonomi");
harga=200000;
bt=10000;
}
break;
case strcmp,'AL':
case strcmp,'al':
strcpy(kk,"ALPHA");
if(kls=='1')
{strcpy(kelas_krt,"Executive");
harga=250000;
bt=10000;
}
else
if(kls=='2')
{strcpy(kelas_krt,"Bisnis");
harga=200000;
bt=10000;
}
else
{strcpy(kelas_krt,"Ekonomi");
harga=150000;
bt=10000;
}
break;
case strcmp,'PH':
case strcmp,'ph':
strcpy(kk,"PHALAPA");
if(kls=='1')
{strcpy(kelas_krt,"Executive");
harga=200000;
bt=10000;
}
else
if(kls=='2')
{strcpy(kelas_krt,"Bisnis");
harga=150000;
bt=10000;
}
else
{strcpy(kelas_krt,"Ekonomi");
harga=100000;
bt=10000;
}
break;
default:
printf("Kode Kereta Yang Anda Masukan Salah\n");
printf("\nIngin Input lagi [Y/T]:");scanf("%s",&lagi);
if(lagi=='Y'||lagi=='y')
{clrscr();
goto awal;
}
else
{clrscr();
goto end;
}
}
clrscr();
printf("\t\tDAFTAR PEMESANAN TIKET KERETA\n");
printf("============================================\n");
printf("Nama Pemesan \t\t:");scanf("%s",&nama);
printf("Nama Kereta \t\t:%s\n",kk);
printf("Kelas Kereta \t\t:%s\n",kelas_krt);
printf("Harga Per Tiket \t:%i\n",harga);
printf("Jumlah Pemesanan Tiket\t:");scanf("%i",&jmlh_tket);
asuransi=jmlh_tket*bt;
printf("Biaya Tambahan Fasilitas:%li\n",asuransi);
pembayaran=harga*jmlh_tket+asuransi;
printf("Pembayaran \t\t:%li\n",pembayaran);
if(jmlh_tket>5)
{
dskn=pembayaran*0.1;
}
else
if(jmlh_tket<=5)
{
dskn=0;
}
printf("Discount \t\t:%li\n",dskn);
printf("============================================\n");
total=pembayaran-dskn;
printf("Total Pembayaran\t:%li\n",total);
printf("Uang Bayar \t\t:");scanf("%li",&ub);
uk=ub-total;
printf("Uang Kembali \t\t:%li\n",uk);
printf("============================================\n");
printf("\nIngin Input lagi [Y/T]:");scanf("%s",&lagi);
if(lagi=='Y'||lagi=='y')
{clrscr();
goto awal;
end:
}
else
{
}
}
 Output :

3. Program Pemesanan Penginapan

Input :
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{
char cust[50],tipe[10],bonus[15],lagi,kode;
int lama,hrg,sewa,cash,total,kembali,adm;
atas:
cout<<" PENGINAPAN PASTI BETAH"<<endl<<endl;
cout<<" **************************************"<<endl<<endl;
cout<<" Nama Penyewa\t\t: ";gets(cust);
cout<<" Kode Kamar [A/B/M]\t: ";cin>>kode;
switch(kode)
{
    case'a':
    case 'A':
    strcpy(tipe,"ANGGREK");
      hrg=300000;
    break;
    case'b':
    case'B':
      strcpy(tipe,"Bougenville");
      hrg=250000;
    break;
    case'm':
    case'M':
      strcpy(tipe,"MAWAR");
      hrg=200000;
    break;
    default:
    cout<<endl;
    cout<<" Kode Kamar Yang Anda Masukan Salah"<<endl;
      goto bawah;
    }
cout<<" Lama Menginap\t\t: ";cin>>lama;
if(lama>=7)
{
strcpy(bonus,"Payung Cantik");
}
else
strcpy(bonus,"TIDAK DAPAT SOUVENIR\t\t");
clrscr();
adm=200000;
sewa=lama*hrg;
total=adm+sewa;
cout<<" PENGINAPAN PASTI BETAH"<<endl<<endl;
cout<<" Nama Penyewa\t\t: "<<cust<<endl;
cout<<" Kode Kamar [A/B/M]\t: "<<kode<<endl;
cout<<" Lama Menginap\t\t: "<<lama<<endl<<endl;
cout<<" **************************************"<<endl<<endl;
cout<<" Tipe Kamar\t\t: "<<tipe<<endl;
cout<<" Lama Menginap\t\t: "<<lama; cout<<" hari"<<endl;
cout<<" Souvenir\t\t: "<<bonus<<endl;
cout<<" Biaya Sewa\t\t: "<<sewa<<endl;
cout<<" Biaya Administrasi\t: "<<adm<<endl;
cout<<" Total Biaya Sewa\t: "<<total<<endl<<endl;
cout<<" **************************************"<<endl<<endl;
cout<<" Uang Bayar\t\t: ";cin>>cash;
kembali=cash-total;
cout<<" Uang Kembali\t\t: "<<kembali<<endl;
bawah:
cout<<endl;
cout<<" INGIN INPUT LAGI?[Y/T] :";cin>>lagi;
clrscr();
if(lagi=='y'||lagi=='Y')
goto atas;
else
getch();
}
 Output :

Related Posts

PERTEMUAN 4 : Seleksi Kondisi (If Else & Switch Case)
4/ 5
Oleh

Subscribe via email

Like the post above? Please subscribe to the latest posts directly via email.