本文實(shí)例為大家分享了C語言職工信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
網(wǎng)站設(shè)計(jì)制作過程拒絕使用模板建站;使用PHP+MYSQL原生開發(fā)可交付網(wǎng)站源代碼;符合網(wǎng)站優(yōu)化排名的后臺管理系統(tǒng);成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、外貿(mào)網(wǎng)站建設(shè)收費(fèi)合理;免費(fèi)進(jìn)行網(wǎng)站備案等企業(yè)網(wǎng)站建設(shè)一條龍服務(wù).我們是一家持續(xù)穩(wěn)定運(yùn)營了10年的創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司。#include#include #include #include struct worker { char ID[20];//工號 char name[20];//姓名 char sex[5];//性別 char born[20];//生日 char edu[20];//學(xué)歷 char position[20];//職務(wù) char wage[10];//工資 char address[100];//住址 char tel[15];//電話 }work[1000]; int n ; //文件讀寫模塊 void read()//讀入數(shù)據(jù) { FILE *fp; int i = 0; if( (fp = fopen("d:\\date.txt","r")) == NULL ) { printf("請?jiān)贒盤根目錄下新建一個(gè)文本文件,文件名為date\n\n\n"); system("pause"); system("cls"); return ; } fscanf(fp,"%d\n",&n); while(i < n) { fscanf(fp,"%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",work[i].ID,work[i].name,work[i].sex,work[i].born,work[i].edu,work[i].position,work[i].wage,work[i].address,work[i].tel); i ++; } fclose(fp); } void write()//寫入數(shù)據(jù) { FILE *fp; int i = 0; if( (fp = fopen("d:\\date.txt","w")) == NULL ) { printf("無法打開文件!\n"); return ; } fprintf(fp,"%d\n",n); while(i < n) { fprintf(fp,"%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",work[i].ID,work[i].name,work[i].sex,work[i].born,work[i].edu,work[i].position,work[i].wage,work[i].address,work[i].tel); i ++; } fclose(fp); } //輸入模塊 void input()// 從鍵盤輸入 { int i; int flag;//標(biāo)記工號是否已存在 char c;//指令Y?N read();//輸入數(shù)據(jù)前先將文件中原有的數(shù)據(jù)讀入 do { flag = 0; printf("\t\t請輸入職工的工號: \n\t\t"); scanf("%s",work[n].ID); for(i = 0 ; i < n ; i ++) { if(strcmp(work[i].ID,work[n].ID) == 0) { flag = 1; break; } } if(flag) { printf("該工號已存在!\n\n"); printf("\t\t是否繼續(xù)輸入?(Y/N): "); scanf("%*c%c",&c); if(c == 'N' || c == 'n') break; continue; } printf("\t\t請輸入職工的姓名: \n\t\t"); scanf("%s",work[n].name); printf("\t\t請輸入職工的性別: \n\t\t"); scanf("%s",work[n].sex); printf("\t\t請輸入職工的出生年月: \n\t\t"); scanf("%s",work[n].born); printf("\t\t請輸入職工的學(xué)歷: \n\t\t"); scanf("%s",work[n].edu); printf("\t\t請輸入職工的職務(wù): \n\t\t"); scanf("%s",work[n].position); printf("\t\t請輸入職工的工資: \n\t\t"); scanf("%s",work[n].wage); printf("\t\t請輸入職工的住址: \n\t\t"); scanf("%s",work[n].address); printf("\t\t請輸入職工的電話: \n\t\t"); scanf("%s",work[n].tel); printf("\t\t是否繼續(xù)輸入?(Y/N): "); scanf("%*c%c",&c); n ++; }while( c != 'N' && c != 'n'); write(); printf("\n\n數(shù)據(jù)已保存!\n\n"); } //顯示模塊 void output_inf(int id) { printf("\t\t 工號: %s\n",work[id].ID); printf("\t\t 姓名: %s\n",work[id].name); printf("\t\t 性別: %s\n",work[id].sex); printf("\t\t出生年月: %s\n",work[id].born); printf("\t\t 學(xué)歷: %s\n",work[id].edu); printf("\t\t 職務(wù): %s\n",work[id].position); printf("\t\t 工資: %s\n",work[id].wage); printf("\t\t 住址: %s\n",work[id].address); printf("\t\t 電話: %s\n",work[id].tel); printf("\n\n\n"); } void show()//顯示所有職工信息 { int i; read(); if(n == 0) printf("無記錄!\n\n"); else for(i = 0 ; i < n ; i ++) { output_inf(i); } } //查詢模塊 void que()//查詢信息 { char num; int flag,i; char q_id[20] ;//查詢工號 char q_name[20] ;//查詢姓名 char q_edu[20] ; //查詢學(xué)歷 char q_position[20] ;//查詢職位 char c;//指令Y?N read();//打開程序后,要查詢以前的數(shù)據(jù),要先讀入 while(1) { system("cls"); printf("\t\t******************查詢********************\n"); printf("\t\t* *\n"); printf("\t\t* 1.按工號查詢 *\n"); printf("\t\t* *\n"); printf("\t\t* 2.按姓名查詢 *\n"); printf("\t\t* *\n"); printf("\t\t* 3.按學(xué)歷查詢 *\n"); printf("\t\t* *\n"); printf("\t\t* 4.按職務(wù)查詢 *\n"); printf("\t\t* *\n"); printf("\t\t* 輸入其他任意鍵退出本模塊 *\n"); printf("\t\t******************************************\n"); printf("\t\t請輸入指令(1-4):"); scanf("%*c%c",&num); if(num < '1' || num > '4') { printf("錯(cuò)誤指令!\n\n"); system("pause"); continue; } system("cls"); flag = 0;//用來標(biāo)記職工信息是否存在 if(num == '1')//按工號查詢 { printf("\t\t請輸入您要查詢職工的工號:"); scanf("%s",q_id); for(i = 0 ; i < n ;i ++) { if( strcmp(work[i].ID,q_id) == 0) { output_inf(i); flag = 1;//標(biāo)記 break; } } } else if(num == '2')//按姓名查詢 { printf("\t\t請輸入您要查詢職工的姓名:"); scanf("%s",q_name); for(i = 0 ; i < n ;i ++) { if( strcmp(work[i].name,q_name) == 0) { output_inf(i); flag = 1;//標(biāo)記 } } } else if(num == '3')//按學(xué)歷查詢 { printf("\t\t請輸入您要查詢職工的學(xué)歷:"); scanf("%s",q_edu); for(i = 0 ; i < n ;i ++) { if( strcmp(work[i].edu,q_edu) == 0) { output_inf(i); flag = 1;//標(biāo)記 } } } else if(num == '4')//按職務(wù)查詢 { printf("\t\t請輸入您要查詢職工的職務(wù):"); scanf("%s",q_position); for(i = 0 ; i < n ;i ++) { if( strcmp(work[i].position,q_position) == 0) { output_inf(i); flag = 1;//標(biāo)記 } } } if(!flag)//判斷是否有該職工信息 { printf("\n\n無該職工信息!\n\n"); } printf("\n\n是否繼續(xù)查詢(Y/N):"); scanf("%*c%c",&c); if(c == 'N' || c == 'n') break; } } //修改信息模塊 void mod()//修改職工信息 { char change_ID[20];//需修改的職工的工號 int number;//職工信息在數(shù)據(jù)中的位置 char num;//指令 char message[100];//修改的信息 char c;//指令Y?N int flag; int i; read(); while(1) { flag = 0; system("cls"); printf("請輸入需修改的職工的工號:"); scanf("%s",change_ID); for(i = 0 ; i < n ; i ++) { if( strcmp(work[i].ID,change_ID) == 0 ) { number = i; flag = 1; break; } } if(!flag) { printf("\n\n無此員工信息?。n\n"); printf("\n\n是否繼續(xù)修改(Y/N):"); scanf("%*c%c",&c); if(c == 'N' || c == 'n') break; continue; } printf("\n\n\t\t******************修改********************\n"); printf("\t\t* *\n"); printf("\t\t* 1.修改姓名 *\n"); printf("\t\t* *\n"); printf("\t\t* 2.修改學(xué)歷 *\n"); printf("\t\t* *\n"); printf("\t\t* 3.修改職務(wù) *\n"); printf("\t\t* *\n"); printf("\t\t* 4.修改工資 *\n"); printf("\t\t* *\n"); printf("\t\t* 5.修改住址 *\n"); printf("\t\t* *\n"); printf("\t\t* 6.修改電話 *\n"); printf("\t\t* *\n"); printf("\t\t* 輸入其他任意鍵退出本模塊 *\n"); printf("\t\t******************************************\n"); printf("\t\t請輸入指令(1-6):"); scanf("%*c%c",&num); if(num < '1' || num > '6') { printf("錯(cuò)誤指令!\n\n"); system("pause"); continue; } system("cls"); printf("請輸入修改后的信息:"); scanf("%s",message); switch(num) { case '1' : strcpy(work[number].name,message); break; case '2' : strcpy(work[number].edu,message); break; case '3' : strcpy(work[number].position,message); break; case '4' : strcpy(work[number].wage,message); break; case '5' : strcpy(work[number].address,message); break; case '6' : strcpy(work[number].tel,message); break; } system("cls"); printf("\n\n是否繼續(xù)修改(Y/N):"); scanf("%*c%c",&c); if(c == 'N' || c == 'n') break; } write(); } //刪除信息模塊 void del()//刪除職工信息 { char delete_ID[20];//刪除職工工號 int i,j; int flag;//標(biāo)記是否有該職工信息 char c; read(); while(1) { system("cls"); flag = 0; printf("請輸入需刪除職工信息的工號:"); scanf("%s",delete_ID); for(i = 0 ; i < n ; i ++) { if( strcmp(work[i].ID,delete_ID) == 0) { n --; flag = 1; for(j = i ; j < n ; j ++) { work[j] =work[j + 1]; } break; } } if(!flag) printf("\n\n無此員工信息!\n\n"); else printf("\n\n刪除成功!\n"); printf("\n\n是否繼續(xù)刪除(Y/N):"); scanf("%*c%c",&c); if(c == 'N' || c == 'n') break; } write(); } //菜單模塊 void menu()//菜單 { printf("\t\t************職工信息管理系統(tǒng)菜單**********\n"); printf("\t\t* *\n"); printf("\t\t* 1.錄入職工信息 *\n"); printf("\t\t* *\n"); printf("\t\t* 2.顯示職工信息 *\n"); printf("\t\t* *\n"); printf("\t\t* 3.查詢職工信息 *\n"); printf("\t\t* *\n"); printf("\t\t* 4.修改職工信息 *\n"); printf("\t\t* *\n"); printf("\t\t* 5.刪除職工信息 *\n"); printf("\t\t* *\n"); printf("\t\t* 0.退出 *\n"); printf("\t\t* *\n"); printf("\t\t******************************************\n"); printf("\t\t請輸入指令(0-5): "); } int main() { int num; n = 0; system("color 0B"); while(1) { menu(); scanf("%d",&num); system("cls"); switch(num) { case 1: input(); break; case 2: show(); break; case 3: que(); break; case 4: mod(); break; case 5: del(); break; case 0: printf("謝謝使用!\n\n"); return 0; default :printf("\n--->無效的指令!\n\n\n"); } system("pause"); system("cls"); } }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.cdcxhl.com,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。