Smart Contact | Real Time Search C++

Smart Contact

Real Time Search C++


#include <iostream.h>
#include <conio.h>

bool strgns(char a[100],char b[100])
{
int i;

for(i=0;i<100 && a[i]!=NULL && b[i]!=NULL ;i++)
if(a[i]!=b[i])
break;

if(b[i]==NULL)
return 0;

return 1;
}

int main()
{
_setcursortype(_NOCURSOR);

bool f;
int i,j,k;
char d,x;
char s[100];
char a[100][100];
char b[100][100];
char c[100][100];

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

strcpy (a[i]," ");
strcpy (b[i]," ");
strcpy (c[i]," ");

}

k=0;

while(1)
{

clrscr();
cout<<"1 ---> Insert"<<endl;
cout<<"2 ---> Delete"<<endl;
cout<<"3 ---> Search"<<endl;
cout<<"4 ---> Print"<<endl;
cout<<"5 ---> Exit"<<endl;

cout<<" -> ";
cin>>d;

if(d=='1')
{
clrscr();

cout<<"First Name => ";
cin>>a[k];

cout<<"Last Name => ";
cin>>b[k];

cout<<"Number => ";
cin>>c[k];

k++;
}

else if(d=='2')

{

clrscr();
cout<<"Smart Delete => ";
cin>>s;

for(i=0;i<100;i++)
if(strcmp(a[i],s)==0 || strcmp(b[i],s)==0 || strcmp(c[i],s)==0)
{
clrscr();
cout<<"First Name -> ("<<a[i]<<") Last Name -> ("<<b[i]<<") Number -> ("<<c[i]<<")"<<endl;
cout<<" Has Been Deleted ... ";

strcpy (a[i]," ");
getch();
}

}

else if(d=='3')

{
j=0;

clrscr();
cout<<"RealTime Search (Press Enter To End) => ";

while(x!=13)
{

x=getch();

clrscr();

if(x==8)

{

if(j>0)
{
j--;
s[j]=NULL;
}

}

else {

s[j]=x;

j++;

s[j]=NULL;

}

cout<<"RealTime Search (Press Enter To End) => "<<s<<endl<<endl;

if(s[0]!=NULL)
for(i=0;i<100;i++)
if(strgns(a[i],s)==0 || strgns(b[i],s)==0 || strgns(c[i],s)==0)
cout<<"First Name -> ("<<a[i]<<") Last Name -> ("<<b[i]<<") Number -> ("<<c[i]<<")"<<endl;

}

x=NULL;

}

else if(d=='4')

{
clrscr();
f=0;

for(i=0;i<100;i++)
if(strcmp(" ",a[i])!=0)
{
cout<<"First Name -> ("<<a[i]<<") Last Name -> ("<<b[i]<<") Number -> ("<<c[i]<<")"<<endl;
f=1;
}

if(f==0)
cout<<"There Is No Contact ... ";

getch();
}

else if(d=='5')

{
clrscr();
cout<<"Created By Omid Bahrami";
getch();
return 0;
}

}

}