Hi,
This program supposed to ask the user to enter the names and the ID numbers and
the number of children the employee have,
the search shoud work like this
taylar 845 3
john 123 2
sara 526 2
**search by name**
the user should enter the employee name he's searching for
if he entered sara
sara 526 2
**search by number of children**
if the user enterd 2
john 123 2
sara 526 2
**sort by name**
the names sould sorted in alphapatical order
john 123 2
sara 526 2
taylar 845 3
************************************
#include <iostream>
#include <cstring>
using namespace::std;
int main ()
{
int counter=0;
char *s[100];
char names[100];
int num[3];
char *j;
int child[3];
int x,n,y,s1,s2;
cout <<"Input the information of 10 imployees: "<< endl;
cout << "Names "<< "Number" <<" childs"<<endl;
for ( int i=0 ; i <3 ; i++ ){
s[i]= names;
cin >> names ;
cout<< "\t";
cin >> num[i] ;
cout << "\t";
cin >> child[i] ;
cout<< "\t" ;
cout << endl;
}
cout << "What type of operation you are interested in: " << endl;
cout << " 1. Search by Employee name" << endl;
cout << " 2. Search by Number of childrean" << endl;
cout << " 3. Sort by Name" << endl;
cout << " 4. To Exit" << endl;
cin >> x ;
while ( x != 4 ) {
if ( x == 1 ) {
cout << "Input the employee name:" << endl;
cin >> j ;
for ( i=0 ; i < 3 ; i++ )
{
int n;
n = strcmp( j , s[i]);
if ( n=0)
{
cout << "The employee you are looking for are :" << endl;
cout << s[i] <<"\t"<< num[i] <<"\t"<< child[i] << endl;
}
}
}
if ( x == 2 ){
cout << "What is the number of children you are looking for:" << endl;
cin >> n;
cout << "The employees you are looking for are:" << endl;
for ( i=0 ; i < 3 ; i++ ){
if ( child[i] == n )
cout << s[i] <<"\t"<< num[i] << "\t" << child[i] << endl;
}
}
if ( x == 3 ){
for ( i=0 ; i <3 ; i++ ){
s1=*s[i];
s2=*s[i+1];
y=strcmp ( s[i] , s[i+1]);
if ( y == 1 ) {
*s[i] = s1;
*s[i+1]=s2;
}
else {
*s[i]=s2;
*s[i+1]=s1;
}
}
cout << "Sort by Name:" << endl;
for ( i=0 ; i<3 ; i++ )
cout << s[i] << "\t" << num[i] << "\t" << child[i] << endl;
}
}
return 0;
}