Latihan dan Jawaban Program C++ Agen Koran BSI
Sabtu, 09 Maret 2013
Borland C++
Coding
Latihan dan Jawaban Program C++ Agen Koran BSI
Tampilan Input Agen KoranTampilan Output Agen Koran
Listing code program C++ Agen Koran (klik tombol generate untuk melihat listing) :
#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 "Sindo";
break;
}
}
main()
{
struct
{
char nama[20],kode;
int ambil,kembali,jual;
float harga,total;
}pengecer[10];
int i,n;
cout<<"AGEN KORAN SINAR BUMI "<<endl;
cout<<"======================"<<endl;
cout<<"Banyak Pengecer : ";cin>>n;
for(i=1;i<=n;i++)
{
cout<<"Penegcer 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 SINAR BUMI >>>>>>>>>>>>>>>>"<<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();
}