SQUENTIAL SEARCH |
#include <iostream> #include <string> #include <cstring> #include <iomanip> using namespace std; int sequentialsearch(char kode[11][7],char key[7]){ int index=(-1); for (int i=0;i<=0;i++){ if (strcmp(key,kode[i])==0) {index=i;} } return index; } int main(){ char key [7]="123456"; int val; char kode[11][7]={"CDR054","CDR054","HDD630","HDD720","MNT308","MNT700", "MTB348","MTB512","PRN202","PRN204","RAM114"}; char nama[11][23]={"aopen 48k","lite on 52x","maxtor 160 gb", "seagate 18gb barracuda","viewsonic e70","lg flatron 775ft","asus a7v26","abit kt7-a", "hp laserjet 1220","vispro 512 mb","abit kt7-a"}; float harga[11]={71,24,285,181,192,225,140,102,1456,468,68};
cout<<"\n=========================================================="; cout<<"\n"<<setw(13)<<"KODE |"; cout<<setw(32)<<"NAMA |"<<setw(13)<<"HARGA |"<<endl; cout<<"============================================================\n";
for(int i=0;i<=10;i++) {cout<<"|"<<setw(11)<<kode[i]<<"|"; cout<<setw(30)<<nama[i]<<"|"; cout<<setw(11)<<harga[i]<<"|"<<endl; } cout<<"============================================================\n"; cout<<"\nMASUKKAN KEY :"; cin>>key; val=sequentialsearch(kode,key); if(val==-1) {cout<<"\ndata tidak ditemukan";} else { cout<<"\ndata ditemukan"; cout<<"\nkode :"<<kode[val]; cout<<"\nnama:"<<nama[val]; cout<<"\nharga:"<<harga[val]<<endl; } system("pause"); } |
EmoticonEmoticon