小編找到了一個(gè)特別好的職工管理系統(tǒng),分享給大家一份C語(yǔ)言職工管理系統(tǒng)的具體實(shí)現(xiàn)代碼,供大家參考,也謝謝這位網(wǎng)友的分享,具體內(nèi)容如下
魚(yú)臺(tái)ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書(shū)銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書(shū)合作)期待與您的合作!
person.cpp
#include "person.h" //首頁(yè) int Print_Head(int * num) { printf("\t***********************************************\n"); printf("\t| 職工管理系統(tǒng) |\n"); printf("\t*---------------------------------------------*\n"); printf("\t| 【1】新增 【2】刪改 |\n"); printf("\t* 【3】查詢 【4】退出 *\n"); printf("\t***********************************************\n"); printf("\t◎請(qǐng)輸入想進(jìn)行操作的序號(hào)【 】\b\b"); *num=getchar(); return SUCCESS; } //刪改畫(huà)面 int Print_DelRev(int* num) { printf("\t******************************************\n"); printf("\t* *\n"); printf("\t* 【1】刪除 【2】修改 【3】返回 *\n"); printf("\t* *\n"); printf("\t******************************************\n"); printf("\t◎請(qǐng)輸入想進(jìn)行操作的序號(hào)【 】\b\b"); *num=getchar(); return SUCCESS; } //查詢畫(huà)面 int Print_Que(int* num) { printf("\t******* ************************************\n"); printf("\t* *\n"); printf("\t* 【1】全部查詢 【2】工號(hào)查詢 *\n"); printf("\t* *\n"); printf("\t* 【3】模糊查詢 【4】返回菜單 *\n"); printf("\t* *\n"); printf("\t******************************************\n"); printf("\t◎請(qǐng)輸入想進(jìn)行操作的序號(hào)【 】\b\b"); *num=getchar(); return SUCCESS; } //增加畫(huà)面 int Print_Add(int* num) { int n=0; printf("\t******************************************\n"); printf("\t* *\n"); printf("\t* 【1】新增 【2】添加 【3】返回 *\n"); printf("\t* *\n"); printf("\t******************************************\n"); printf("\t◎請(qǐng)輸入想進(jìn)行操作的序號(hào)【 】\b\b"); *num=getchar(); return SUCCESS; } //標(biāo)題頭 int Print_Tittle() { printf("-------------------------------------------\n"); printf(" 工號(hào) | 姓名 |性別|年齡| 電話 \n"); printf("-------------------------------------------\n"); return SUCCESS; } //選擇將要打開(kāi)的文件 int File_name() { printf("\n\t◎請(qǐng)輸入您想要打開(kāi)的文件:"); //memset(filename,0,sizeof(filename)); if(scanf("%s", filename)!=1){ printf("\a 選擇文件錯(cuò)誤!"); return FAILED; } return SUCCESS; } //生成鏈表,參數(shù)n是add記錄數(shù)量 struct Employee *Creat() { printf("\n\t◎請(qǐng)輸入要添加的數(shù)據(jù)個(gè)數(shù):"); int n; if(scanf("%d", &n)!=1) { printf("\a error!"); } struct Employee *head; struct Employee *p1, *p2; system("cls"); for(int i=1;inum,p1->name,p1->sex, p1->age,p1->tel); p1->next = NULL; if(i==1) { head = p2 = p1; } else { p2->next = p1; p2 = p1; } } return(head); } //建立新文件 int WriteData_wb(struct Employee *head) { FILE *fp; struct Employee *p; if((fp = fopen(filename, "wb"))==NULL) printf("\a 打開(kāi)文件錯(cuò)誤!"); p = head; while(p!=NULL) { if(fwrite(p,SIZE,1,fp)!=1) { printf("\b 寫(xiě)入數(shù)據(jù)出錯(cuò)\n"); fclose(fp); return FAILED; } p=p->next; } fclose(fp); return SUCCESS; } //在已有文件添加 int WriteData_ab(struct Employee *head) { FILE *fp; struct Employee *p; if((fp = fopen(filename, "ab"))==NULL) printf("\a 打開(kāi)文件錯(cuò)誤!"); p = head; while(p!=NULL) { if(fwrite(p,SIZE,1,fp)!=1) { printf("\b 寫(xiě)入數(shù)據(jù)出錯(cuò)\n"); fclose(fp); return FAILED; } p=p->next; } fclose(fp); return SUCCESS; } //增加 int Emp_Add() { system("cls"); getchar(); int add; while(1){ system("cls"); Print_Add(&add); while(add!='1' && add!='2' && add!='3') { putchar('\a'); printf("◎請(qǐng)重新輸入有效序號(hào)(1~3):【 】\b\b"); add=getchar(); } switch(add){ case '1': WriteData_wb(Creat()); printf("\n◎新建文件成功數(shù)據(jù)已保存√\n"); system("pause"); system("cls"); Emp_Add(); break; case '2': WriteData_ab(Creat()); printf("\n◎數(shù)據(jù)已成功添加√\n"); system("pause"); system("cls"); Emp_Add(); break; case '3': system("cls"); getchar(); Emp_Return(); break; } } return SUCCESS; } //讀取文件的數(shù)據(jù)到鏈表中返回鏈表head指針 struct Employee *Read() { struct Employee *head = NULL; struct Employee *p1, *p2;//s = p1;p = p2; FILE *fp; if((fp=fopen(filename,"rb+"))==NULL) { printf("打開(kāi)文件出錯(cuò)\n"); exit(0); } while(!feof(fp)) { if((p1=(struct Employee*)malloc(SIZE))==NULL){ printf("內(nèi)存申請(qǐng)出錯(cuò)\n"); fclose(fp); exit(0); } if(fread(p1,SIZE,1,fp)!=1){ free(p1); break; } if(head==NULL) head=p2=p1; else{ p2->next=p1; p2=p1; } } fclose(fp); return (head); } //刪除 int Emp_Del() { struct Employee* head; struct Employee* pt1,*pt2; char str_num[10]; memset(str_num,0,sizeof(str_num)); printf("\n◎請(qǐng)輸入你要?jiǎng)h除的學(xué)號(hào)信息:"); scanf("%s",str_num); pt1=Read(); pt2=pt1->next; head=pt1; while(pt2!=NULL){ if(!strcmp(pt1->num,str_num)){ WriteData_wb(pt2); }else if(!strcmp(pt2->num,str_num)){ pt1->next=pt2->next; WriteData_wb(head); } pt2=pt2->next; pt1=pt1->next; } if(pt2!=NULL){ printf("\t◎沒(méi)有你要?jiǎng)h除的數(shù)據(jù)"); } return SUCCESS; } //修改 int Emp_Rev() { struct Employee* pt1,*pt2,*head; char str_num[10]; printf("\t◎請(qǐng)輸入要修改的學(xué)號(hào)信息:"); scanf("%s",str_num); pt1=Read(); pt2=pt1->next; head=pt1; while(pt2!=NULL){ if(strcmp(pt1->num,str_num)==0) { Print_Tittle(); scanf("%s%s%s%d%s",pt1->num,pt1->name,pt1->sex, pt1->age,pt1->tel); WriteData_wb(head); } else if(strcmp(pt2->num,str_num)==0) { Print_Tittle(); scanf("%s%s%s%d%s",pt1->num,pt1->name,pt1->sex, pt1->age,pt1->tel); WriteData_wb(head); } pt2 = pt2->next; pt1 = pt1->next; } if(pt2!=NULL) printf("數(shù)據(jù)庫(kù)中沒(méi)有存儲(chǔ)您要?jiǎng)h除的數(shù)據(jù)!\n"); return 0; } //刪改 int Emp_DelRev() { getchar(); int delrev=0; while(1){ system("cls"); Print_DelRev(&delrev); while(delrev!='1' && delrev!='2' && delrev!='3'){ putchar('\a'); //getchar(); printf("○請(qǐng)重新輸入有效序號(hào)(1~3):【 】\b\b"); delrev=getchar(); } switch(delrev){ case '1': Emp_Del(); printf("\n◎已成功刪除指定數(shù)據(jù)!"); system("pause"); getchar(); break; case '2': Emp_Rev(); printf("\n◎已成功修改指定數(shù)據(jù)!"); system("pause"); getchar(); break; case '3': system("cls"); getchar(); Emp_Return(); break; } } return SUCCESS; } //總體查詢 int Emp_QueAll() { struct Employee *pt; pt = Read(); Print_Tittle(); do { printf("%2s%5s%4s%2d%3s\n", pt->num,pt->name,pt->sex,pt->age,pt->tel); pt = pt->next; }while(pt!=NULL); printf("\n\n"); return SUCCESS; } //工號(hào)查詢 int Emp_QueNum() { struct Employee *pt; char str_num[10]; printf("\t◎請(qǐng)輸入您要查詢的學(xué)號(hào):"); scanf("%s", str_num); pt = Read(); Print_Tittle(); do { if(!strcmp(pt->num,str_num)) { printf("%2s%5s%4s%2d%3s\n", pt->num,pt->name,pt->sex,pt->age,pt->tel); printf("\n\n"); return 0; } pt = pt->next; }while(pt!=NULL); printf("\t數(shù)據(jù)庫(kù)中沒(méi)有存儲(chǔ)您要查詢的數(shù)據(jù)!\n"); printf("\n\n"); return SUCCESS; } //模糊查詢 int Emp_QueVague() { struct Employee *pt; char str_vague[20]; int m=0; printf("\t◎請(qǐng)輸入您要查詢的關(guān)鍵詞:"); scanf("%s", str_vague); pt = Read(); Print_Tittle(); do { if(strstr(pt->num,str_vague)!=0||strstr(pt->name,str_vague)!=0 ||strstr(pt->sex,str_vague)!=0||strstr(pt->age,str_vague)!=0 ||strstr(pt->tel,str_vague)!=0) { printf("%2s%5s%4s%2d%3s\n", pt->num,pt->name,pt->sex,pt->age,pt->tel); m = 1; } pt = pt->next; }while(pt!=NULL); if(!m) printf("數(shù)據(jù)庫(kù)中沒(méi)有存儲(chǔ)您要查詢的數(shù)據(jù)!\n"); printf("\n\n"); return SUCCESS; } //查詢 int Emp_Que() { system("cls"); int que; while(1){ system("cls"); Print_Que(&que); while(que!='1' && que!='2' && que!='3'){ putchar('\a'); printf("\t○請(qǐng)重新輸入有效序號(hào)(1~3):【 】\b\b"); que=getchar(); } switch(que){ case '1': Emp_QueAll(); system("pause"); getchar(); break; case '2': Emp_QueNum(); system("pause"); getchar(); break; case '3': Emp_QueVague(); system("pause"); getchar(); break; case '4': Emp_Return(); system("pause"); getchar(); break; } } return SUCCESS; } //返回 int Emp_Return() { Emp_Menu(); return SUCCESS; } //退出 void Emp_Quit() { printf("\n\t◎謝謝使用!"); system("pause"); exit(0); } //menu函數(shù) int Emp_Menu() { //int* Menu=NULL; int menu=0; //Print_Head(&Menu); //menu=*Menu; //delete Menu; //printf("%d\n",menu); Print_Head(&menu); while(menu!='1' && menu!='2' && menu!='3'&& menu!='4') { printf("error! please input the right number!\n"); putchar('\a'); //getchar(); printf("◎請(qǐng)重新輸入有效序號(hào)(1~4):【 】\b\b"); menu=getchar(); } switch(menu){ case '1': File_name(); Emp_Add(); break; case '2': File_name(); Emp_DelRev(); break; case '3': File_name(); Emp_Que(); break; case '4': Emp_Quit(); break; } return SUCCESS; } /*void Sig(int n) { printf("\n\t◎程序?qū)⒁顺?,操作已保存?); system("pause"); exit(0); }*/ int main() { //printf("\t◎使用Ctrl+C終止現(xiàn)在程序的運(yùn)行!\n"); //signal(SIGINT,Sig); Emp_Menu(); return SUCCESS; }
person.h
#ifndef __PERSON_H__ #define __PERSON_H_ #define _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1 #include#include #include #include #include #define SUCCESS 0 #define FAILED (!SUCCESS) #define SIZE sizeof(struct Employee) //全局變量 int flag=0;//返回標(biāo)志 char filename[30];//要打開(kāi)的文件名 //員工信息結(jié)構(gòu)體 struct Employee{ char name[20]; char tel[15]; char sex[5]; char num[10]; char age[3]; struct Employee* next; }; //建立一個(gè)鏈表 struct Employee* creat(int n); //主函數(shù) int Emp_Menu(); //首頁(yè)打印 int Print_Head(); //刪改打印 int Print_DelRev(); //增加打印 int Print_Add(); //表頭打印 int Print_Tittle(); //新建文件寫(xiě)入 int WriteData_wb(struct Employee *head); //在已有的文件寫(xiě)入 int WriteData_ab(struct Employee *head); //添加 int Emp_Add(); //刪除 int Emp_Del(); //修改 int Emp_Rev(); //查詢 int Emp_Que(); //返回 int Emp_Return(); //退出 void Emp_Quit(); #endif //__PERSON_H__
更多學(xué)習(xí)資料請(qǐng)關(guān)注專題《管理系統(tǒng)開(kāi)發(fā)》。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。