diff --git a/worker.txt b/worker.txt new file mode 100644 index 0000000..a3a548b Binary files /dev/null and b/worker.txt differ diff --git a/职工工作量统计.c b/职工工作量统计.c new file mode 100644 index 0000000..253a1aa --- /dev/null +++ b/职工工作量统计.c @@ -0,0 +1,278 @@ +#include "stdio.h" +#include "stdlib.h" +#define FILENAME "worker.txt" +#define N 20 +/******************************************************* + +*******************************************************/ +struct worker +{ + int number; /**/ + int counts; /**/ + int grade; /**/ +}; +/******************************************************* +ʾ˵ +*******************************************************/ +void xinxi() +{ + printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); + printf("+ ְͳϵͳ +\n"); + printf("+ +\n"); + printf("+ 1. ְϢ +\n"); + printf("+ +\n"); + printf("+ 2. +\n"); + printf("+ +\n"); + printf("+ 3. +\n"); + printf("+ +\n"); + printf("+ 4. ְŽϢɾ +\n"); + printf("+ +\n"); + printf("+ 5. +\n"); + printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); +} +/******************************************************* +ϢʾĻ +*******************************************************/ +int readFromFile(struct worker w[]) +{ + FILE *fp = NULL; + int i = 0; + fp = fopen(FILENAME, "rb"); /*ļ*/ + if (fp != NULL) + { + while (!feof(fp)) /*ļжѧ*/ + { + if (i >= N) + break; + if (fread(w + i, sizeof(struct worker), 1, fp) == 1) + i++; + } + fclose(fp); + } + return i; +} +/******************************************************* +:ְϢ +*******************************************************/ +int f(struct worker w[], int length) +{ + FILE *fp; + if ((fp = fopen(FILENAME, "ab+")) == NULL) + { + exit(0); + } + int i = length; + while (i < N) { + printf("%dְ\n", i); + printf("\n"); + printf("빤(ְΪ0):\n");/*빤*/ + scanf("%d", &w[i].number); + if (w[i].number == 0) + break; + printf("\n"); + printf("\n"); + printf(":\n");/**/ + scanf("%d", &w[i].counts); + fwrite(&w[i], sizeof(struct worker), 1, fp); + printf("\n"); + i++; + } + fclose(fp); + return i; +} +/******************************************************* +:벢ۼ +*******************************************************/ +void input(struct worker w[], int length) +{ + + int i = 1; + int number, counts; + printf("빤:"); + scanf("%d", &number); + while (number != 0) + { + printf(":\n"); + scanf("%d", &counts); + for (i = 0; i < length; i++) + if (w[i].number == number) + { + w[i].counts += counts; + break; + } + if (i >= length) + printf("Ų:\n"); + printf("빤:"); + scanf("%d", &number); + } + FILE *fp; + if((fp=fopen("worker.txt","wb"))==NULL) + { + printf("cannot open this file!\n"); + exit(0); + } + for(i=0;i w[k].counts) + k = j; + /* w[i] and w[k] */ + s = w[k]; + w[k] = w[i]; + w[i] = s; + } + if (length > 0) + w[0].grade = 1; + for (i = 1; i < length; i++) + if (w[i].counts == w[i - 1].counts) + w[i].grade = w[i - 1].grade; + else + w[i].grade = w[i - 1].grade + 1; +} +//////////////////////////////////////////////////////////////////////////////// +/* ΡͬһεְǵĹţ*/ +/////////////////////////////////////////////////////////////////////////////// +void sortNumber(struct worker w[], int length) +{ + int i = 0; + int grade, count; + if (length > 0) + { + while (i < length) + { + count = 0; + grade = w[i].grade; + printf(":%d ", grade); + printf(" :%d ", w[i].counts); + printf("%s", ":"); + while (i < length) + { + if (grade == w[i].grade) + { + printf("%d ", w[i].number); + count++; + } + else + break; + i++; + } + printf(":%d\n", count); + } + } + else + printf("ְݲ!\n"); +} +/******************************************************** +ְɾְϢ +********************************************************/ +int delet(struct worker w[], int length, int stuNum) +{ + int i, j; + char choice; + for (i = 0; i < length; i++) + { + if (stuNum == w[i].number) + { + printf("ɾְΪ"); + printf("%d\n", w[i].number); + break; + } + } + if (i < length) + { + printf("ȷʵҪɾְ?(Y/N)"); + scanf("%c", &choice); + if (choice == 'Y' || choice == 'y') + { + for (j = i; j < length; j++) + w[j] = w[j + 1]; + length--; + printf("ɾɹ!\n"); + } + } + else + printf("\nְָ!\n"); + FILE *fp; + if((fp=fopen("worker.txt","wb"))==NULL) + { + printf("cannot open this file!\n"); + exit(0); + } + for(i=0;i