0% found this document useful (0 votes)
2K views4 pages

Program Input Stok BaRang C++

This program allows users to input, display, sort, and search for notebook data including type, brand, model, and price. The program displays a menu with 6 options - input data, display data, sort by price, search by price, about, and exit. It uses structures to store an array of notebook objects and implements input validation and looping to return to the main menu.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views4 pages

Program Input Stok BaRang C++

This program allows users to input, display, sort, and search for notebook data including type, brand, model, and price. The program displays a menu with 6 options - input data, display data, sort by price, search by price, about, and exit. It uses structures to store an array of notebook objects and implements input validation and looping to return to the main menu.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <iostream.

h>
#include <conio.h>
#include <stdio.h>
struct notebook
{ char jenis[10],merk [10],tipe[15];
int harga; };
struct notebook nb[5];
main () {
int pil,bts,i, t, r,s, cari, a,e,m;
char jwb;
menu:
cout<<endl;
cout<<"Selamat Datang"<<endl;
cout<<"Ini Adalah Program Untuk menginputkan Barang"<<endl;
cout<<"TOKO KOMPUTER JOSS"<<endl;
cout<<"=============================="<<endl;
cout<<endl;
cout<<"Silakan Pilih Menu"<<endl;
cout<<"1. INPUTKAN DATA BARANG"<<endl;
cout<<"2. TAMPILKAN DATA"<<endl;
cout<<"3. PENGURUTAN HARGA BARANG"<<endl;
cout<<"4. PENCARIAN BARANG"<<endl;
cout<<"5. Tentang Program"<<endl;
cout<<"6. Keluar"<<endl;
cout<<endl;
cout<<"Masukan pilihan : ";cin>>pil;
if (pil==1)
{ clrscr();
cout<<"MENU INPUT BARANG"<<endl;
cout<<endl;
cout<<"Masukan jumlah Barang yang ingin diinputkan : ";cin>>bts;
cout<<endl;
cout<<"INPUTKAN DATA BARANG:"<<endl;
cout<<"----------------------"<<endl;
//menginputkan data
for (i=0; i<bts; i++)
{cout<<"Data Barang "<<(i+1)<<endl;
cout<<"Jenis Barang\t: ";cin>>nb[i].jenis;
cout<<"Merk\t: ";cin>>nb[i].merk;
cout<<"Tipe\t: ";cin>>nb[i].tipe;
cout<<"Harga\t: ";cin>>nb[i].harga;
cout<<"-------------------"<<endl;}
clrscr();
cout<<"Data Sudah di inputkan..:"<<endl;
cout<<endl;
cout<<"Kembali? [y/t] : ";cin>>jwb;

if (jwb=='y'||jwb=='Y')
{clrscr();
goto menu;}
}
//pilihan 2 (Menampilkan Data Barang)
else if (pil==2)
{
clrscr();
for (i=0; i<bts; i++)
{
cout<<endl;
cout<<"Data Barang "<<(i+1)<<endl;
cout<<"Jenis\t: "<<nb[i].jenis<<endl;
cout<<"Merk\t: "<<nb[i].merk<<endl;
cout<<"Tipe\t: "<<nb[i].tipe<<endl;
cout<<"Harga\t: "<<nb[i].harga<<endl;
cout<<endl;
}
cout<<endl;
cout<<"Kembali? [y/t] : ";cin>>jwb;
if (jwb=='y'||jwb=='Y')
{clrscr();
goto menu;
}
}
//jika pilihan 3 (Mengurutkan Harga) Sorting
else if (pil==3)
{
clrscr();cout<<" Berikut Adalah Sorting Data harga"<<endl;
cout<<"(Diurutkan dari yang paling Murah)"<<endl;
//pengurutan data ascending
for(i=0;i<bts-1;i++){
t=i;
for(r=i+1;r<bts;r++){
if(nb[t].harga>nb[r].harga)
t=r;}
if(nb[i].harga !=nb[t].harga)
{s=nb[i].harga;
nb[i].harga=nb[t].harga;
nb[t].harga=s;}
}
for(i=0;i<bts;i++){
cout<<" "<<nb[i].harga;
}
cout<<endl;
cout<<"Kembali? [y/t] : ";cin>>jwb;
if (jwb=='y'||jwb=='Y')
{clrscr();
goto menu;}
}

//jika yang dipilih menu 4 (Pencarian Barang)


else if (pil==4)
{
cout<<"Untuk Mencari Barang Berdasar Harga"<<endl;
cout<<"Inputkan Harga barang yang ingin dicari : ";
cin>>cari;
a=0;
e=bts;
while(a <= e)
{ m = (a + e)/2;
if(bts > nb[m].harga)
{ a = m + 1; }
else if(cari < nb[m].harga)
{ e = m - 1; }
else
{ a = e + 1; }
}
if(cari==nb[m].harga)
{ cout << "Harga "<<cari<<" ada di Barang/Produk ke "<<(m+1)<< endl; }
else
{ cout << "Produk dengan Harga "<<m<<" Tidak ditemukan" << endl; }
cout<<"Kembali? [y/t] : ";cin>>jwb;
if (jwb=='y'||jwb=='Y')
{clrscr();
goto menu;}
}
else if (pil==5)
{
clrscr();
cout<<"-----------------------"<<endl;
cout <<"Program ini dibuat Oleh:"<<endl;
cout<<"Tri Purnomo & Dwi Aji"<<endl;
cout<<endl;
cout<<endl;
cout<<"Terimakasih Telah Menggunakan Program ini"<<endl;
cout<<endl;
cout<<endl;
cout<<"-------------------"<<endl;
cout<<"Kembali? [y/t] : ";cin>>jwb;
if (jwb=='y'||jwb=='Y')
{clrscr();
goto menu;}
}
else if (pil==6)
{clrscr();
cout<<"Tekan Enter untuk keluar";
}
else { clrscr();
cout<<"Anda Salah Input";
cout<<endl;
cout<<"Kembali? [y/t] : ";cin>>jwb;
if (jwb=='y'||jwb=='Y')

{clrscr();
goto menu;}
}

getch();
}

You might also like