Latihan Program C++ Agen Koran BSI
 
Listing code program C++ Agen Koran :

#include <stdio.h>
#include <conio.h>
#include <iostream.h>
char *koran(char a)
{
switch(a)
{
case 'K':
return "Kompas";
break;
case 'R':
return "Republika";
break;
case 'S':
return "Tempo";
break;
}
}

main()
{
struct
{
char nama[20],kode;
int ambil,kembali,jual;
float harga,total;
}pengecer[10];
int i,n;
cout<<"AGEN KORAN LABSLICIOUS "<<endl;
cout<<"======================"<<endl;
cout<<"Banyak Pengecer : ";cin>>n;
for(i=1;i<=n;i++)
{
cout<<"Pengecer Ke - "<<i<<endl;
cout<<"Masukan Nama pengecer  : ";cin>>pengecer[i].nama;
cout<<"Masukan Kode Koran     : ";cin>>pengecer[i].kode;
cout<<"Masukan Jumlah Ambil   : ";cin>>pengecer[i].ambil;
cout<<"Masukan Jumlah Kembali : ";cin>>pengecer[i].kembali;
pengecer[i].jual=pengecer[i].ambil-pengecer[i].kembali;

switch(pengecer[i].kode)
{
case 'K':
pengecer[i].harga=2500;
break;
case 'R':
pengecer[i].harga=2000;
break;
case 'S':
pengecer[i].harga=3000;
break;
}
pengecer[i].total=pengecer[i].harga*pengecer[i].jual;
}
clrscr();
cout<<"     >>>>>>>>>>>>>>>>>>  AGEN KORAN LABSLICIOUS  >>>>>>>>>>>>>>>>"<<endl;
cout<<"========================================================================"<<endl;
cout<<"NO   NAMA          NAMA       JUMLAH  JUMLAH   JUMLAH      HARGA     TOTAL"<<endl;
cout<<"         PENGECER  KORAN      AMBIL   KEMBALI  TERJUAL     KORAN     PENJUALAN"<<endl;
cout<<"========================================================================"<<endl;
for(i=1;i<=n;i++)
{
cout<<i<<"    "<<pengecer[i].nama<<"      "<<koran(pengecer[i].kode)<<"      "<<pengecer[i].ambil<<"       "<<pengecer[i].kembali<<"       "<<pengecer[i].jual<<"           "<<pengecer[i].harga<<"       "<<pengecer[i].total<<endl;
}
getch();
}


Post a Comment

 
Top