hi can anyone help me to complete the code for searching a name and update some record which is to be saved on a database?

#include<cstdlib>
#include<iostream>

using namespace std;

struct newemployee
{
char firstname[25];
char lastname[25];
int contactnumber;
int age;
float salary;
int hoursworked;
}
;
void Add();
void Delete();
void update();
void sorting();
void calculatesalary();
int searching();
void saveAndQuit();
void print();
void printemployee(int index);
int search(string name);



newemployee * employee= new newemployee[25];
int numberOfEmployee=0;
int main(int argc, char *argv[])
{
cout<<"Welcome Tex Company Ltd Employee Database"<<endl;
cout<<"Choose the following task"<<endl;
int choice;
cout<<"choose a task"<<endl;
cout <<"1.Add Records"<<endl;
cout <<"2.Delete Records"<<endl;
cout <<"3.Update Records"<<endl;
cout <<"4.Calculate Salary"<<endl;
cout <<"5.Searching for employee" <<endl;
cout <<"6.show employee" <<endl;
cout <<"7.save and quit" <<endl;
cin >>choice;
int exit=0;
while(exit==0)
{

if (choice==1)
{
cout <<"Add Employees "<<endl;
Add();
}
else if(choice==2)
{
cout <<"deletion of employee"<<endl;
Delete();
}
else if (choice==3)
{
cout <<"update of employee"<<endl;
update();
}
else if (choice==3)
{
cout <<"sorting of employee"<<endl;
sorting();
}
else if (choice==4)
{
cout <<"calculate salary"<<endl;
calculatesalary();
}
else if (choice==5)
{
cout <<"searching for employee"<<endl;
searching ();
}
else if (choice==6)
{
cout<<"show employee"<<endl;
print();

}
else if (choice==7)
{
cout<<"Save and Quit"<<endl;
saveAndQuit();



}
else
{
cout<<"Enter a number from 1 to 7"<<endl;
}
cout<<"choose a task"<<endl;
cout <<"1.Add Records"<<endl;
cout <<"2.Delete Records"<<endl;
cout <<"3.Update Records"<<endl;
cout <<"4.Calculate Salary"<<endl;
cout <<"5.Searching for employee" <<endl;
cout <<"6.show employee" <<endl;
cout <<"7.save and quit" <<endl;

cin>>choice;
cin.get();
}
system("PAUSE");
return EXIT_SUCCESS;
}
void Add()
{
cout<<"Enter employee's firstname" <<endl;
cin>>employee[numberOfEmployee].firstname;

cout<<"Enter employee's lastname"<<endl;
cin>>employee[numberOfEmployee].lastname;

cout<<"Enter employee's contact number"<<endl;
cin>>employee[numberOfEmployee].contactnumber;

cout<<"Enter the employee's age"<<endl;
cin>>employee[numberOfEmployee].age;

cout << "Enter the employee's salary" << endl;
cin >>employee[numberOfEmployee].salary;

cout<<"Please enter Number of Hours Worked"<<endl;
cin >>employee[numberOfEmployee].hoursworked;


numberOfEmployee++;
cin.get();




}


void Delete()
{
cout<<"please enter firstname to delete"<<endl;
string name;
cin>>name;
cin.get();


int value=search(name);
//printemployee(value);
if(value==-1)
{
cout<<"Name does not exist"<<endl;

}
else
{
newemployee * temp=new newemployee[2];
employee [value]= temp [1];
numberOfEmployee--;

}

}

void update()
{



}

void sorting()
{






}

void calculatesalary()
{




}

int searching()
{
cout<<"please enter firstname to search"<<endl;
string name;
cin>>name;
cin.get();

int temp;

for( int i=0; i < numberOfEmployee; i++)
{

if (name.compare(employee[i].firstname)==0)
{
cout<<"Employee found"<<endl;
printemployee (i);
temp=i;
break;
}
else
{
cout<<"Employee Not found"<<endl;
temp=-1;

}
}

return temp;
}

void saveAndQuit()
{
exit(0);
}

void print() //the program will display each of the function each at a time
{
for( int i=0; i < numberOfEmployee; i++)

{
cout<<" name of employee: " <<employee[i].firstname<<endl;
cout<<" Lastname of employee: "<<employee[i].lastname<<endl;
cout<<"contact number : "<<employee[i].contactnumber<<endl;
cout<<" Age: "<<employee[i].age<<endl;
cout<<"Salary: "<<employee[i].salary<<endl;
cout<<"Hours Worked:"<<employee[i].hoursworked<<endl;

}

}

void printemployee(int index)//
{

cout<<" name of employee: " <<employee[index].firstname<<endl;
cout<<" Lastname of employee: "<<employee[index].lastname<<endl;
cout<<"contact number : "<<employee[index].contactnumber<<endl;
cout<<" Age: "<<employee[index].age<<endl;
cout<<"Salary: "<<employee[index].salary<<endl;
cout<<"Hours of Worked:"<<employee[index].hoursworked<<endl;




}

int search(string name)
{


int temp;
for( int i=0; i < numberOfEmployee; i++)
{
if (name.compare(employee[i].firstname)==0)
{


temp =i;
break;

}
else
{
temp=-1;

}
}

return temp ;
}


}











plz use line code (see right format <>)
select your code and then click on <>.
I suggest that you store the entire struct in a vector.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
newEmployee item; // you may have to pass these into your functions
vector<item>myVec;       // unless there are in your header file
void Add()
{
cout<<"Enter employee's firstname" <<endl;
cin>> item.firstname;

cout<<"Enter employee's lastname"<<endl;
cin>>item.lastname;

cout<<"Enter employee's contact number"<<endl;
cin>>item.contactnumber;

cout<<"Enter the employee's age"<<endl;
cin>>item.age;

cout << "Enter the employee's salary" << endl;
cin >>item.salary;

cout<<"Please enter Number of Hours Worked"<<endl;
cin >>item.hoursworked;

myVec.pushback(item);

}
}

void Search()
{
   string name;
   cout << " Name to search? " << endl;
   cin >> name;
   for (int i =0; i < myVec.size(); i++)
   {
         if (name == myVec[i].firstName)
         {
               cout << " Name found " << endl;
               break;
          }
    }


}


This was just a sample but you should get the idea.
http://www.cplusplus.com/reference/vector/vector/

Hope that helps!
Topic archived. No new replies allowed.