?? agb.cpp
字號:
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<stdio.h>
#include "graphics.h"
#include "conio.h"
#include "dos.h"
#define maxworker 100
FILE *fp; /*定義全局變量fp,指向數據庫文件 worker.txt*/
struct date1{ /*日期的結構,用于存儲工人的生日,工作日期等*/
int year;
int month;
int day;
};
struct address { /*地址的結構, 用于存儲工人的地址*/
char province[10];
char city[10];
char street[20];
};
struct WORKER { /*工人的資料總結構*/
char name[20];
enum {male,female}sex;
struct date1 birthday;
enum {elesch,middle,high,university,other}rofs;
struct date1 workday;
int workeri;
char position[20];
struct address addr;
int workerj;
char tel[13];
};
/*程序的初始化函數,用于從數據庫中讀出現存的資料到內存中*/
void data_load(int *i,struct WORKER *p){
char c;
long int k;
fp=fopen("worker.txt","r");
if(!fp){fopen("worker.txt","w+");*i=0;}
else{
for((*i)=0;(*i)<maxworker;(*i)++){
if(feof(fp)) return;
c=fgetc(fp);
if(c==EOF) return;
fflush(stdin);
k=*i;
fseek(fp,k*sizeof(struct WORKER),SEEK_SET);
fread(&p[*i],sizeof(struct WORKER),1,fp);
}
}
void modify(int i,struct WORKER *mp){
char mod_name[20];
char temp[20];
int mi;
enum {false,true}status;
status=false;
printf("Enter the worker's name to modify:");
scanf("%s",mod_name);
/*調用search函數(在上面已經聲明了的),搜索到的話就返回工人的id,沒有的話就返回-1*/
if((mi=search(i,mp,1,mod_name))==-1)return;
/*下面的處理跟添加一個工人的資料的處理一模一樣,比較繁*/
printf("\nNow modify %s's profile...\n",mod_name);
while(status==false){
printf("Enter the name of the worker:");
scanf("%s",mp[mi].name);
if(strlen(mp[mi].name)==0 || strlen(mp[mi].name)>20){
status=false;puts("input error,name cannot over 8 character or less than 0 character!");
continue;
}
else
status=true;
printf("Enter the gender of worker:(1=>female,0=>male)");
scanf("%d",&mp[mi].sex);
if(mp[mi].sex!=0 && mp[mi].sex!=1){
status=false;puts("only 0 or 1 can be accepted!");
continue;
}
else
status=true;
printf("Enter the birthday of worker:\n");
printf("\tYear:");
scanf("%4d",&mp[mi].birthday.year);
if(mp[mi].birthday.year>9999 || mp[mi].birthday.year<0){
status=false;puts("input error,the year of birthday cannot more than 9999 or less than 0!");
continue;
}
else
status=true;
printf("\tMonth:");
scanf("%2d",&mp[mi].birthday.month);
if(mp[mi].birthday.month>12 || mp[mi].birthday.month<1){
status=false;puts("input error,the month of birthday cannot be more than 12 or less than 1");
continue;
}
else
status=true;
printf("\tDay:");
scanf("%2d",&mp[mi].birthday.day);
if(mp[mi].birthday.day>31 || mp[mi].birthday.day<1){
status=false;puts("input error,the year of birthday cannot be more than 31 or less than 1!");
continue;
}
else
status=true;
printf("Enter the workday of worker:\n");
printf("\tYear:");
scanf("%4d",&mp[mi].workday.year);
if(mp[mi].workday.year>9999 || mp[mi].workday.year<0){
status=false;puts("input error,the year of workday cannot more than 9999 or less than 0!");
continue;
}
else
status=true;
printf("\tMonth:");
scanf("%2d",&mp[mi].workday.month);
if(mp[mi].workday.month>12 || mp[mi].workday.month<1){
status=false;puts("input error,the month of workday cannot be more than 12 or less than 1");
continue;
}
else
status=true;
printf("\tDay:");
scanf("%2d",&mp[mi].workday.day);
if(mp[mi].workday.day>31 || mp[mi].workday.day<1){
status=false;puts("input error,the year of workday cannot be more than 31 or less than 1!");
continue;
}
else
status=true;
printf("Enter the record of formal schooling of worker:(0=>element school,1=>middle school,2=>high school,3=>university,4=>other)");
scanf("%d",&mp[mi].rofs);
if(mp[mi].rofs!=0 && mp[mi].rofs!=1 &&mp[mi].rofs!=2 &&mp[mi].rofs!=3 &&mp[mi].rofs!=4){
status=false;puts("only digit can be accepted!you can only enter 0,1,2,3,4");
continue;
}
else
status=true;
printf("Enter the position of worker:");
scanf("%s",mp[mi].position);
if(strlen(mp[mi].position)==0 || strlen(mp[mi].position)>20){
status=false;puts("input error,position cannot over 20 character or less than 0 character!");
continue;
}else
status=true;
printf("Enter the address of worker:\n");
printf("\tProvince:");
scanf("%s",mp[mi].addr.province);
if(strlen(mp[mi].addr.province)==0 || strlen(mp[mi].addr.province)>20){
status=false;puts("input error,province cannot over 20 character or less than 0 character!");
continue;
}
else
status=true;
printf("\tCity:");
scanf("%s",mp[mi].addr.city);
if(strlen(mp[mi].addr.city)==0 || strlen(mp[mi].addr.city)>20){
status=false;puts("input error,city cannot over 20 character or less than 0 character!");
continue;
}
else
status=true;
printf("\tStreet:");
scanf("%s",mp[mi].addr.street);
if(strlen(mp[mi].addr.street)==0 || strlen(mp[mi].addr.street)>30){
status=false;puts("input error,street cannot over 30 character or less than 0 character!");
continue;
}
else
status=true;
printf("Enter the telephone number of worker:(area code/telephone code)");
scanf("%s",mp[mi].tel);
if(strlen(mp[mi].tel)==0 || strlen(mp[mi].tel)>13){
status=false;puts("input error,telephone number cannot over 13 character or less than 0 character!");
continue;
}
else
status=true;
}
}
fclose(fp);
}
void main(void)
{
struct WORKER profile[maxworker];data_load(&i,profile);
do
{ if(k!=1)
{printf("\nPlease press any key to return to the main meun");
getch();}
k++;
clrscr();
initgraph(&GD,&GM,"e:\\tc\\bgi");
setbkcolor(LIGHTBLUE);
hz(200,20,40,2,10,"人事管理系統");
printf("\n\n\n\n\n");
printf("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("\t\t\t*3.Search one worker from the file\n");
printf("\t\t\t*4.Modify one worker's information\n");
printf("\t\t\t*0.exit without save\n\n\n");
printf("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("\t\t\tPlease input your selection number:");
scanf("%d",&selection);
switch(selection)
{
case 3:
search(i,profile,1,"");
break;
case 4:
modify(i,profile);
break;
case 0:
printf("Are you sure to exit without save?New data that you enter will be lost!(y/n)");
c=getch();
if(c=='y'||'Y')exit(0);
break;
default:
printf("please enter the correct selection!");
return 0;
}
}while(1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -