Program Pencarian data untuk Array of Record di C++

Berikut ini merupakan contoh coding program pencarian data yang terstruktur dalam bentuk record.Sebelum membuat program searching ini ,kita harus paham dulu teknik pemodelan dalam Array of record.

#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
typedef struct

{
int nim;
char nama[25];
char alamat[25];
char golongan[1];
}
mahasiswa;
mahasiswa mhs[10];
int main()
{

for (int i=0; i<10; i++)
{
cout<<“mahasiswa ke : “<<i+1;
cout<<” \n”;
cout<<“Nomor Induk : “;
cin>>mhs[i].nim;
cout<<“Nama : “;
cin>>mhs[i].nama;
cout<<“alamat : “;
cin>>mhs[i].alamat;
cout<<“Golongan : “;
cin>>mhs[i].golongan;
cout<<endl;
}

 

int i, k;
bool found;
cout<<“Untuk Mencari data silakan masukkan NIM ! “;
cin >>k;
found =false;
i=0;
while ((i<10)&(!found))
{
if (mhs[i].nim==k)
found=true;
else
i=i+1;
}
if(found){
cout<<“nim: “<<k<<“Ditemukan “;
cout<<“\n”;
cout<<“Nim : “<<mhs[i].nim;
cout<<“\n”;
cout<<“Nama : “<<mhs[i].nama;
cout<<“\n”;
cout<<“Alamat : “<<mhs[i].alamat;
cout<<“\n”;
cout<<“Golongan : “<<mhs[i].golongan;
cout<<endl;
}
else
cout<<“nim “<<k<<“tidak ada dalam data”;

system(“PAUSE”);
return EXIT_SUCCESS;
}

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s