Searching
Assalamualaikum
wr wb.
Kali ini saya
akan memposting source kode tentang penjualan laptop menggunakan searcing dalam
bahasa C dan menggunakan aplikasi code block. Langsung saja, berikut programnya
:
#include
<stdio.h>
#include
<conio.h>
#include
<string.h>
#include
<windows.h>
COORD
kordinat={0,0};
void
gotoxy(int x, int y)
{
kordinat.X=x;
kordinat.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),kordinat);
}
struct
datalaptop
{
char *merek, *tipe;
int harga, total;
int jumlah;
};
struct
datalaptop data[20];//array of record
int
cari, i,k,j,n,no, bayar, kembali;
int
total_biaya=0;
void
daftar()
{
system("cls");
printf("+==============================================+\n");
printf("| No | Merek
| Tipe |
Harga |\n");
printf("|==============================================|\n");
printf("| 1 | | Aspire 4743 | Rp. 4500000 |\n");
printf("| 2 |
Acer | Aspire One | Rp. 3500000 |\n");
printf("| 3 |
| Aspire V3 | Rp. 5000000 |\n");
printf("|----|------------|-------------|--------------|\n");
printf("| 4 |
|ASUS X200MA | Rp. 6000000 |\n");
printf("| 5 |
Asus |E1-7010 White| Rp.
7000000 |\n");
/*printf("| 6 |
|A6-7310 White| Rp. 4299000
|\n");
printf("|----|------------|-------------|--------------|\n");*/
printf("+==============================================+\n");
jual();
getch();
}
void
jual()
{
int no;
i=1;
char lagi;
do{
//int i=1;
printf("\nInput no laptop : ");
scanf("%d",&no);
if (no==1)
{
data[i].merek="Acer";
data[i].tipe="Aspire 4743";
data[i].harga=4500000;
printf("Merek : %s\n",data[i].merek);
printf("Tipe : %s\n",data[i].tipe);
printf("Harga : %d\n",data[i].harga);
printf("Jumlah : ");
scanf("%d",&data[i].jumlah); fflush(stdin);
data[i].total=data[i].harga*data[i].jumlah;
total_biaya=data[i].total+total_biaya;
n=n+1;i++;
} else
if (no==2)
{
data[i].merek="Acer";
data[i].tipe="Aspire One";
data[i].harga=3500000;
printf("Merek : %s\n",data[i].merek);
printf("Tipe : %s\n",data[i].tipe);
printf("Harga : %d\n",data[i].harga);
printf("Jumlah : ");
scanf("%d",&data[i].jumlah); fflush(stdin);
data[i].total=data[i].harga*data[i].jumlah;
total_biaya=data[i].total+total_biaya;
n=n+1;i++;
}else
if (no==3)
{
data[i].merek="Acer";
data[i].tipe="Aspire V3";
data[i].harga=5000000;
printf("Merek : %s\n",data[i].merek);
printf("Tipe : %s\n",data[i].tipe);
printf("Harga : %d\n",data[i].harga);
printf("Jumlah : ");
scanf("%d",&data[i].jumlah); fflush(stdin);
data[i].total=data[i].harga*data[i].jumlah;
total_biaya=data[i].total+total_biaya;
n=n+1;i++;
}else
if (no==4)
{
data[i].merek="Asus";
data[i].tipe="ASUS X200MA";
data[i].harga=6000000;
printf("Merek : %s\n",data[i].merek);
printf("Tipe : %s\n",data[i].tipe);
printf("Harga : %d\n",data[i].harga);
printf("Jumlah : ");
scanf("%d",&data[i].jumlah); fflush(stdin);
data[i].total=data[i].harga*data[i].jumlah;
total_biaya=data[i].total+total_biaya;
n=n+1;i++;
}else
if (no==5)
{
data[i].merek="Asus";
data[i].tipe="E1-7010
White";
data[i].harga=7000000;
printf("Merek : %s\n",data[i].merek);
printf("Tipe : %s\n",data[i].tipe);
printf("Harga : %d\n",data[i].harga);
printf("Jumlah : ");
scanf("%d",&data[i].jumlah); fflush(stdin);
data[i].total=data[i].harga*data[i].jumlah;
total_biaya=data[i].total+total_biaya;
n=n+1;
i++;
}//else
/*if (no==6)
{
data[i].merek="Asus";
data[i].tipe="A6-7310
White";
data[i].harga=4299000;
printf("Merek : %s\n",data[i].merek);
printf("Tipe : %s\n",data[i].tipe);
printf("Harga : %d\n",data[i].harga);
printf("Jumlah : ");
scanf("%d",&data[i].jumlah); fflush(stdin);
data[i].total=data[i].harga*data[i].jumlah;
total_biaya=data[i].total+total_biaya;
n=n+1;
}*/
//total_biaya=data[i].total;
k++;
printf("\nBeli lagi (Y/T) : ");
scanf("%s",&lagi); //fflush(stdin);
}while (lagi!='T'&&lagi!='t');
}
void
output()
{
system("cls");
printf("+==========================================================================+\n");
printf("| No | Merek
| Tipe |
Harga | Jumlah | Total |\n");
printf("|-------------------------------------------------------|------------------|\n");
for(i=1;i<=n;i++)
{
printf("| | | | | | Rp. |\n");
gotoxy(3, i+2);
printf("%d\n",i);
gotoxy(8, i+2);
printf("%s\n", data[i].merek);
gotoxy(20, i+2); printf("%s\n",
data[i].tipe);
gotoxy(35, i+2);
printf("%d\n", data[i].harga);
gotoxy(50, i+2);
printf("%d\n", data[i].jumlah);
gotoxy(62, i+2);
printf("%d\n", data[i].total);
//n=1;
}
printf("|-------------------------------------------------------|------------------|\n");
printf("|
Total Biaya | Rp.
|\n");
printf("|-------------------------------------------------------|------------------|\n");
printf("| Pembayaran | Rp. |\n");
printf("|
Kembalian | Rp. |\n");
printf("+==========================================================================+\n");
gotoxy(62, i+3); printf("%d\n",
total_biaya);
gotoxy(62, i+5); scanf("%i",
&bayar);
if(bayar<total_biaya){
gotoxy(62,
i+6);printf("--------");
gotoxy(30, i+8);printf("Maaf,
uang anda tidak mencukupi");
}
else
{
kembali=bayar-total_biaya;fflush(stdin);
gotoxy(62, i+6);printf("%d",
kembali);
}
getch();
}
void
pencarian()
{
system("cls");
printf("masukkan harga laptop yang
dicari : ");
scanf("%d",&cari);
for(i=0;i<k;i++)
{
if(data[i].harga==cari)
{
printf("Merek : %s\n",data[i].merek);
printf("Tipe : %s\n",data[i].tipe);
printf("Harga : %d\n",data[i].harga);
printf("Jumlah :
%d\n",data[i].jumlah);
printf("\n");
j++;
}
}
if(j==0)
{
printf("Data tidak
ditemukan");
}
getch();
}
void
main()
{
int pil;
do{
system("cls");
printf("+================================+\n");
printf("| PENJUALAN LAPTOP |\n");
printf("|--------------------------------|\n");
printf("| 1. Daftar Laptop |\n");
printf("| 2. Tampilkan hasil
penjualan |\n");
printf("| 3. Pencarian |\n");
printf("| 0. Keluar |\n");
printf("|--------------------------------|\n");
printf("| Pilih menu : |\n");
printf("+================================+\n");
gotoxy(15,8);
scanf("%d",&pil);
//pil=getch();
switch(pil)
{
case 1 : {daftar(); break;}
case 2 : {output(); break;}
case 3 : {pencarian(); break;}
case 0 : break;
default : gotoxy(1,9);
printf("Pilihan salah"); getch();
}
}while (pil!=0);
}
|
Terimakasih..
semoga bermanfaat.
Wassalamualaikum
wr wb.