Sie sind auf Seite 1von 5

#include <iostream>

#include <conio.h>

using namespace std;

struct Barang{

string kode_barang;

string nama_barang;

int harga_barang;

};

int main(){

Barang brg[5]={

{"B001","BUKU",5000},

{"B002","PENSIL",2000},

{"B003","PULPEN",3500},

{"B004","PENGGARIS",1500},

{"B005","PENGHAPUS",1000},

};

char z;

printf("=============================================\n");

printf("Kode Barang\tNama Barang\t\tHarga\n");

printf("=============================================\n");

printf("B001\t\tBuku\t\t\t5000\n");
printf("B002\t\tPensil\t\t\t2000\n");

printf("B003\t\tPulpen\t\t\t3500\n");

printf("B004\t\tPenggaris\t\t1500\n");

printf("B005\t\tPenghapus\t\t1000\n");

printf("=============================================\n");

ulang:

cout<<"A. Mencari Kode Barang\n";

cout<<"B. Mengurutkan Berdasarkan Harga Barang\n";

printf("=============================================\n");

char input;

printf("\nMasukan Pilihan A/B = ");scanf("%s",&input);

printf("=============================================\n\n");

if(input=='a' || input=='A')

int i,x;

string cari_kode;

bool ketemu;

cout<<"Masukan Kode Barang yang diCari = "; cin>>cari_kode;

for (i=0;i<5;i++){

if (brg[i].kode_barang == cari_kode){
ketemu = true;

x=i;

if (ketemu){

cout<<"============================================="<<endl;

cout<<"Kode Barang = "<<brg[x].kode_barang<<endl;

cout<<"Nama Barang = "<<brg[x].nama_barang<<endl;

cout<<"Harga Barang = "<<brg[x].harga_barang<<endl;

else{

cout<<"Data Barang Tidak Ada";

else

if (input=='b' || input=='B'){

int temp3 ;

string temp2,temp;

cout<<"Data setelah diurut \n";

for(int j=0;j<5;j++)

for(int k=j+1;k<5;k++)

if(brg[j].harga_barang>brg[k].harga_barang)
{

temp=brg[j].kode_barang;

brg[j].kode_barang=brg[k].kode_barang;

brg[k].kode_barang=temp;

temp2=brg[j].nama_barang;

brg[j].nama_barang=brg[k].nama_barang;

brg[k].nama_barang=temp2;

temp3=brg[j].harga_barang;

brg[j].harga_barang=brg[k].harga_barang;

brg[k].harga_barang=temp3;

for(int i=0;i<5;i++){

cout<<"\nKode Barang = "<<brg[i].kode_barang;

cout<<"\nNama Barang = "<<brg[i].nama_barang;

cout<<"\nHarga Barang = "<<brg[i].harga_barang;

cout<<"\n";

else{

printf("\n\t\tTerima kasih, Semoga bermanfaat . . . ");


}

printf("\n\nUlang Lagi? Y/T = ");scanf("%s",&z);

printf("=============================================\n");

if(z=='y' || z=='Y')

goto ulang;

else

printf("\n\t\tTerima kasih, Semoga bermanfaat . . . ");

getch();