كود PHP:
#include<stdio.h>
#define size 10
struct name{
char first[30];
char last[30];
};
struct datehire{
char day[2];
char month[2];
char year[4];
};
struct employee{
struct name allname;
char id[20];
char salary[20];
struct datehire alldate;
};
typedef struct employee employee;
void choice();
void addrecord(employee *);
void changerecord(employee *);
void loada(employee *);
void loadall(employee *);
main(void){
choice();
return 0;
}
void choice(){
employee employee_list[size];
int choice;
int rubbish;
do{
printf(" <--------welcome to employee database system--------> \n\n");
printf(" please choose the number of function that you want->\n\n");
printf(" <1>add record/records\n");
printf(" <2>change a record\n");
printf(" <3>load a record to screen\n");
printf(" <4>load all record to screen\n");
printf(" <5>exit\n");
printf("\n\n\nplease enter:->");
scanf("%d",&choice);
switch(choice){
case 1:
Addrecord(employee_list);
break;
case 2:
Changerecord(employee_list);
break;
case 3:
Loada(employee_list);
break;
case 4:
Loadall(employee_list);
break;
case 5:
Printf("exited,thanks you to using our system!\n");
printf("press any key and then press the enter to exit\n");
scanf("%d",&rubbish);
break;
default:
Printf("error input!please input the number between 1-5");
scanf("%d",&rubbish);
}
}while (choice!=5);
}
void addrecord(employee *employee_list){
int count=0;
int display=0;
printf("enter employee name(first name)->");
scanf("%s",employee_list[count].allname.first);
printf("enter employee name(last name)->");
scanf("%s",employee_list[count].allname.last);
printf("enter the the employee id->");
scanf("%s",employee_list[count].id);
printf("enter the employee salary->");
scanf("%s",employee_list[count].salary);
printf("please enter the date of hire->");
scanf("%s%s%s",&employee_list[count].alldate.day,&employee_list[count].alldate.month,&employee_list[count].alldate.year);
printf("\n");
printf("the record [%d] employee first name -> %s \n",display+1,employee_list[count].allname.first);
printf("the record [%d] employee last name -> %s\n",display+1,employee_list[count].allname.last);
printf("the record [%d] employee id ->%s \n",display+1,employee_list[count].id);
printf("the record [%d] employee salary -> %s\n",display+1,employee_list[count].salary);
printf("the record [%d] employee hire of date-> %s/%s/%s\n",display+1,employee_list[count].alldate.day,employee_list[count].alldate.month,employee_list[count].alldate.year);
printf("\n");
count=count+1;
display=display+1;
}
void changerecord(employee *employee_list){
int choice1;
char check;
printf("what record do you want to change?enter the number of record please->");
scanf("%d",&choice1);
printf("you want to change record %d\n",choice1);
--choice1;
printf("enter employee name(first name) to change the orignal record:\n");
scanf("%s",employee_list[choice1].allname.first);
printf("enter employee name(last name) to change the orignal:\n");
scanf("%s",employee_list[choice1].allname.last);
printf("enter the the employee id to change the orignal\n");
scanf("%s",employee_list[choice1].id);
printf("enter the employee salary to change the orignal\n");
scanf("%s",employee_list[choice1].salary);
printf("please enter the date of hire\n");
scanf("%s%s%s",&employee_list[choice1].alldate.day,&employee_list[choice1].alldate.month,&employee_list[choice1].alldate.year);
printf("the orignal have changed,do you want to check it?y or n\n");
scanf("%s",&check);
if((check=='y')||(check=='y')){
printf("the record [%d] first name-> %s \n",choice1+1,employee_list[choice1].allname.first);
printf("the record [%d] last name-> %s\n",choice1+1,employee_list[choice1].allname.last);
printf("the record [%d] id-> %s\n",choice1+1,employee_list[choice1].id);
printf("the record [%d] salary-> %s\n",choice1+1,employee_list[choice1].salary);
printf("the record [%d] date of hire-> %s/%s/%s\n",choice1+1,employee_list[choice1].alldate.day,employee_list[choice1].alldate.month,employee_list[choice1].alldate.year);
printf("end of change record");
printf("\n\n\n\n\n\n");
}
}
void loada(employee *employee_list)
{
int choice1;
printf("what record do you want to load to screen?enter the number of record please->");
scanf("%d",&choice1);
choice1-1;
printf("%s ",employee_list[choice1].allname.first);
printf("%s\n",employee_list[choice1].allname.last);
printf("%s\n",employee_list[choice1].id);
printf("%s\n",employee_list[choice1].salary);
printf("%s/%s/%s\n",employee_list[choice1].alldate.day,employee_list[choice1].alldate.month,employee_list[choice1].alldate.year);
}
void loadall(employee *employee_list){
}