文章目录

  • 综合实验二:学生成绩管理系统
    • 1、要求
    • 2、代码
  • 综合实验五 :万年历系统
    • 1、要求
    • 2、代码
  • 综合实验八:职工信息管理系统
    • 1、要求
    • 2、代码

综合实验二:学生成绩管理系统

1、要求

(一)程序运行时,首先显示主菜单如下:

  1. 新建数据
  2. 添加数据
  3. 删除数据
  4. 排序
  5. 查询
  6. 退出

屏幕提示:请输入序号选择相应操作。
要求当用户输入任一序号后,程序都能进行相应操作。

(二)在主菜单中选择序号4,弹出子菜单选择排序方式,子菜单如下:

  1. 数学成绩排序
  2. 程序设计成绩排序
  3. 总分排序。
  4. 返回主菜单

请按序号选择相应操作。
选择子菜单的序号后,程序能正确运行并在屏幕上显示按要求排序后的相关信息。
(三)在主菜单中选择序号5,弹出子菜单选择查询方式,子菜单如下:

  1. 学号查询
  2. 姓名查询
  3. 数学成绩查询
  4. 程序设计成绩查询
  5. 总分查询
  6. 返回主菜单

请按序号选择相应操作。

在子菜单中选择序号后,程序按以下方式工作:

1)学号查询:输入学号后,若该学号存在则显示与其相关的所有信息,否则显示找不到的提示信息;(提示:查询到满足条件的结果后,查询即可结束)
2)姓名查询:输入姓名后,若该姓名存在则显示与其相关的所有信息,否则显示找不到的提示信息;(提示:使用字符串比较函数进行比较)
3)按科目查询:输入指定分数,程序运行后显示该科目中考试成绩大于等于指定分数的同学的学号、姓名以及该科成绩并统计满足条件的人数;
4)总分查询:输入指定分数,程序运行后显示总分成绩大于等于指定分数的同学的学号、姓名以及各科成绩并统计满足条件的人数。

2、代码

#include<stdio.h>
#include<windows.h>
#include<stdlib.h>
#include<string.h>
typedef struct Node
{long int ID;// 学号char Name[50];// 姓名int Math;// 数学成绩int C;// 程序设计成绩int Score;// 总分struct Node* next;// 指针域
}node;node list;// 链表// 读取文件
int Read_FILE(node* L);// 保存文件
int  Save_FILE(node* L);// 主菜单界面
void welcome();// 新建学生信息
void Build(node* L);// 增加学生信息
void Add(node* L, node e);// 功能
void Add_Printf();// 界面// 删除学生信息
void Delete_Printf(node* L);// 界面
void Delete(node* s);// 功能// 排序学生信息
void Sort(node* L);
void Print(node* L);// 输出学生信息
void Print_Printf();// 界面
bool cmp_big_Math(node e1, node e2);// 数学成绩从大到小
bool cmp_small_Math(node e1, node e2);// 数学成绩从小到大
bool cmp_big_C(node e1, node e2);// 程序设计成绩从大到小
bool cmp_small_C(node e1, node e2);// 程序设计成绩从小到大
bool cmp_big_Score(node e1, node e2);// 成绩从大到小
bool cmp_small_Score(node e1, node e2);// 成绩从小到大// 查询学生信息
void Search_Printf(node* L);// 界面
node* Search_id(int id, node* L);// 按学号进行查找
node* Search_name(char name[], node* L);// 按姓名进行查找
void Search_math(int math, node* L);// 按数学成绩进行查找
void Search_c(int c, node* L);// 按程序设计成绩进行查找
void Search_score(int score, node* L);// 按总分进行查找// 退出管理系统
void goodbye();int main()
{int choice = 0;Read_FILE(&list);while (true){welcome();scanf("%d", &choice);switch (choice){case 1:// 新建学生信息Build(&list);break;case 2:// 增加学生信息Add_Printf();break;case 3:// 删除学生信息Delete_Printf(&list);break;case 4:// 排序学生信息Sort(&list);break;case 5:// 查询学生信息Search_Printf(&list);break;case 6:// 退出管理系统goodbye();break;}printf("是否需要继续操作?(Yes:1 / No:0):");scanf("%d", &choice);if (choice == 0){break;}}return 0;
}void welcome()
{system("cls");printf("****************************************************************\n");printf("***********             学生成绩管理系统             ***********\n");printf("***********          1 ---- 新建学生信息             ***********\n");printf("***********          2 ---- 增加学生信息             ***********\n");printf("***********          3 ---- 删除学生信息             ***********\n");printf("***********          4 ---- 排序学生信息             ***********\n");printf("***********          5 ---- 查询学生信息             ***********\n");printf("***********          6 ---- 退出管理系统             ***********\n");printf("****************************************************************\n");printf("请选择想要实现的功能(数字):");
}// 读取文件
int Read_FILE(node* L)
{FILE* pfRead = fopen("student_information.txt", "r");node st;node* s;node* t = L;if (pfRead == NULL){return 0;}while (fscanf(pfRead, "%ld %s %d %d %d", &st.ID, st.Name, &st.Math, &st.C, &st.Score) != EOF){s = (node*)malloc(sizeof(node));*s = st;// 尾插法t->next = s;t = s;t->next = NULL;}return 1;
}// 保存文件
int Save_FILE(node* L)
{FILE* pfWrite = fopen("student_information.txt", "w");if (pfWrite == NULL){return 0;}node* p = L->next;while (p != NULL){fprintf(pfWrite, " %ld %s %d %d %d\n", p->ID, p->Name, p->Math, p->C, p->Score);p = p->next;}return 1;
}// 新建学生信息
void Build(node* L)
{node* p, * q;p = L->next;while (p != NULL) {q = p->next;free(p);p = q;}L->next = NULL;printf("新建成功!\n");
}// 增加学生信息
void Add_Printf()
{system("cls");node st;printf("请输入新增学生的相关信息:\n");printf("学号:");scanf("%ld", &st.ID);printf("姓名:");scanf("%s", st.Name);printf("数学成绩:");scanf("%d", &st.Math);printf("程序设计成绩:");scanf("%d", &st.C);st.Score = st.Math + st.C;Add(&list, st);
}void Add(node* L, node e)
{// 头插法node* p = L;node* s = (node*)malloc(sizeof(node));*s = e;s->next = p->next;p->next = s;Save_FILE(L);
}// 删除学生信息
void Delete_Printf(node* L)
{system("cls");long int id;node* p;printf("请输入要删除的学生的学号:");scanf("%ld", &id);node* st = Search_id(id, L);p = st;if (st == NULL){printf("查无此人!\n");return;}st = st->next;printf("________________________________________________________\n");printf("|学号\t|姓名\t|数学成绩\t|程序设计成绩\t|总分\t|\n");printf("________________________________________________________\n");printf("%ld|%s\t|%d\t\t|%d\t\t|%d\t|\n", st->ID, st->Name, st->Math, st->C, st->Score);printf("________________________________________________________\n");Delete(p);// 保存信息Save_FILE(L);
}void Delete(node* s)
{node* t = s->next;s->next = t->next;t->next = NULL;free(t);
}// 排序学生信息
void Sort(node* L)
{while (1){system("cls");int choice1 = 0, choice2 = 0;printf("按照数学成绩排序     ---- 1\n");printf("按照程序设计成绩排序 ---- 2\n");printf("按照总分排序         ---- 3\n");printf("返回主菜单           ---- 4\n");printf("请选择排序方式:");scanf("%d", &choice1);system("cls");if (choice1 == 1 || choice1 == 2 || choice1 == 3){printf("从大到小排序 ---- 1\n");printf("从小到大排序 ---- 2\n");printf("请选择排序方式:");scanf("%d", &choice2);}int flag = 0;for (node* p = L->next; p != NULL; p = p->next){for (node* q = p; q != NULL; q = q->next){switch (choice1){case 1:if (choice2 == 1) {if (!cmp_big_Math(*p, *q)){flag = 1;}}else if (choice2 == 2){if (!cmp_small_Math(*p, *q)){flag = 1;}}break;case 2:if (choice2 == 1) {if (!cmp_big_C(*p, *q)){flag = 1;}}else if (choice2 == 2){if (!cmp_small_C(*p, *q)){flag = 1;}}break;case 3:if (choice2 == 1){if (!cmp_big_Score(*p, *q)){flag = 1;}}else if (choice2 == 2){if (!cmp_small_Score(*p, *q)){flag = 1;}}break;case 4:return;}if (flag == 1){// 交换数据域node t = *p;*p = *q;*q = t;// 处理指针域t.next = p->next;p->next = q->next;q->next = t.next;flag = 0;}}}Print(L);printf("是否继续排序该学生信息?(Yes:1 / No:0):");scanf("%d", &choice1);if (choice1 == 0){break;}}
}// 输出学生信息
void Print(node* L)
{system("cls");node* p = L->next;Print_Printf();if (p != NULL){while (p != NULL){printf("________________________________________________________\n");printf("%ld|%s\t|%d\t\t|%d\t\t|%d\t|\n", p->ID, p->Name, p->Math, p->C, p->Score);printf("________________________________________________________\n");p = p->next;}}
}void Print_Printf()
{printf("________________________________________________________\n");printf("|学号\t|姓名\t|数学成绩\t|程序设计成绩\t|总分\t|\n");printf("________________________________________________________\n");
}// 数学成绩从大到小
bool cmp_big_Math(node e1, node e2)
{return e1.Math > e2.Math;
}// 数学成绩从小到大
bool cmp_small_Math(node e1, node e2)
{return e1.ID < e2.ID;
}// 程序设计成绩从大到小
bool cmp_big_C(node e1, node e2)
{return e1.C > e2.C;
}// 程序设计成绩从小到大
bool cmp_small_C(node e1, node e2)
{return e1.C < e2.C;
}// 成绩从大到小
bool cmp_big_Score(node e1, node e2)
{return e1.Score > e2.Score;
}// 成绩从小到大
bool cmp_small_Score(node e1, node e2)
{return e1.Score < e2.Score;
}// 查询学生信息
void Search_Printf(node* L)
{while (1){system("cls");int choice = 0;printf("学号查询         ---- 1\n");printf("姓名查询         ---- 2\n");printf("数学成绩查询     ---- 3\n");printf("程序设计成绩查询 ---- 4\n");printf("总分查询         ---- 5\n");printf("返回主菜单       ---- 6\n");printf("请输入查询方式:");scanf("%d", &choice);int id, math, c, score;char name[50];node* st;if (choice == 1){printf("请输入要查询的学号:");scanf("%d", &id);st = Search_id(id, L);if (st == NULL){printf("查无此人!\n");}else{st = st->next;printf("________________________________________________________\n");printf("|学号\t|姓名\t|数学成绩\t|程序设计成绩\t|总分\t|\n");printf("________________________________________________________\n");printf("%ld|%s\t|%d\t\t|%d\t\t|%d\t|\n", st->ID, st->Name, st->Math, st->C, st->Score);printf("________________________________________________________\n");}}else if (choice == 2){printf("请输入要查询的姓名:");scanf("%s", name);st = Search_name(name, L);if (st == NULL){printf("查无此人!\n");}else{st = st->next;printf("________________________________________________________\n");printf("|学号\t|姓名\t|数学成绩\t|程序设计成绩\t|总分\t|\n");printf("________________________________________________________\n");printf("%ld|%s\t|%d\t\t|%d\t\t|%d\t|\n", st->ID, st->Name, st->Math, st->C, st->Score);printf("________________________________________________________\n");}}else if (choice == 3){printf("请输入要查询的数学成绩:");scanf("%d", &math);Search_math(math, L);}else if (choice == 4){printf("请输入要查询的程序设计成绩:");scanf("%d", &c);Search_c(c, L);}else if (choice == 5){printf("请输入要查询的总分:");scanf("%d", &score);Search_score(score, L);}else if (choice == 6)return;printf("是否继续查询该学生信息?(Yes:1 / No:0):");scanf("%d", &choice);if (choice == 0){break;}}
}// 按学号进行查找
node* Search_id(int id, node* L)
{node* p = L;while (p->next != NULL){if (p->next->ID == id){return p;}p = p->next;}return NULL;
}// 按姓名进行查找
node* Search_name(char name[], node* L)
{node* p = L;while (p->next != NULL){if (strcmp(name, p->next->Name) == 0){return p;}p = p->next;}return NULL;
}// 按数学成绩进行查找
void Search_math(int math, node* L)
{node* p = L;int count = 0;while (p->next != NULL){if (p->next->Math >= math){if(!count){printf("________________________________________________________\n");printf("|学号\t|姓名\t|数学成绩\t|程序设计成绩\t|总分\t|\n");printf("________________________________________________________\n");}printf("________________________________________________________\n");printf("%ld|%s\t|%d\t\t|%d\t\t|%d\t|\n", p->next->ID, p->next->Name, p->next->Math, p->next->C, p->next->Score);printf("________________________________________________________\n");count++;}p = p->next;}if (count)printf("满足条件的人数:%d\n", count);elseprintf("没有满足条件的人!\n");
}// 按程序设计成绩进行查找
void Search_c(int c, node* L)
{node* p = L;int count = 0;while (p->next != NULL){if (p->next->C >= c){if (!count){printf("________________________________________________________\n");printf("|学号\t|姓名\t|数学成绩\t|程序设计成绩\t|总分\t|\n");printf("________________________________________________________\n");}printf("________________________________________________________\n");printf("%ld|%s\t|%d\t\t|%d\t\t|%d\t|\n", p->next->ID, p->next->Name, p->next->Math, p->next->C, p->next->Score);printf("________________________________________________________\n");count++;}p = p->next;}if (count)printf("满足条件的人数:%d\n", count);elseprintf("没有满足条件的人!\n");
}// 按总分进行查找
void Search_score(int score, node* L)
{node* p = L;int count = 0;while (p->next != NULL){if (p->next->Score >= score){if (!count){printf("________________________________________________________\n");printf("|学号\t|姓名\t|数学成绩\t|程序设计成绩\t|总分\t|\n");printf("________________________________________________________\n");}printf("________________________________________________________\n");printf("%ld|%s\t|%d\t\t|%d\t\t|%d\t|\n", p->next->ID, p->next->Name, p->next->Math, p->next->C, p->next->Score);printf("________________________________________________________\n");count++;}p = p->next;}if (count)printf("满足条件的人数:%d\n", count);elseprintf("没有满足条件的人!\n");
}// 退出管理系统
void goodbye()
{system("cls");printf("欢迎下次使用学生信息管理系统!");exit(0);// 结束程序
}

综合实验五 :万年历系统

1、要求

  1. 日期对星期的转换。
  2. 输出指定日期N天后的日期。
  3. 输出当前日期。
  4. 输出指定日期的节假日。
  5. 判断指定年是否是闰年还是平年。

2、代码

#include<stdio.h>
#include<windows.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
int year, month, day;int d[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31} };
int run[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
int ping[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
char weekday[7][10] = { "星期一","星期二","星期三","星期四","星期五","星期六","星期日" };// 表头
void welcome();
// 打印星号
void print_star();// 平闰年判断
int leap(int year);
// 计算输入的 year 与 1900年有多少天
int day_sum(int year, int month, int day, int run[], int ping[]);
// 打印日历
void print(int sum,int year,int month);// 日期转换
void week_day();
// 判断星期几
int caculateWeekDay(int year, int month, int day);// N天后日期
void ndays();// 当前日期
void time_now();// 求节假日
void fest();
int festival(int year1, int month1, int day1, int iWeek);// 判断平闰
void pingrun();// 退出万年历系统
void goodbye();int main()
{int choice = 0;printf("请输入当前日期(年、月、日):");scanf("%d %d %d", &year, &month, &day);while (1){welcome();int sum = day_sum(year, month, day, run, ping);print(sum, year, month);printf("请选择想要实现的功能(数字):");scanf("%d", &choice);switch (choice){case 1:// 日期转换week_day();break;case 2:// N天后日期ndays();break;case 3:// 当前日期time_now();break;case 4:// 求节假日fest();break;case 5:// 判断平闰pingrun();break;case 6:// 退出系统goodbye();break;}printf("是否需要继续操作?(Yes:1 / No:0):");scanf("%d", &choice);if (choice == 0){break;}}goodbye();return 0;
}// 表头
void welcome()
{system("cls");print_star();printf("***********                 万年历系统                  ***********\n");printf("***********             1 ---- 日期转换                 ***********\n");printf("***********             2 ---- N天后日期                ***********\n");printf("***********             3 ---- 当前日期                 ***********\n");printf("***********             4 ---- 求节假日                 ***********\n");printf("***********             5 ---- 判断平闰                 ***********\n");printf("***********             6 ---- 退出系统                 ***********\n");print_star();print_star();for (int i = 0; i < 7; i++)printf("\t%s", weekday[i]);printf("\n");
}// 打印星号
void print_star()
{printf("*******************************************************************\n");
}// 平闰年判断
int leap(int year)
{int four, hundred, fourhundred;four = year % 4;hundred = year % 100;fourhundred = year % 400;if (four == 0 && hundred == 0 && fourhundred == 0){return 1;}else if (four == 0 && hundred != 0 && fourhundred != 0){return 1;}return 0;
}// 计算输入的 year 与 1900年有多少天
int day_sum(int year, int month, int day, int run[], int ping[])
{// 1900 1 1 :星期一int sum = 0;for (int i = 1900; i <= year + 1; i++){int flag = leap(year);// 判断平闰年if (flag == 1){sum += 366;}else{sum += 365;}}// 加上月份的天数for (int i = 0; i < month - 1; i++){if (leap(year) == 1){sum += run[i];}else{sum += ping[i];}}return sum;
}// 打印日历
void print(int sum, int year, int month)
{int result, temp, i;result = sum % 7;// 计算前面空余的天数for (i = 0; i < result; i++){printf("\t");}temp = 7 - result;// 从第几格开始打印1号if (leap(year) == 1){for (i = 1; i <= run[month - 1]; i++)// 打印31天{printf("\t%d", i);if (i == temp || (i - temp) % 7 == 0)printf("\n");}printf("\n");}else{for (i = 1; i <= ping[month - 1]; i++)// 打印30天{printf("\t%d", i);if (i == temp || (i - temp) % 7 == 0)printf("\n");}printf("\n");}print_star();
}// 日期转换
void week_day()
{system("cls");int year1, month1, day1, iWeek;printf("请输入需要转换的年月日:");scanf("%d %d %d", &year1, &month1, &day1);iWeek = caculateWeekDay(year1, month1, day1);switch (iWeek)//iWeek获得返回值{case 0: printf("%4d年%2d月%2d日是星期一\n", year1, month1, day1); break;case 1: printf("%4d年%2d月%2d日是星期二\n", year1, month1, day1); break;case 2: printf("%4d年%2d月%2d日是星期三\n", year1, month1, day1); break;case 3: printf("%4d年%2d月%2d日是星期四\n", year1, month1, day1); break;case 4: printf("%4d年%2d月%2d日是星期五\n", year1, month1, day1); break;case 5: printf("%4d年%2d月%2d日是星期六\n", year1, month1, day1); break;case 6: printf("%4d年%2d月%2d日是星期日\n", year1, month1, day1); break;}
}// 判断星期几
int caculateWeekDay(int year, int month, int day)
{int iWeek;// 基姆拉尔森计算公式W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7if (month == 1 || month == 2) {// 1月和2月看作上一年13月和14月month += 12;year--;}return iWeek = (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400) % 7;
}// N天后日期
void ndays()
{system("cls");int year1 = year, month1 = month, day1 = day, n, k;printf("请输入天数:");scanf("%d", &n);day1 += n;k = month;for (; day1 > d[leap(year1)][k]; k++){day1 -= d[leap(year1)][k];if (k == 12)k = 0, year1++;}month1 = k;printf("N天后为:%04d年%02d月%02d日\n", year1, month1, day1);
}// 当前日期
void time_now()
{system("cls");printf("现在是%4d年%2d月%2d日!\n", year, month, day);
}// 求节假日
void fest()
{system("cls");int year1, month1, day1, iWeek;printf("请输入要查询的日期:");scanf("%d %d %d", &year1, &month1, &day1);iWeek = caculateWeekDay(year1, month1, day1);if (festival(year1, month1, day1, iWeek))printf("%4d年%2d月%2d日是节假日!\n", year1, month1, day1);elseprintf("%4d年%2d月%2d日不是节假日!\n", year1, month1, day1);
}
int festival(int year1, int month1, int day1, int iWeek)
{if (month1 == 1){if (day1 <= 3)return 1;}if (month1 == 4){if (day1 >= 3 && day1 <= 5)return 1;}if (month1 == 5){if (day1 <= 5)return 1;}if (month1 == 6){if (day1 >= 3 && day1 <= 5)return 1;}if (month1 == 9){if (day1 >= 10 && day1 <= 12)return 1;}if (month1 == 10){if (day1 <= 7)return 1;}if (iWeek >= 5)return 1;return 0;
}// 判断平闰
void pingrun()
{system("cls");int year1;printf("请输入要判断的年份:");scanf("%d", &year1);if (leap(year1) == 1)printf("%d为闰年!\n", year1);elseprintf("%d为平年!\n", year1);
}// 退出万年历系统
void goodbye()
{printf("欢迎下次使用万年历系统!");exit(0);// 结束程序
}

综合实验八:职工信息管理系统

1、要求

职工信息包括职工号、姓名、性别、年龄、学历、职务、工资、住址、电话等(职工号不重复)。试设计一职工信息管理系统,使之能提供以下功能:

  • 职工信息录入功能(职工信息用文件保存)
  • 职工信息浏览功能
  • 查询或排序功能:(至少一种查询方式)
    (1)按工资查询
    (2)按学历查询等
  • 职工信息删除、修改功能

2、代码

#include<stdio.h>
#include<windows.h>
#include<stdlib.h>
#include<string.h>
typedef struct Node
{int ID;// 工号char Name[50];// 姓名char Sex[10];// 性别int Age;// 年龄char Education[20];// 学历char Post[20];// 职务int Wage;// 工资char Room[50];// 住址char Telephone[20];// 电话struct Node* next;// 指针域
}node;node list;// 链表// 读取文件
int Read_FILE(node* L);// 保存文件
int  Save_FILE(node* L);// 主菜单界面
void welcome();// 增加职工信息
void Add(node* L, node e);// 功能
void Add_Printf();// 界面// 删除职工信息
void Delete_Printf(node* L);// 界面
void Delete(node* s);// 功能// 修改职工信息
void Fix(node* L);// 查询职工信息
void Search_Printf(node* L);// 界面
node* Search_id(int id, node* L);// 按工号进行查找
node* Search_name(char name[], node* L);// 按姓名进行查找// 输出职工信息
void Print(node* L);// 功能
void Print_Printf();// 界面// 排序职工信息
void Sort(node* L);
bool cmp_big_Wage(node e1, node e2);// 工资从大到小
bool cmp_small_Wage(node e1, node e2);// 工资从小到大// 退出管理系统
void goodbye();int main()
{int choice = 0;Read_FILE(&list);while (true){welcome();scanf("%d", &choice);switch (choice){case 1:// 增加职工信息Add_Printf();break;case 2:// 删除职工信息Delete_Printf(&list);break;case 3:// 修改职工信息Fix(&list);break;case 4:// 查询职工信息Search_Printf(&list);break;case 5:// 输出职工信息Print(&list);break;case 6:// 排序职工信息Sort(&list);break;case 0:// 退出职工系统goodbye();break;}printf("是否需要继续操作?(Yes:1 / No:0):");scanf("%d", &choice);if (choice == 0){break;}}return 0;
}void welcome()
{system("cls");printf("****************************************************************\n");printf("***********             职工信息管理系统             ***********\n");printf("***********          1 ---- 增加职工信息             ***********\n");printf("***********          2 ---- 删除职工信息             ***********\n");printf("***********          3 ---- 修改职工信息             ***********\n");printf("***********          4 ---- 查询职工信息             ***********\n");printf("***********          5 ---- 输出职工信息             ***********\n");printf("***********          6 ---- 排序职工信息             ***********\n");printf("***********          0 ---- 退出管理系统             ***********\n");printf("****************************************************************\n");printf("请选择想要实现的功能(数字):");
}// 读取文件
int Read_FILE(node* L)
{FILE* pfRead = fopen("worker_information.txt", "r");node st;node* s;node* t = L;if (pfRead == NULL){return 0;}while (fscanf(pfRead, "%d %s %s %d %s %s %d %s %s", &st.ID, st.Name, st.Sex, &st.Age, st.Education, st.Post, &st.Wage, st.Room, st.Telephone) != EOF){s = (node*)malloc(sizeof(node));*s = st;// 尾插法t->next = s;t = s;t->next = NULL;}return 1;
}// 保存文件
int  Save_FILE(node* L)
{FILE* pfWrite = fopen("worker_information.txt", "w");if (pfWrite == NULL){return 0;}node* p = L->next;while (p != NULL){fprintf(pfWrite, "%d %s %s %d %s %s %d %s %s\n", p->ID, p->Name, p->Sex, p->Age, p->Education, p->Post, p->Wage, p->Room, p->Telephone);p = p->next;}return 1;
}// 增加职工信息
void Add_Printf()
{system("cls");node st;printf("请输入新增职工的相关信息:\n");printf("工号:");scanf("%d", &st.ID);printf("姓名:");scanf("%s", st.Name);printf("性别:");scanf("%s", st.Sex);printf("年龄:");scanf("%d", &st.Age);printf("学历:");scanf("%s", st.Education);printf("职务:");scanf("%s", st.Post);printf("工资:");scanf("%d", &st.Wage);printf("住址:");scanf("%s", st.Room);printf("电话:");scanf("%s", &st.Telephone);Add(&list, st);
}void Add(node* L, node e)
{// 头插法node* p = L;node* s = (node*)malloc(sizeof(node));*s = e;s->next = p->next;p->next = s;Save_FILE(L);
}// 删除职工信息
void Delete_Printf(node* L)
{system("cls");int id;node* p;printf("请输入要删除的职工的工号:");scanf("%d", &id);node* st = Search_id(id, L);p = st;if (st == NULL){printf("查无此人!\n");return;}st = st->next;printf("________________________________________________________________________________________________\n");printf("|学号\t|姓名\t|性别\t|年龄\t|学历\t|职位\t|工资\t|住址\t\t\t|电话\t\t|\n");printf("________________________________________________________________________________________________\n");printf("|%d\t|%s\t|%s\t|%d\t|%s\t|%s\t|%d\t|%s\t\t|%s\t|\n", st->ID, st->Name, st->Sex, st->Age, st->Education, st->Post, st->Wage, st->Room, st->Telephone);printf("________________________________________________________________________________________________\n");Delete(p);// 保存信息Save_FILE(L);
}void Delete(node* s)
{node* t = s->next;s->next = t->next;t->next = NULL;free(t);
}// 修改职工信息
void Fix(node* L)
{system("cls");int id;printf("请输入要修改的职工的工号:");scanf("%d", &id);node* st = Search_id(id, L);if (st == NULL){printf("查无此人!\n");return;}st = st->next;int choice = 0;while (1){system("cls");// 输出一次所要修改的职工信息printf("________________________________________________________________________________________________\n");printf("|学号\t|姓名\t|性别\t|年龄\t|学历\t|职位\t|工资\t|住址\t\t\t|电话\t\t|\n");printf("________________________________________________________________________________________________\n");printf("|%d\t|%s\t|%s\t|%d\t|%s\t|%s\t|%d\t|%s\t\t|%s\t|\n", st->ID, st->Name, st->Sex, st->Age, st->Education, st->Post, st->Wage, st->Room, st->Telephone);printf("________________________________________________________________________________________________\n");printf("修改姓名 ---- 1\n");printf("修改性别 ---- 2\n");printf("修改班级 ---- 3\n");printf("修改学历 ---- 4\n");printf("修改职位 ---- 5\n");printf("修改工资 ---- 6\n");printf("修改住址 ---- 7\n");printf("修改电话 ---- 8\n");printf("请输入要修改的信息:");scanf("%d", &choice);switch (choice){case 1:printf("请输入姓名:");scanf("%s", st->Name);break;case 2:printf("请输入性别:");scanf("%s", st->Sex);break;case 3:printf("请输入年龄:");scanf("%d", st->Age);break;case 4:printf("请输入学历:");scanf("%s", st->Education);break;case 5:printf("请输入职务:");scanf("%s", st->Post);break;case 6:printf("请输入工资:");scanf("%d", st->Wage);break;case 7:printf("请输入住址:");scanf("%s", st->Room);break;case 8:printf("请输入电话:");scanf("%s", st->Telephone);break;}printf("是否继续修改该学生信息?(Yes:1 / No:0):");scanf("%d", &choice);if (choice == 0){break;}}// 修改完成后该学生的信息printf("________________________________________________________________________________________________\n");printf("|学号\t|姓名\t|性别\t|年龄\t|学历\t|职位\t|工资\t|住址\t\t\t|电话\t\t|\n");printf("________________________________________________________________________________________________\n");printf("|%d\t|%s\t|%s\t|%d\t|%s\t|%s\t|%d\t|%s\t\t|%s\t|\n", st->ID, st->Name, st->Sex, st->Age, st->Education, st->Post, st->Wage, st->Room, st->Telephone);printf("________________________________________________________________________________________________\n");// 保存信息Save_FILE(L);
}// 查询职工信息
void Search_Printf(node* L)
{system("cls");int choice = 0;printf("按照工号查询 ---- 1\n");printf("按照姓名查询 ---- 2\n");printf("请输入查询方式:");scanf("%d", &choice);int id;char name[50];node* st;if (choice == 1){printf("请输入要查询的工号:");scanf("%d", &id);st = Search_id(id, L);if (st == NULL){printf("查无此人!\n");}else{st = st->next;printf("________________________________________________________________________________________________\n");printf("|学号\t|姓名\t|性别\t|年龄\t|学历\t|职位\t|工资\t|住址\t\t\t|电话\t\t|\n");printf("________________________________________________________________________________________________\n");printf("|%d\t|%s\t|%s\t|%d\t|%s\t|%s\t|%d\t|%s\t\t|%s\t|\n", st->ID, st->Name, st->Sex, st->Age, st->Education, st->Post, st->Wage, st->Room, st->Telephone);printf("________________________________________________________________________________________________\n");}}else if (choice == 2){printf("请输入要查询的姓名:");scanf("%s", name);st = Search_name(name, L);if (st == NULL){printf("查无此人!\n");}else{st = st->next;printf("________________________________________________________________________________________________\n");printf("|学号\t|姓名\t|性别\t|年龄\t|学历\t|职位\t|工资\t|住址\t\t\t|电话\t\t|\n");printf("________________________________________________________________________________________________\n");printf("|%d\t|%s\t|%s\t|%d\t|%s\t|%s\t|%d\t|%s\t\t|%s\t|\n", st->ID, st->Name, st->Sex, st->Age, st->Education, st->Post, st->Wage, st->Room, st->Telephone);printf("________________________________________________________________________________________________\n");}}
}// 按学号进行查找
node* Search_id(int id, node* L)
{node* p = L;while (p->next != NULL){if (p->next->ID == id){return p;}p = p->next;}return NULL;
}// 按姓名进行查找
node* Search_name(char name[], node* L)
{node* p = L;while (p->next != NULL){if (strcmp(name, p->next->Name) == 0){return p;}p = p->next;}return NULL;
}// 输出职工信息
void Print(node* L)
{system("cls");node* p = L->next;Print_Printf();if (p != NULL){while (p != NULL){printf("________________________________________________________________________________________________\n");printf("|%d\t|%s\t|%s\t|%d\t|%s\t|%s\t|%d\t|%s\t\t|%s\t|\n", p->ID, p->Name, p->Sex, p->Age, p->Education, p->Post, p->Wage, p->Room, p->Telephone);printf("________________________________________________________________________________________________\n");p = p->next;}}
}void Print_Printf()
{printf("________________________________________________________________________________________________\n");printf("|学号\t|姓名\t|性别\t|年龄\t|学历\t|职位\t|工资\t|住址\t\t\t|电话\t\t|\n");printf("________________________________________________________________________________________________\n");
}// 排序职工信息
void Sort(node* L)
{system("cls");int choice = 0;printf("按照工资从大到小排序 ---- 1\n");printf("按照工资从小到大排序 ---- 2\n");printf("请选择排序方式:");scanf("%d", &choice);int flag = 0;for (node* p = L->next; p != NULL; p = p->next){for (node* q = p; q != NULL; q = q->next){switch (choice){case 1:if (!cmp_big_Wage(*p, *q)){flag = 1;}break;case 2:if (!cmp_small_Wage(*p, *q)){flag = 1;}break;if (flag == 1){// 交换数据域node t = *p;*p = *q;*q = t;// 处理指针域t.next = p->next;p->next = q->next;q->next = t.next;flag = 0;}}}}
}// 工资从大到小
bool cmp_big_Wage(node e1, node e2)
{return e1.Wage > e2.Wage;
}
// 工资从小到大
bool cmp_small_Wage(node e1, node e2)
{return e1.Wage < e2.Wage;
}// 退出管理系统
void goodbye()
{system("cls");printf("欢迎下次使用职工信息管理系统!");exit(0);// 结束程序
}

C语言:程序设计综合训练相关推荐

  1. 江苏理工学院c语言实验报告,江苏理工学院 C语言程序设计综合训练.doc

    江苏理工学院 C语言程序设计综合训练.doc <C语言程序设计综合训练> 江苏理工学院 课 程 设 计 报 告 姓 名: 王 曼 同组人员: 班 级: 10电子2W 指导教师: 曹凤雪 成 ...

  2. c语言程序女设计教学效果分析,C语言程序设计的教学论文

    C语言程序设计的教学论文 1C语言程序设计教学方法研究 1.1理论教学 对于大多数课程而言,从宏观上将课程知识点及其关联讲授给学生非常必要,这便于学生更加系统深刻地理解所学内容.作为教材讲解C语言程序 ...

  3. 江苏大学c语言程序设计,江苏大学201级C语言课程设计要求及题目.doc

    江苏大学201级C语言课程设计要求及题目 C语言程序课程设计 C programming curriculum design 课程设计大纲 一.学时与学分 总学时:1.5周 总学分:2 二.课程设计的 ...

  4. c语言预上机报告,《C语言程序设计》上机报告.doc

    <C语言程序设计>上机报告 <程序设计语言基础(1)上机实践> 综合报告 专业班级 姓 名 学 号 <程序设计语言基础(1)上机实践>报告 ( 2008-2009 ...

  5. c语言程序设计实训太空战机,清华大学出版社-图书详情-《C程序设计实训教程(第2版)》...

    前 言 "C程序设计"是一门实践性很强的课程,学习本课程既要理解C语言的基本理论和基本知识,更要掌握应用理论知识编写程序的方法和技能.为此,编者基于长期从事"C程序设计& ...

  6. c语言程序设计实践课选题,学生程序设计论文,关于C语言程序设计课程实践相关参考文献资料-免费论文范文...

    导读:该文是关于学生程序设计论文范文,为你的论文写作提供相关论文资料参考. 摘 要:通过对C语言程序设计课程的创新与实践,研究和探索培养高职学生创新能力的课程设计和教育方法,探索课程与创新实践教育结合 ...

  7. C语言程序设计运动会管理系统(一)

    1.课程设计目的     C语言程序设计课程设计是计算机科学与技术专业重要的实践性教学环节之一,本次设计结合实际应用的要求,使课程设计既覆盖C语言的知识点,又接近工程实际需要.目的是通过课程设计的综合 ...

  8. c语言通讯录二分查找,C语言程序设计 通讯录程序.doc

    <C语言程序设计 通讯录程序.doc>由会员分享,可在线阅读,更多相关<C语言程序设计 通讯录程序.doc(28页珍藏版)>请在人人文库网上搜索. 1.目录:课 程 设 计 任 ...

  9. c语言程序设计创新,C语言程序设计课程创新与实践

    摘 要:通过对C语言程序设计课程的创新与实践,研究和探索培养高职学生创新能力的课程设计和教育方法,探索课程与创新实践教育结合的教育模式,从而实现具有高素质的职业技术人才培养的目标. 关键词:教学内容: ...

  10. c语言程序设教材计 乌云高娃,C语言程序设计教学课件作者第3版乌云高娃演示文稿C语言程序设计教学课件作者第3版乌云高娃演示文稿演示文稿第1章C语言程序设计基础课件.ppt...

    C语言程序设计教学课件作者第3版乌云高娃演示文稿C语言程序设计教学课件作者第3版乌云高娃演示文稿演示文稿第1章C语言程序设计基础课件.ppt 主要内容 课程概述 为什么选择C语言作为入门课程? C语言 ...

最新文章

  1. Memcache面试题
  2. iOS中容易混淆的知识点(持续更新中)
  3. 如何点击按钮弹出弹框显示几秒_产品反馈设计:如何与用户有效沟通?
  4. 万年历升级版 Calendar
  5. Cmd打开Java软件
  6. SVN服务器的本地搭建和使用
  7. using的一种用法
  8. ajax下拉搜索框,jQuery的带搜索过滤ajax加载下拉框插件
  9. c语言例题22:日期计算
  10. 华为RS1 企业的网络架构
  11. java压缩图片thumbnails_Java压缩图片、减小图片文件体积大小,Thumbnails使用教程...
  12. Tensorflow2 model.compile()理解
  13. sizeof 知多少
  14. MacBook Pro App Store无法下载和更新软件解决方案
  15. 360打开html乱码怎么办,360浏览器出现乱码怎么回事_360浏览器页面乱码如何解决-win7之家...
  16. 浙江从小学生就上计算机课,浙江省2012年1月自学考试小学数学教学研究试题
  17. Tarena 课程体系
  18. android手机电视互动,手机APP控制电视 长虹智能机多屏互动体验(组图)
  19. PyCharm安装教程和第三方库安装方法
  20. Linux Examination

热门文章

  1. Asible简介及部署
  2. The Shawshank Redemption-7
  3. 汉诺塔(河内塔)问题解析(函数递归经典问题)
  4. SpringCloud五大常用组件
  5. GD32 CAN波特率计算问题
  6. 太吾绘卷第一世攻略_太吾绘卷狮相门第一世打通7剑冢攻略
  7. XML入门教程(3)
  8. 战双帕弥什qq登录服务器未响应是什么意思,战双帕弥什渠道账号登录失败怎么办...
  9. 浅谈Wi-Fi渗透--原理篇
  10. Aggregation-Based Graph Convolutional Hashing forUnsupervised Cross-Modal Retrieval