Contoh Kuis PRA-UAS Algoritma dan Pemograman 1 (Semester 1)
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
judul()
{
puts(" TOKO ROTI ENAK");
}
garis()
{
puts("----------------------------------------------------------------------------");
}
long terjual(long ambil, long kembali)
{
return(ambil-kembali);
}
long total(long harga, long terjual)
{
return(harga*terjual);
}
long kembali(long uby, long ttlbay)
{
return(uby-ttlbay);
}
main()
{
int i, j;
long subtotal,totjul, u_bayar, u_kembali;
char bns[20], lagi;
struct
{
char jns_roti[15], kd_roti[5], rasa[2], kd_rasa[2];
int jml_ambil,jml_kmbli, hrg, terjul;
long tot;
}roti[100];
awal:
totjul=0;
subtotal=0;
clrscr();
judul();
cout<<endl;
cout<<"\nInput Banyak Penjual : "; cin>>j;
cout<<"==============================="<<endl;
cout<<endl;
for(i=1;i<=j;i++)
{
cout<<"Data ke - "<<i<<endl;
cout<<"Input Kode Roti [SR01/BT02/HK03] : "; cin>>roti[i].kd_roti; cout<<endl;
cout<<"Kode Rasa [C/S] : "; cin>>roti[i].kd_rasa; cout<<endl;
if(!strcmp(roti[i].kd_roti, "SR01")||!strcmp(roti[i].kd_roti, "sr01"))
{
strcpy(roti[i].jns_roti, "Sari Roti");
if(!strcmp(roti[i].kd_rasa, "C")||!strcmp(roti[i].kd_rasa, "c"))
{
strcpy(roti[i].rasa, "C");
roti[i].hrg=5000;
}
else if(!strcmp(roti[i].kd_rasa, "S")||!strcmp(roti[i].kd_rasa, "s"))
{
strcpy(roti[i].rasa, "S");
roti[i].hrg=4000;
}
else
{
strcpy(roti[i].rasa, "Kode Salah");
roti[i].hrg=0;
}
}
else if(!strcmp(roti[i].kd_roti, "BT02")||!strcmp(roti[i].kd_roti, "bt02"))
{
strcpy(roti[i].jns_roti, "BOTI");
if(!strcmp(roti[i].kd_rasa, "C")||!strcmp(roti[i].kd_rasa, "c"))
{
strcpy(roti[i].rasa, "C");
roti[i].hrg=3000;
}
else if(!strcmp(roti[i].kd_rasa, "S")||!strcmp(roti[i].kd_rasa, "s"))
{
strcpy(roti[i].rasa, "S");
roti[i].hrg=2500;
}
else
{
strcpy(roti[i].rasa, "Kode Salah");
roti[i].hrg=0;
}
}
else if(!strcmp(roti[i].kd_roti, "HK03")||!strcmp(roti[i].kd_roti, "hk03"))
{
strcpy(roti[i].jns_roti, "Holland Bakery");
if(!strcmp(roti[i].kd_rasa, "C")||!strcmp(roti[i].kd_rasa, "c"))
{
strcpy(roti[i].rasa, "C");
roti[i].hrg=6000;
}
else if(!strcmp(roti[i].kd_rasa, "S")||!strcmp(roti[i].kd_rasa, "s"))
{
strcpy(roti[i].rasa, "S");
roti[i].hrg=5000;
}
else
{
strcpy(roti[i].rasa, "Kode Salah");
roti[i].hrg=0;
}
}
else
{
strcpy(roti[i].jns_roti, "Kode Salah");
}
cout<<endl;
cout<<"Jumlah Ambil : "; cin>>roti[i].jml_ambil;
cout<<endl;
cout<<"Jumlah Kembali : "; cin>>roti[i].jml_kmbli;
cout<<endl;
roti[i].terjul=terjual(roti[i].jml_ambil, roti[i].jml_kmbli);
roti[i].tot=total(roti[i].hrg, roti[i].terjul);
if (roti[i].terjul>=10)
{
strcpy(bns, "Roti Sari Roti");
}
else if(roti[i].terjul>=5)
{
strcpy(bns, "Roti Boti");
}
else
{
strcpy(bns, "Tidak dapat");
}
}
clrscr();
cout<<"\t\t\t\tTRANSAKSI\n";
cout<<endl;
garis();
puts("| NO | Jenis Roti | Kode Rasa | Harga | Ambil | Kembali | Terjual | Total |");
garis();
for(i=1;i<=j;i++)
{
cout<<setiosflags(ios::left)<<setw(2)<<"|"<<i<<" |";
cout<<setiosflags(ios::right)<<setw(11)<<roti[i].jns_roti<<" |";
cout<<setiosflags(ios::right)<<setw(5)<<roti[i].rasa<<" |";
cout<<setiosflags(ios::right)<<setw(5)<<roti[i].hrg<<" |";
cout<<setiosflags(ios::right)<<setw(4)<<roti[i].jml_ambil<<" |";
cout<<setiosflags(ios::right)<<setw(5)<<roti[i].jml_kmbli<<" |";
cout<<setiosflags(ios::right)<<setw(5)<<roti[i].terjul<<" |";
cout<<setiosflags(ios::right)<<setw(6)<<roti[i].tot<<" |"<<endl;
subtotal=subtotal+roti[i].tot;
totjul=totjul+roti[i].terjul;
}
garis();
cout<<" Total Jual : "<<totjul<<endl;
cout<<" Pendapatan : "<<subtotal<<endl;
cout<<" Bonus : "<<bns<<endl;
cout<<" Uang Bayar : "; cin>>u_bayar;
u_kembali=kembali(u_bayar, subtotal);
cout<<" Uang Kembali: "<<u_kembali;
cout<<endl<<endl;
cout<<"\t\t\tInput Data Lagi [Y/T]: ";cin>>lagi;
if(lagi=='y'||lagi=='Y')
goto awal;
else
goto akhir;
getch();
akhir:
}
0 komentar:
Posting Komentar