Penggunaan Array dalam membuat sebuah program penjualan menggunakan bahasa C++, berikut contoh kodingnya yang gue buat.. semoga bisa membantu :D
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<string.h>
void main()
{
int jumlah_pelanggan, i, j;
int jumlah_jenis[10];
int jumlah_susu[10][15], harga[5][5];
int jumlah_bayar[5][5], total_bonus[5];
float total_bayar[5][5];
float jumlah_total_bayar[5];
float diskon[5][5];
char nama[5][20];
char kode_susu[5][5][5], kode_kemasan[5][5][5], merk[5][5][10],
jenis_kemasan[5][5][10];
char nama_bonus[5][20];
cout<<"Program Pembayaran Toko Susu SEJAHTERAH"<<endl;
cout<<endl;
cout<<"Input Jumlah Pelanggan : ";
cin>>jumlah_pelanggan;
clrscr();
for(i=0;i<jumlah_pelanggan;i++)
{
cout<<" Pelanggan ke-"<<i+1<<endl;
cout<<"Input Nama Pelanggan : "; gets(nama[i]);
cout<<"Jumlah Jenis Susu : ";
cin>>jumlah_jenis[i];
jumlah_total_bayar[i]=0;
cout<<endl;
for(j=0;j<jumlah_jenis[i];j++)
{
cout<<" Jenis Susu ke-"<<j+1<<endl;
cout<<"Input Kode Susu [ S/D/B ] : "; cin>>kode_susu[i][j];
cout<<"Input Kode Kemasan [ KT/KL ] : "; cin>>kode_kemasan[i][j];
cout<<"Input Jumlah Beli : "; cin>>jumlah_susu[i][j];
cout<<endl;
//mencari merk dan harga susu
if(strcmp(kode_susu[i][j],"S")==0)
{ strcpy(merk[i][j],"SGM");
if(strcmp(kode_kemasan[i][j],"KT")==0)
{ strcpy(jenis_kemasan[i][j],"Kotak");
harga[i][j]=40;}
else if(strcmp(kode_kemasan[i][j],"KL")==0)
{ strcpy(jenis_kemasan[i][j],"Kaleng");
harga[i][j]=50;}
}
else if(strcmp(kode_susu[i][j],"D")==0)
{ strcpy(merk[i][j],"Dancow");
if(strcmp(kode_kemasan[i][j],"KT")==0)
{strcpy(jenis_kemasan[i][j],"Kotak");
harga[i][j]=50;}
else if(strcmp(kode_kemasan[i][j],"KL")==0)
{strcpy(jenis_kemasan[i][j],"Kaleng");
harga[i][j]=60;}
}
else if(strcmp(kode_susu[i][j],"B")==0)
{ strcpy(merk[i][j],"Bendera");
if(strcmp(kode_kemasan[i][j],"KT")==0)
{strcpy(jenis_kemasan[i][j],"Kotak");
harga[i][j]=55;}
else if(strcmp(kode_kemasan[i][j],"KL")==0)
{strcpy(jenis_kemasan[i][j],"Kaleng");
harga[i][j]=65;}
}
else {strcpy(merk[i][j],"Tidak Terdaftar");}
//mencari jumlah bayar
jumlah_bayar[i][j]=jumlah_susu[i][j]*harga[i][j];
//mencari diskon
if(strcmp(kode_kemasan[i][j],"KL")==0 && jumlah_bayar[i][j]>120 )
{ diskon[i][j]=jumlah_bayar[i][j]*0.04;}
else {diskon[i][j]=0;}
//mencari total bayar
total_bayar[i][j]=jumlah_bayar[i][j]-diskon[i][j];
//mencari jumlah total bayar
jumlah_total_bayar[i]=jumlah_total_bayar[i]+total_bayar[i][j];
}
total_bonus[i]=0;
if(jumlah_total_bayar[i]>total_bonus[i])
{strcpy(nama_bonus[i],nama[i]);
total_bonus[i]==jumlah_total_bayar[i];}
else {strcpy(nama_bonus[i],"Tidak Ada");}
}
//tampilan
clrscr();
cout<<endl<<endl;
cout<<" By:Rezki N.L\n";
cout<<endl<<endl;
cout<<" ---------------------------------\n";
cout<<" * TOKO SUSU SUKA MAJU SELALU *\n";
cout<<" ---------------------------------\n";
cout<<endl<<endl;
for(i=0;i<jumlah_pelanggan;i++)
{ cout<<"Nama Pelanggan : "<<nama[i]<<endl;
cout<<"================================================================================\n";
cout<<" MERK SUSU KEMASAN JUMLAH HARGA JUMLAH BAYAR DISKON TOTAL BAYAR \n";
cout<<"================================================================================\n";
for(j=0;j<jumlah_jenis[i];j++)
{ printf(" %-8s %-6s %-4i %-3i %2i %.2f %2.2f \n",
merk[i][j], jenis_kemasan[i][j], jumlah_susu[i][j], harga[i][j], jumlah_bayar[i][j],
diskon[i][j], total_bayar[i][j]);
}
cout<<"================================================================================\n";
cout<<" JUMLAH YG HARUS DIBAYAR "<<jumlah_total_bayar[i]<<endl;
cout<<endl<<endl<<endl<<endl;
}
cout<<"Yang Mendapatkan bonus adalah : "<<nama_bonus[i];
getch();
}
Langganan:
Posting Komentar
(
Atom
)