Laman

Kamis, 02 Mei 2013

Contoh Program Array Pada C++



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

#include <stdio.h>
#include <iomanip.h>
main()
{
int bj,n,hs[4],jh[4],bp[4],jb=0,tb;
char kp[4],*jp[4];
float pj;
cout<<"GEROBAK FRIED CHICKEN         \n";
cout<<"------------------------------\n";
cout<<"Kode Jenis Potong Harga       \n";
cout<<"------------------------------\n";
cout<<" D   Dada         Rp. 2500    \n";
cout<<" P   Paha         Rp. 2000    \n";
cout<<" S   Sayap        Rp. 1500    \n";
cout<<"------------------------------\n";

cout<<"Banyak Jenis : ";cin>>bj;
for (n=1;n<=bj;n++)
{
cout<<"Jenis Ke - : "<<n<<endl;
cout<<"Kode Potong [D/P/S] : ";cin>>kp[n];
cout<<"Banyak Potong : ";cin>>bp[n];
}
clrscr();

cout<<"GEROBAK FRIED CHICKEN\n";
cout<<"-----------------------------------------\n";
cout<<"No. Jenis     Harga   Bayak  Jumlah      \n";
cout<<"    Potong    Satuan  Beli   Harga       \n";
cout<<"-----------------------------------------\n";
for (n=1;n<=bj;n++)
{
cout<<setiosflags(ios::left)<<setw(4)<<n;
if (kp[n]=='D'||kp[n]=='d')
{ jp[n]="Dada";
  hs[n]=2500;
}
else if (kp[n]=='p'||kp[n]=='P')
{ jp[n]="Paha";
  hs[n]=2000;
}
else if (kp[n]=='S'||kp[n]=='s')
{ jp[n]="Sayap";
  hs[n]=1500;
}

cout<<setiosflags(ios::left)<<setw(10)<<jp[n];
cout<<setiosflags(ios::left)<<setw(8)<<hs[n];
cout<<setiosflags(ios::left)<<setw(7)<<bp[n];
jh[n]=hs[n]*bp[n];
cout<<setiosflags(ios::left)<<setw(12)<<jh[n]<<endl;
jb=jb+jh[n];
}
cout<<"-----------------------------------------\n";
cout<<"              Jumlah Bayar Rp "<<jb<<endl;
pj=jb*0.1;
cout<<"              Pajak 10%    Rp "<<pj<<endl;
tb=jb+pj;
cout<<"              Total Bayar  Rp "<<tb<<endl;
getch();
}

1 komentar: