#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
struct employees
{
int em_id;
string em_name;
string position;
string gender;
};
void read(employees record[], int max_1);
bool IDsort(const employees &a, const employees &b)
{
return(a.em_id < b.em_id);
}
char Namesort(const employees&a, const employees &b)
{
return(a.em_name < b.em_name);
}
void Insort(employees record[], int max_2);
void printemployees ( employees record[], int max_3);
int main()
{
const int n= 1000;
employees record[n];
int options;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"Welcome to Employees Record System"<<endl;
cout<<"Please insert a number to proceed"<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<" 1.Insert new record."<<endl;
cout<<" 2.Sort record."<<endl;
cout<<" 3.Delete record."<<endl;
cout<<" 4.Display record."<<endl;
cout<<" -------------------------------------------------------------------------------"<<endl;
cout<<"Selection : ";
cin>>options;
switch(options)
{
case 0: break;
case 1: read(record,n);
break;
case 2: Insort(record,n);
break;
case 4: printemployees(record,n);
break;
default: cout<<"Invalid selection"<<endl;
break;
}
system ("pause");
return 0;
}
void read( employees record[], int max_1)
{
for (int i=0; i<max_1; i++)
{
for (int i=0; i<max_1; i++)
{
continued:
cout<<"employees no. "<<(i+1)<<endl;
cout<<"Enter employee ID: ";
cin>>record[i].em_id;
cin.ignore(100,'\n');
cout<<"Enter employee name: ";
cin>>record[i].em_name;
cin.ignore(100,'\n');
cout<<"Enter employee position: ";
cin>>record[i].position;
cin.ignore(100,'\n');
cout<<"Enter employee gender: ";
cin>>record[i].gender;
cin.ignore(100,'\n');
}
}
}
void Insort(employees record[], int max_2)
{
int selections=0;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"You had selected sorting function"<<endl;
cout<<"Select a number to proceed"<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"1. Sort by ID"<<endl;
cout<<"2. Sort by name"<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"Selection: "<<endl;
cin>>selections;
switch(selections)
{
case 1: std::sort(record,record+max_2,IDsort);
break;
case 2: std::sort(record,record+max_2,Namesort);
break;
}
}
void printemployees(employees record[], int max_3)
{
for(int i=0; i<max_3; i++)
{
cout<<"employee no. "<<(i+1)<<endl;
cout<<"employee ID: "<<record[i].em_id<<endl;
cout<<"employee name: "<<record[i].em_name<<endl;
cout<<"employeenationality: "<<record[i].position<<endl;
cout<<"employee gender: "<<record[i].gender<<endl;
}
}
Hi..i have modified someone's code and try to understand it..
But for this record system..there are several problems
1) The record can't quit when the user want to.
2) The record can't update and when want to display it, it fail.
Any suggestion to do that? I am not asking the coding..just the way to do that. Thanks for any help or suggestion ^^''