C語言實(shí)現(xiàn)職工管理系統(tǒng)
小編找到了一個(gè)特別好的職工管理系統(tǒng),分享給大家一份C語言職工管理系統(tǒng)的具體實(shí)現(xiàn)代碼,供大家參考,也謝謝這位網(wǎng)友的分享,具體內(nèi)容如下
person.cpp
#include "person.h"
//首頁
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;
}
//刪改畫面
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;
}
//查詢畫面
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;
}
//增加畫面
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;
}
//選擇將要打開的文件
int File_name()
{
printf("\n\t◎請(qǐng)輸入您想要打開的文件:");
//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;i<n+1;i++) {
p1 = (struct Employee*)malloc(SIZE);
Print_Tittle();
scanf("%s%s%s%d%s",p1->num,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 打開文件錯(cuò)誤!");
p = head;
while(p!=NULL) {
if(fwrite(p,SIZE,1,fp)!=1) {
printf("\b 寫入數(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 打開文件錯(cuò)誤!");
p = head;
while(p!=NULL) {
if(fwrite(p,SIZE,1,fp)!=1) {
printf("\b 寫入數(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("打開文件出錯(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◎沒有你要?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ù)庫中沒有存儲(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ù)庫中沒有存儲(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ù)庫中沒有存儲(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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <signal.h>
#define SUCCESS 0
#define FAILED (!SUCCESS)
#define SIZE sizeof(struct Employee)
//全局變量
int flag=0;//返回標(biāo)志
char filename[30];//要打開的文件名
//員工信息結(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();
//首頁打印
int Print_Head();
//刪改打印
int Print_DelRev();
//增加打印
int Print_Add();
//表頭打印
int Print_Tittle();
//新建文件寫入
int WriteData_wb(struct Employee *head);
//在已有的文件寫入
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)開發(fā)》。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C語言編寫學(xué)生成績(jī)管理系統(tǒng)
- C語言通訊錄管理系統(tǒng)完整版
- C語言實(shí)現(xiàn)圖書管理系統(tǒng)
- C語言職工信息管理系統(tǒng)源碼
- 學(xué)生信息管理系統(tǒng)C語言版
- C語言學(xué)生管理系統(tǒng)源碼分享
- C語言圖書管理系統(tǒng)簡(jiǎn)潔版
- 學(xué)生成績(jī)管理系統(tǒng)C語言代碼實(shí)現(xiàn)
- C語言數(shù)據(jù)結(jié)構(gòu)之學(xué)生信息管理系統(tǒng)課程設(shè)計(jì)
- C語言利用結(jié)構(gòu)體數(shù)組實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)
相關(guān)文章
利用C++11原子量如何實(shí)現(xiàn)自旋鎖詳解
當(dāng)自旋鎖嘗試獲取鎖時(shí)以忙等待(busy waiting)的形式不斷地循環(huán)檢查鎖是否可用,下面這篇文章主要給大家介紹了關(guān)于利用C++11原子量如何實(shí)現(xiàn)自旋鎖的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-06-06
C++線性表深度解析之動(dòng)態(tài)數(shù)組與單鏈表和棧及隊(duì)列的實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)動(dòng)態(tài)數(shù)組、單鏈表、棧、隊(duì)列,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
C++中簡(jiǎn)單讀寫文本文件的實(shí)現(xiàn)方法
本篇文章是對(duì)C++中簡(jiǎn)單讀寫文本文件的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
C++ 中時(shí)間與時(shí)間戳的轉(zhuǎn)換實(shí)例詳解
這篇文章主要介紹了C++ 中時(shí)間與時(shí)間戳的轉(zhuǎn)換實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-06-06
C++實(shí)現(xiàn)歸并排序(MergeSort)
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)歸并排序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04

