目录
界面展示
康康代码
stdbill.c:
tool.c
stuact.c
student.c? (最核心的链表操作)
log.c
头文件
main.c
咱们书接上回,之前完成了学生系统的初版,但是奈何学校要答辩,身边的同学都在拼命的卷自己的系统,我自然是不能善罢甘休,
按照老师的要求,我将系统分为了ui层,逻辑业务层,功能实现层
然后又自己加了一点其他的功能,什么彩色显示啊,什么将数据存储在表格里啊,,,,
奈何最后提交的文档实在太拉跨,可以说是学的教训了
界面展示
话不多说,上图
?
?
?
?
查看分数统计
?
打印学生成绩单
?
康康代码
因为是多文件写成的代码,我会将代码与文件名一同注明
stdbill.c:
#define _CRT_SECURE_NO_WARNINGS 1//用来防止vs的莫名其妙的报错
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<windows.h>
#include"student.h"
#include"sys.h"
#include"log.h"
void sowhmess()//通用提示信息
{
printf("对不起,您的输入有误......\n");
printf("操作完毕,返回主菜单继续......\n");
}
//学生查看
void query(pstd heads)
{
system("cls");
printf("学生信息查看......\n");
check_mains();
int c = 0;
scanf("%d", &c);
switch (c)
{
case 1:system("cls"); sort_byname(heads); out(heads); break;//
case 2:system("cls"); sort_byid(heads); out(heads); break;//
case 3:system("cls"); showmajor(heads); break;//
case 4:system("cls"); sort_s1(heads); out(heads); break;//
case 5:system("cls"); sort_s2(heads); out(heads); break;//
case 0:system("cls"); printf("退出查看。\n"); break;//
default:system("cls"); printf("输入错误,退出当前界面。。。。\n");break;//
}
printf("操作完毕,返回主菜单继续......\n");
system("pause");
}
//删除
void deletestu(pstd heads)
{
system("cls");
printf("学生信息删除......\n");
fund_mains();
int c = 0;
scanf("%d", &c);
switch (c)
{
case 1:deletes(heads, fundname(heads)); break;
case 2:deletes(heads, fundid(heads)); break;
case 0:system("cls"); printf("退出。\n"); break;
default:printf("输入错误,退出当前界面。。。。\n"); break;
}
printf("操作完毕,返回主菜单继续......\n");
system("pause");
system("cls");
}
//分类查询
void querystu(pstd heads)
{
system("cls");
printf("学生分类查询......\n");
fund_mains();
int c = 0;
scanf("%d", &c);
switch (c)
{
case 1:system("cls"); outone(fundname(heads)); break;
case 2:system("cls"); outone(fundid(heads)); break;
case 0:system("cls"); printf("退出查询。\n"); break;
default:system("cls"); printf("输入错误,退出当前界面。。。。\n"); break;
}
printf("操作完毕,返回主菜单继续......\n");
system("pause");
system("cls");
}
//更新
void updute(pstd heads)
{
system("cls");
printf("学生信息修改......\n");
fund_mains();
int c = 0;
scanf("%d", &c);
switch (c)
{
case 1:change(fundname(heads)); break;
case 2:change(fundid(heads)); break;
case 0:system("cls"); printf("退出修改。\n"); break;
default:printf("输入错误,退出当前界面。。。。"); break;
}
printf("操作完毕,返回主菜单继续......\n");
system("pause");
system("cls");
}
//账号验证
int is_user(char* usera, char* userp)
{
if (ismgid(usera,userp)==1)
{
printf("\t\t欢迎进入管理员端系统,请稍等.........\n");
Sleep(1000);
return 1;
}
else if (isstuid(usera,userp)==1)
{
printf("\t\t欢迎进入学生端系统,请稍等.........\n");
Sleep(1000);
return 2;
}
return 0;
}
#define _CRT_SECURE_NO_WARNINGS 1
#include<windows.h>
//引用的是函数库定义好了的函数,这里进行了封装,如果有兴趣的话可以去查查windows.h的文档
void color(char x)
{
if (x >= 0 && x <= 15)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
}
stuact.c
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include"stdbill.h"
#include"student.h"
#include"log.h"
pstd main_mg(int x, pstd heads)
{
system("cls");
switch (x){
case 1:
system("cls"); heads = input(); system("cls"); break;
case 2:
system("cls"); adds(heads); system("pause"); system("cls");break;
case 3:
system("cls"); query(heads); system("cls"); break;
case 4:
system("cls"); updute(heads); system("cls"); break;
case 5:
system("cls"); precent(heads); outtotal(heads); system("pause"); system("cls"); break;
case 6:
system("cls"); querystu(heads); system("cls"); break;
case 7:
system("cls"); save(heads); system("pause"); system("cls"); break;
case 8:
system("cls"); heads = read(); out(heads); system("pause"); system("cls"); break;
case 9:
system("cls"); deletestu(heads); system("cls"); break;
case 10:
system("cls"); sort_s2(heads); getmark(heads); system("cls"); break;
case 0:
system("cls"); printf("感谢使用\n"); Sleep(1000); system("pause");exit(-1); break;
default:
system("cls"); printf("手抖了?\n再试试?\n\n\n"); break;
}
return heads;
}
pstd main_stu(int x, pstd heads)
{
system("cls");
switch (x){
case 1:
system("cls"); query(heads); system("pause"); break;
case 2:
system("cls"); querystu(heads); system("pause"); break;
case 3:
system("cls"); sort_s2(heads); getmark(heads); system("cls"); break;
case 0:
system("cls"); printf("感谢使用\n"); Sleep(1000); system("pause"); exit(-1); break;
default:
system("cls"); printf("手抖了?\n再试试?\n\n\n"); break;
}
return heads;
}
void addid()
{
addidhead();
int x;
printf("请输入你的选择!");
scanf("%d", &x);
if (x == 1){
addstuid();
}
else if (x == 2){
addmgid();
}
else {
printf("选择错误!");
return;
}
}
int logtime(int x)
{
switch (x){
case 1:return login();
case 2:system("cls"); addid(); system("cls"); break;
default:
break;
}
return -1;
}
int login()
{
char usera[20], userp[20];
int i;
system("cls");
head();
printf("\t\t账户:");
scanf("%s", usera);
printf("\t\t密码:");
for (i = 0; i < 20; i++){
userp[i] = getch();
if (userp[i] == '\r'){
break;
}
printf("*");
}
userp[i] = '\0';
return is_user(usera, userp);
}
student.c? (最核心的链表操作)
#define _CRT_SECURE_NO_WARNINGS 1
#include"student.h"
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#include<stdbool.h>
#include<windows.h>
#include"tool.h"
pstd input()//创建
{
int n;
int i;
float x;
char a[10];
char b[7];
char sb[7];
char m[20];
printf("请输入学生个数:\n");
scanf("%d", &n);
pstd ph = (pstd)malloc(sizeof(std));//头指针
pstd pt = ph;//尾指针
pt->pnext = NULL;//尾指针为空
for (i = 1; i <= n; i++)
{
//数据输入
printf("请输入第%d个学生的名字:\n", i);
scanf("%s", a);
printf("请输入第%d个学生的学号(6位):\n", i);
scanf("%s", b);
if (i > 1 && haveid(ph, b) == 0) {
printf("已存在该学生!\n");
return NULL;
}
pstd pn = (pstd)malloc(sizeof(std));//开辟空间
strcpy(pn->name, a);
strcpy(pn->id, b);
printf("请输入第%d个学生专业:\n", i);
scanf("%s", m); strcpy(pn->major, m);
printf("请输入第%d个学生的性别:\n", i);
scanf("%s", sb); strcpy(pn->sex, sb);
printf("请输入第%d个学生的语文成绩:\n", i);
scanf("%f", &x); pn->s[0] = x;
printf("请输入第%d个学生的数学成绩:\n", i);
scanf("%f", &x); pn->s[1] = x;
printf("请输入第%d个学生的英语成绩:\n", i);
scanf("%f", &x); pn->s[2] = x;
printf("请输入第%d个学生的物理成绩:\n", i);
scanf("%f", &x); pn->s[3] = x;
printf("请输入第%d个学生的化学成绩:\n", i);
scanf("%f", &x); pn->s[4] = x;
printf("请输入第%d个学生的生物成绩:\n", i);
scanf("%f", &x); pn->s[5] = x;
pn->t = pn->s[0] + pn->s[1] + pn->s[2] + pn->s[3] + pn->s[4] + pn->s[5];
pn->a = pn->t / 6.0;
pt->pnext = pn;//上次循环之前的尾指针指向新创建的节点
pn->pnext = NULL;//新节点的指针域为空
pt = pn;//新节点为尾节点
system("cls");
}
return ph;
}
void out(pstd p)//输出
{
if (p == NULL)
{
printf("无学生数据\n");
return;
}
int i = 1;
pstd pr = p->pnext;
while (pr)
{
color(2);
printf("序号:%d\n", i++);
color(3);
printf("姓名:%s ", pr->name);
printf("学号:%s ", pr->id);
printf("专业:%s ", pr->major);
printf("性别:%s ", pr->sex);
color(6);
printf("\n");
printf("语文:%5.2f ", pr->s[0]);
printf("数学:%5.2f ", pr->s[1]);
printf("英语:%5.2f ", pr->s[2]);
printf("物理:%5.2f ", pr->s[3]);
printf("化学:%5.2f ", pr->s[4]);
printf("生物:%5.2f ", pr->s[5]);
printf("\n");
color(5);
printf("总分:%5.2f", pr->t);
printf("平均:%5.2f", pr->a);
color(7);
printf("\n");
pr = pr->pnext;
}
}
void sort_s1(pstd p)//低到高
{
if (p == NULL)
{
printf("无学生数据\n");
return;
}
pstd pur, cur, next, end;
end = NULL;
while (p->pnext != end)
{
for (pur = p, cur = pur->pnext, next = cur->pnext; next != end; pur = pur->pnext, cur = cur->pnext, next = next->pnext)
{
if (cur->t > next->t)
{
pur->pnext = next;
cur->pnext = next->pnext;
next->pnext = cur;
pstd m = cur;
cur = next;
next = m;
}
}
end = cur;
}
}
void sort_s2(pstd p)//高到低
{
if (p == NULL)
{
printf("无学生数据\n");
return;
}
{
pstd pur, cur, next, end;
end = NULL;
while (p->pnext != end)
{
for (pur = p, cur = pur->pnext, next = cur->pnext; next != end; pur = pur->pnext, cur = cur->pnext, next = next->pnext)
{
if (cur->t < next->t)
{
pur->pnext = next;
cur->pnext = next->pnext;
next->pnext = cur;
pstd m = cur;
cur = next;
next = m;
}
}
end = cur;
}
}
}
void sort_byname(pstd p)//姓名排序
{
if (p == NULL)
{
printf("无学生数据\n");
return;
}
pstd pur, cur, next, end;
end = NULL;
while (p->pnext != end)
{
for (pur = p, cur = pur->pnext, next = cur->pnext; next != end; pur = pur->pnext, cur = cur->pnext, next = next->pnext)
{
if (strcmp(cur->name, next->name) > 0)
{
pur->pnext = next;
cur->pnext = next->pnext;
next->pnext = cur;
pstd m = cur;
cur = next;
next = m;
}
}
end = cur;
}
}
void sort_byid(pstd p)//学号排序
{
if (p == NULL)
{
printf("无学生数据\n");
return;
}
pstd pur, cur, next, end;
end = NULL;
while (p->pnext != end)
{
for (pur = p, cur = pur->pnext, next = cur->pnext; next != end; pur = pur->pnext, cur = cur->pnext, next = next->pnext)
{
if (strcmp(cur->id, next->id) > 0)
{
pur->pnext = next;
cur->pnext = next->pnext;
next->pnext = cur;
pstd m = cur;
cur = next;
next = m;
}
}
end = cur;
}
}
void outone(pstd p)
{
if (p == NULL)
{
printf("无学生数据\n");
}
else
{
pstd pr = p;
color(3);
printf("姓名:%s ", pr->name);
printf("学号:%s ", pr->id);
printf("专业:%s ", pr->major);
printf("性别:%s ", pr->sex);
color(6);
printf("\n");
printf("语文:%5.2f ", pr->s[0]);
printf("数学:%5.2f ", pr->s[1]);
printf("英语:%5.2f ", pr->s[2]);
printf("物理:%5.2f ", pr->s[3]);
printf("化学:%5.2f ", pr->s[4]);
printf("生物:%5.2f ", pr->s[5]);
printf("\n");
color(5);
printf("总分:%5.2f", pr->t);
printf("平均:%5.2f", pr->a);
color(7);
printf("\n");
}
}
pstd fundname(pstd p)
{
if (p == NULL)
{
printf("无学生数据\n");
return NULL;
}
int f = 0;
int l = 0;
char n[10];
printf("请输入您要查找的名字:\n");
scanf("%s", n);
pstd pr = p->pnext;
while (pr != NULL)
{
if (strcmp(pr->name, n) == 0)
{
f++;
return pr;
}
pr = pr->pnext;
}
if (f == 0)
printf("对不起查无此人\n");
return NULL;
}
pstd fundid(pstd p)
{
if (p == NULL)
{
printf("无学生数据\n");
return NULL;
}
int f = 0;
int l = 0;
char i[7];
printf("请输入您要查找的学号:\n");
scanf("%s", i);
pstd pr = p->pnext;
while (pr != NULL)
{
if (strcmp(pr->id, i) == 0)
{
f++;
return pr;
}
pr = pr->pnext;
}
if (f == 0)
printf("对不起,查无此人\n");
return NULL;
}
void showmajor(pstd p)
{
if (p == NULL)
{
printf("无学生数据\n");
return;
}
int f = 0;
int l = 0;
char m[20];
printf("请输入您要查找的专业:\n");
scanf("%s", m);
pstd pr = p->pnext;
while (pr != NULL)
{
if (strcmp(pr->major, m) == 0)
{
f++;
outone(pr);
}
pr = pr->pnext;
}
if (f == 0)
printf("对不起查无此人\n");
return;
}
void deletes(pstd p, pstd ps)
{
if (p == NULL)
{
printf("无学生数据\n");
return;
}
pstd pr = p;
while (pr->pnext != ps)
{
pr = pr->pnext;
}
pstd pt = pr->pnext;
pr->pnext = ps->pnext;
free(pt);
pt = NULL;
}
void adds(pstd p)
{
if (p == NULL)
{
printf("无学生数据\n");
return;
}
pstd ph = p->pnext;
while (ph->pnext != NULL)
{
ph = ph->pnext;
}
int n;
int i;
float x;
char a[10];
char b[7];
char m[20];
printf("请输入添加学生个数:\n");
scanf_s("%d", &n);
pstd pt = ph;//尾指针
pt->pnext = NULL;//尾指针为空
for (i = 1; i <= n; i++)
{
//数据输入
printf("请输入第%d个添加学生的名字:\n", i);
scanf("%s", a);
printf("请输入第%d个添加学生的学号(6位):\n", i);
scanf("%s", b);
if (haveid(p, b) == 0) {
printf("已存在该学生!\n");
system("pause");
return;
}
pstd pn = (pstd)malloc(sizeof(std));//开辟空间
strcpy(pn->id, b);
strcpy(pn->name, a);
printf("请输入第%d个学生专业:\n", i);
scanf("%s", m); strcpy(pn->major, m);
printf("请输入第%d个学生的性别:\n", i);
scanf("%s", b); strcpy(pn->sex, b);
printf("请输入第%d个添加学生的语文成绩:\n", i);
scanf("%f", &x); pn->s[0] = x;
printf("请输入第%d个添加学生的数学成绩:\n", i);
scanf("%f", &x); pn->s[1] = x;
printf("请输入第%d个添加学生的英语成绩:\n", i);
scanf("%f", &x); pn->s[2] = x;
printf("请输入第%d个添加学生的物理成绩:\n", i);
scanf("%f", &x); pn->s[3] = x;
printf("请输入第%d个添加学生的化学成绩:\n", i);
scanf("%f", &x); pn->s[4] = x;
printf("请输入第%d个添加学生的生物成绩:\n", i);
scanf("%f", &x); pn->s[5] = x;
pn->t = pn->s[0] + pn->s[1] + pn->s[2] + pn->s[3] + pn->s[4] + pn->s[5];
pn->a = pn->t / 6.0;
pt->pnext = pn;//上次循环之前的尾指针指向新创建的节点
pn->pnext = NULL;//新节点的指针域为空
pt = pn;//新节点为尾节点
system("cls");
}
}
void precent(pstd p)
{
if (p == NULL)
{
printf("无学生数据\n");
return;
}
pstd pr = p->pnext;
int a = 0, b = 0, c = 0, d = 0, e = 0;
float t;
while (pr)
{
if (pr->s[0] >= 90)
a++;
else if (pr->s[0] >= 80 && pr->s[0] < 90)
b++;
else if (pr->s[0] >= 70 && pr->s[0] < 80)
c++;
else if (pr->s[0] >= 60 && pr->s[0] < 70)
d++;
else
e++; pr = pr->pnext;
}
t = a + b + c + d + e;
printf("语文:\n优秀:%d人 %.2f%% 良好:%d人 %.2f%% 中等:%d人 %.2f%% 及格:%d人 %.2f%% 不及格:%d人 %.2f%% \n", a, a * 100.0 / t, b, b * 100.0 / t, c, c * 100.0 / t, d, d * 100.0 / t, e, e * 100.0 / t);
a = 0; b = 0; c = 0; d = 0; e = 0;
pr = p->pnext;
while (pr)
{
if (pr->s[1] >= 90)
a++;
else if (pr->s[1] >= 80 && pr->s[1] < 90)
b++;
else if (pr->s[1] >= 70 && pr->s[1] < 80)
c++;
else if (pr->s[1] >= 60 && pr->s[1] < 70)
d++;
else
e++; pr = pr->pnext;
}
t = a + b + c + d + e;
printf("数学:\n优秀:%d人 %.2f%% 良好:%d人 %.2f%% 中等:%d人 %.2f%% 及格:%d人 %.2f%% 不及格:%d人 %.2f%% \n", a, a * 100.0 / t, b, b * 100.0 / t, c, c * 100.0 / t, d, d * 100.0 / t, e, e * 100.0 / t);
a = 0; b = 0; c = 0; d = 0; e = 0;
pr = p->pnext;
while (pr)
{
if (pr->s[2] >= 90)
a++;
else if (pr->s[2] >= 80 && pr->s[2] < 90)
b++;
else if (pr->s[2] >= 70 && pr->s[2] < 80)
c++;
else if (pr->s[2] >= 60 && pr->s[2] < 70)
d++;
else
e++; pr = pr->pnext;
}
t = a + b + c + d + e;
printf("英语:\n优秀:%d人 %.2f%% 良好:%d人 %.2f%% 中等:%d人 %.2f%% 及格:%d人 %.2f%% 不及格:%d人 %.2f%% \n", a, a * 100.0 / t, b, b * 100.0 / t, c, c * 100.0 / t, d, d * 100.0 / t, e, e * 100.0 / t);
a = 0; b = 0; c = 0; d = 0; e = 0;
pr = p->pnext;
while (pr)
{
if (pr->s[3] >= 90)
a++;
else if (pr->s[3] >= 80 && pr->s[3] < 90)
b++;
else if (pr->s[3] >= 70 && pr->s[3] < 80)
c++;
else if (pr->s[3] >= 60 && pr->s[3] < 70)
d++;
else
e++; pr = pr->pnext;
}
t = a + b + c + d + e;
printf("物理:\n优秀:%d人 %.2f%% 良好:%d人 %.2f%% 中等:%d人 %.2f%% 及格:%d人 %.2f%% 不及格:%d人 %.2f%% \n", a, a * 100.0 / t, b, b * 100.0 / t, c, c * 100.0 / t, d, d * 100.0 / t, e, e * 100.0 / t);
a = 0; b = 0; c = 0; d = 0; e = 0;
pr = p->pnext;
while (pr)
{
if (pr->s[4] >= 90)
a++;
else if (pr->s[4] >= 80 && pr->s[4] < 90)
b++;
else if (pr->s[4] >= 70 && pr->s[4] < 80)
c++;
else if (pr->s[4] >= 60 && pr->s[4] < 70)
d++;
else
e++;
pr = pr->pnext;
}
t = a + b + c + d + e;
printf("化学:\n优秀:%d人 %.2f%% 良好:%d人 %.2f%% 中等:%d人 %.2f%% 及格:%d人 %.2f%% 不及格:%d人 %.2f%% \n", a, a * 100.0 / t, b, b * 100.0 / t, c, c * 100.0 / t, d, d * 100.0 / t, e, e * 100.0 / t);
a = 0; b = 0; c = 0; d = 0; e = 0;
pr = p->pnext;
while (pr)
{
if (pr->s[5] >= 90)
a++;
else if (pr->s[5] >= 80 && pr->s[5] < 90)
b++;
else if (pr->s[5] >= 70 && pr->s[5] < 80)
c++;
else if (pr->s[5] >= 60 && pr->s[5] < 70)
d++;
else
e++; pr = pr->pnext;
}
t = a + b + c + d + e;
printf("生物:\n优秀:%d人 %.2f%% 良好:%d人 %.2f%% 中等:%d人 %.2f%% 及格:%d人 %.2f%% 不及格:%d人 %.2f%% \n", a, a * 100.0 / t, b, b * 100.0 / t, c, c * 100.0 / t, d, d * 100.0 / t, e, e * 100.0 / t);
printf("\n\n\n");
}
void save(pstd p)
{
if (p == NULL)
{
printf("无学生数据\n");
return;
}
pstd pr = p->pnext;
if (pr == NULL)
return;
FILE* fp;
if ((fp = fopen("xdzn.xls", "wt")) == NULL)
{
printf("储存失败\n");
return;
}
while (pr)
{
fprintf(fp, "%s\t%s\t%s\t%s\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n",
pr->name, pr->id, pr->sex, pr->major, pr->s[0], pr->s[1], pr->s[2], pr->s[3], pr->s[4], pr->s[5], pr->t, pr->a);
pr = pr->pnext;
}
fclose(fp);
fp = NULL;
}
pstd read()
{
int end;
pstd ph = (pstd)malloc(sizeof(std));
pstd pt = ph;
pt->pnext = NULL;
FILE* fp;
if ((fp = fopen("xdzn.xls", "r+")) == NULL)
{
printf("读取失败\n");
return NULL;
}
while (1)
{
pstd pn = (pstd)malloc(sizeof(std));
end = fscanf(fp, "%s\t%s\t%s\t%s\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n", &pn->name, &pn->id, &pn->sex, &pn->major, &pn->s[0], &pn->s[1], &pn->s[2], &pn->s[3], &pn->s[4], &pn->s[5], &pn->t, &pn->a);
if (end == EOF)
{
free(pn);
pn = NULL;
return ph;
}
pt->pnext = pn;
pn->pnext = NULL;
pt = pn;
}
free(fp);
fp = NULL;
printf("读取成功\n");
return ph;
}
pstd change(pstd p)
{
if (p == NULL)
return p;
pstd pn = p;
float x;
char sb[6];
char m[20];
printf("请输入待修改学生专业:\n");
scanf("%s", m); strcpy(pn->major, m);
printf("请输入待修改学生的性别:\n");
scanf("%s", sb); strcpy(pn->sex, sb);
printf("请输入待修改学生的语文成绩:\n");
scanf("%f", &x); pn->s[0] = x;
printf("请输入待修改学生的数学成绩:\n");
scanf("%f", &x); pn->s[1] = x;
printf("请输入待修改学生的英语成绩:\n");
scanf("%f", &x); pn->s[2] = x;
printf("请输入待修改学生的物理成绩:\n");
scanf("%f", &x); pn->s[3] = x;
printf("请输入待修改学生的化学成绩:\n");
scanf("%f", &x); pn->s[4] = x;
printf("请输入待修改学生的生物成绩:\n");
scanf("%f", &x); pn->s[5] = x;
pn->t = pn->s[0] + pn->s[1] + pn->s[2] + pn->s[3] + pn->s[4] + pn->s[5];
pn->a = pn->t / 6.0;
return p;
}
void pai(pstd p, pstd pr)
{
if (p == NULL)
{
printf("无学生数据\n");
return;
}
if (pr == NULL)
{
return;
}
int c = 0;
sort_s2(p);
pstd pt = p;
while (pt != pr)
{
pt = pt->pnext;
c++;
}
if (pt->pnext != NULL) {
printf("排名:%d\n", c);
outone(pr);
return;
}
}
void outtotal(pstd p)
{
if (p == NULL)
{
printf("无学生数据\n");
return;
}
float n = 0;
float c = 0;
pstd pr = p->pnext;//
while (pr)
{
n += pr->s[0];
c++;
pr = pr->pnext;
}
printf("语文总分为%5.2f 平均分为%5.2f\n", n, n / c);
pr = p->pnext;
n = 0; c = 0;
while (pr)
{
n += pr->s[1];
c++;
pr = pr->pnext;
}
printf("数学总分为%5.2f 平均分为%5.2f\n", n, n / c);
pr = p->pnext;
n = 0; c = 0;
while (pr)
{
n += pr->s[2];
c++;
pr = pr->pnext;
}
printf("英语总分为%5.2f 平均分为%5.2f\n", n, n / c);
pr = p->pnext;
n = 0; c = 0;
while (pr)
{
n += pr->s[3];
c++;
pr = pr->pnext;
}
printf("物理总分为%5.2f 平均分为%5.2f\n", n, n / c);
pr = p->pnext;
n = 0; c = 0;
while (pr)
{
n += pr->s[4];
c++;
pr = pr->pnext;
}
printf("化学总分为%5.2f 平均分为%5.2f\n", n, n / c);
pr = p->pnext;
n = 0; c = 0;
while (pr)
{
n += pr->s[5];
c++;
pr = pr->pnext;
}
printf("生物总分为%5.2f 平均分为%5.2f\n", n, n / c);
}
int haveid(pstd p, char* id)
{
pstd pt = p;
while (pt->pnext != NULL)
{
if (strcmp(id, pt->id) == 0)
{
return 0;
}
pt = pt->pnext;
}
return 1;
}
void getmark(pstd p)
{
int i=1;
if (p == NULL)
{
printf("无学生数据\n");
return;
}
pstd pr = p->pnext;
if (pr == NULL)
return;
FILE* fp;
if ((fp = fopen("成绩单.xls", "wt")) == NULL)
{
printf("打印失败\n");
system("pause");
return;
}
fprintf(fp, "排名\t姓名\t学号\t性别\t专业\t语文\t数学\t英语\t物理\t化学\t生物\t总分\t平均分\n");
while (pr)
{
fprintf(fp, "第%d名\t%s\t%s\t%s\t%s\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n",i,pr->name, pr->id, pr->sex, pr->major, pr->s[0], pr->s[1], pr->s[2], pr->s[3], pr->s[4], pr->s[5], pr->t, pr->a);
pr = pr->pnext;
i++;
}
fclose(fp);
fp = NULL;
printf("打印成功!\n");
system("pause");
}
log.c
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include "log.h"
#include<stdlib.h>
//这里使用的是将密码存储在全局变量中,别问,问就是懒
idkey mg[100];//管理员密码
idkey ss[100];//学生密码
int markmg[100] = {0};
int marks[100] = {0};
void log()
{
head();
printf("\n\n\n");
printf("\t\t用户登录,请输入账号,密码,......\n");
}
//管理员密码操作
void addmgid()//注册
{
char id[20]; char key[20];
printf("请输入账号:\n");
scanf("%s",id);
printf("请输入密码:\n");
scanf("%s", key);
if (strlen(id) <= 1) {
printf("格式错误!\n");
system("pause");
return;
}
for (int i = 0; i < 100; i++){
if (strcmp(mg[i].id, id) == 0)
{
printf("此账号已被注册!\n");
system("pause");
return;
}
else if (markmg[i] == 0)
{
strcpy(mg[i].id, id);
strcpy(mg[i].key, key);
markmg[i] = 1;
FILE* fp;
if ((fp = fopen("mgid", "a")) == NULL)
{
return;
}
fprintf(fp, "%s %s\n", id, key);
printf("管理员注册成功\n");
system("pause");
fclose(fp);
return;
}
}
}
void readmgid()//读取
{
FILE* fp;
int x;
if ((fp = fopen("mgid", "r+")) == NULL)
return;
int end;
for (int i = 0; i < 100; i++){
if (markmg[i] != 1){
end = fscanf(fp, "%s %s\n", &mg[i].id, &mg[i].key);
markmg[i] = 1;
if (end == EOF)
{
fclose(fp);
return;
}
}
}
return;
}
int ismgid(char id[], char key[])//验证
{
if (strlen(id) <= 1){
printf("格式错误!\n");
return 0;
}
for (int i = 0; markmg[i] == 1; i++){
if (strcmp(id, mg[i].id) == 0 && strcmp(key, mg[i].key) == 0){
return 1;
}
}
return 0;
}
void addstuid()
{
char id[20]; char key[20];
printf("请输入账号:\n");
scanf("%s", id);
printf("请输入密码:\n");
scanf("%s", key);
if (strlen(id) <= 1) {
printf("格式错误!\n");
system("pause");
return;
}
for (int i = 0; i < 100; i++)
{
if (strcmp(ss[i].id, id) == 0)
{
printf("此账号已被注册!\n");
system("pause");
return;
}
else if (marks[i] == 0)
{
strcpy(ss[i].id, id);
strcpy(ss[i].key, key);
marks[i] = 1;
FILE* fp;
if ((fp = fopen("studentid", "a")) == NULL){
return;
}
fprintf(fp, "%s %s\n", id, key);
printf("学生账号注册成功\n");
system("pause");
fclose(fp);
return;
}
}
}
void readstuid()
{
FILE* fp;
int x;
if ((fp = fopen("studentid", "r+")) == NULL)
return;
int end;
for (int i = 0; i < 100; i++)
{
if (marks[i] != 1)
{
end = fscanf(fp, "%s %s\n", &ss[i].id, &ss[i].key);
marks[i] = 1;
if (end == EOF){
fclose(fp);
return;
}
}
}
return;
}
int isstuid(char id[], char key[])
{
if (strlen(id) <= 1)
{
printf("格式错误!\n");
return 0;
}
for (int i = 0; marks[i] == 1; i++)
{
if (strcmp(id, ss[i].id) == 0 && strcmp(key, ss[i].key) == 0)
{
return 1;
}
}
return 0;
}
sys.c
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include "tool.h"
#define HEAD_ONE 30
#define HEAD_TWO 28
#define HEAD_THREE 30
#define HEAD_FOUR 30
void welcome()
{
printf("\n\n\n");
color(1);
printf("\t***************************************************************\n\n");
color(2);
printf("\t * 帅哥美女们,欢迎使用信息管理系统 *\n\n");
color(3);
printf("\t *<<<< <swpu程序设计课程组光宗耀组为您服务> >>>>*\n\n");
color(4);
printf("\t * * * *\n");
color(5);
printf("\t * * * * * * * * \n");
color(6);
printf("\t * * ^ * ^ * * ^ * ^ * *\n ");
color(7);
printf("\t ** * * * * **\n");
color(8);
printf("\t**************************************************************\n");
color(9);
printf("\t ** * * * * **\n");
color(2);
printf("\t * * ^ * * ^ * *\n");
color(3);
printf("\t * * * * \n");
color(4);
printf("\t * * * * ");
color(5);
printf("\t \n");
color(6);
printf("\t ——————光宗耀组!!!");
color(7);
printf("\n\n\n\t");
}
void mains_mg()
{
color(1);
printf("____________________________________________________________\n"); color(2);
printf("|1.录入学生信息 |\n"); color(3);
printf("|2.添加学生信息 |\n"); color(4);
printf("|3.查看学生信息 |\n"); color(5);
printf("|4.修改学生信息 |\n"); color(6);
printf("|5.查看分数统计 |\n"); color(7);
printf("|6.查找学生信息 |\n"); color(8);
printf("|7.存储学生信息 |\n"); color(9);
printf("|8.读取学生信息 |\n"); color(8);
printf("|9.删除学生信息 |\n"); color(6);
printf("|10.打印学生成绩 |\n"); color(5);
printf("|0.退出学生系统 |\n"); color(4);
printf("|___________________________________________________________|\n");
color(4);
printf("请输入您的选择:\n");
color(7);
}
void head()
{
color(8);
printf(" _____ \n");
printf(" \\\\/,---< 欢迎使用!!!!! \n");
printf(" ( )@ @( _ \n");
printf(" C __>/ |/ ) \n");
printf(" \\\\// |_/ \n");
color(5);
printf(" ,- >o<-.__/ / \n");
printf(" / \\/ ____/ \n");
printf(" / /| | | \n");
printf(" / \'--/_| | \n");
printf(" `----\\_) | \n");
printf(" |____| \n");
color(1);
printf(" | | | \n");
printf(" | | | \n");
printf(" | | | \n");
printf(" |__|_| \n");
printf(" (____)_) \n");
printf("\n\n\n\n\n\n\n");
color(4);
printf(" <<--__请登录__-->>\n");
color(7);
}
void check_mains()
{
color(1);
printf(" |____________________________________ \n");
color(2);
printf(" |1.按照姓名查看 |\n");
color(3);
printf(" |2.按照学号查看 |\n");
color(4);
printf(" |3.按照专业查看 |\n");
color(5);
printf(" |4.按照成绩顺序查看 |\n");
color(6);
printf(" |5.按照成绩逆序查看 |\n");
printf(" |0.退出查看 |\n");
color(7);
printf(" |____________________________________|\n");
color(8);
printf("请输入您的选择:\n");
color(7);
}
void fund_mains()
{
color(1);
printf("|_______________________ \n");
color(2);
printf("|1.通过姓名查找 |\n");
color(3);
printf("|2.通过学号查找 |\n");
color(4);
printf("|_______________________|\n");
color(7);
printf("请输入您的查找方式:\n");
}
void mains_stu()
{
color(1);
printf("____________________________________________________________\n");
color(2);
printf("|1.查看学生信息 |\n");
color(3);
printf("|2.查找学生信息 |\n");
color(4);
printf("|3.打印学生成绩 |\n");
color(5);
printf("|0.退出学生系统 |\n");
color(6);
printf("|___________________________________________________________|\n");
color(7);
printf("请输入您的选择:\n");
}
void addidhead()
{
color(1);
printf("|_______________________ \n");
color(2);
printf("|1.注册学生账号 |\n");
color(3);
printf("|2.注册教师账号 |\n");
color(4);
printf("|_______________________|\n");
color(7);
}
void logtimehead()
{
color(1);
printf("|_______________________ \n");
color(2);
printf("|1.登录用户账号 |\n");
color(3);
printf("|2.注册用户账号 |\n");
color(4);
printf("|_______________________|\n");
color(7);
}
头文件
stdbill.h
#pragma once
//通用提示信息
void sowhmess();
//排序
void sort();
//查看
void query();
//删除
void deletestu();
//分类查询
void querystu();
//更新
void updute();
//登录验证
int is_user(char* usera, char* userp);
void querystd();
tool.h
#pragma once
void gotoxy(int x, int y);//光标定位
//颜色
void color(char x);
stuact.h
#pragma once
#include"student.h"
//管理员功能
pstd main_mg(int x, pstd heads);
//学生权限
pstd main_stu(int x, pstd heads);
//密码验证
int login();
//登录/注册实现
int logtime(int x);
//注册实现
void addid();
student.h
#pragma once
typedef struct std
{
char name[10];//姓名
char id[7];//学号
char sex[6];//性别
char major[20];//专业
float s[6];//各科分数
float t;//总分
float a;//平均
struct std* pnext;
}std, * pstd;
//创建
pstd input();
//输出所有学生信息
void out(pstd p);
//总分低到高排序
void sort_s1(pstd p);
//总分高到低排序
void sort_s2(pstd p);
//姓名排序
void sort_byname(pstd p);
//学号排序
void sort_byid(pstd p);
//输出单个学生信息
void outone(pstd p);
//姓名查找
pstd fundname(pstd p);
//学号查找
pstd fundid(pstd p);
//专业查找
void showmajor(pstd p);
//删除学生
void deletes(pstd p, pstd ps);
//成绩分析
void precent(pstd p);
//文件储存
void save(pstd p);
//文件读取
pstd read();
//学生添加
void adds(pstd p);
//排名
void pai(pstd p, pstd pr);
//计算总分与平均分
void outtotal(pstd p);
//修改学生信息
void change(pstd p);
//学生学号验证
int haveid(pstd p,char* id);
//打印成绩单
void getmark(pstd p);
log.h
#pragma once
typedef struct idkey
{
char id[20];
char key[20];
}idkey;
//因为是多文件所以说要对全局变量使用extern修饰
extern idkey mg[100];//管理员密码
extern idkey ss[100];//学生密码
extern int markmg[100];
extern int marks[100];
void log();
//注册管理员账号
void addmgid();
//读取管理员账号
void readmgid();
//验证管理员账号
int ismgid(char id[], char key[]);
//注册学生账号
void addstuid();
//读取学生账号
void readstuid();
//验证学生账号
int isstuid(char id[], char key[]);
sys.h
#pragma once
//欢迎界面
void welcome();
//管理员界面
void mains_mg();
//登录界面
void head();
//学生界面
void mains_stu();
//查看选项
void check_mains();
//查找选项
void fund_mains();
//注册界面
void addidhead();
//登录/注册界面
void logtimehead();
main.c
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include"sys.h"
#include"stuact.h"
#include"stdbill.h"
#include"log.h"
#include"tool.h"
#include"student.h"
int main() {
readstuid();
readmgid();
int lc = 0;
pstd heads = NULL;
welcome();
system("pause");
while (lc < 3){
system("cls");
int logs;
logtimehead();
scanf("%d", &logs);
int l = logtime(logs);
if (l == 1){
int num;
system("cls");
printf("\t\t欢迎进入系统,请稍等......\n");
Sleep(1000);
do{
mains_mg();
scanf("%d", &num);
heads=main_mg(num, heads);
} while (1);
}else if (l == 2){
heads = read();
int num;
system("cls");
printf("\t\t欢迎进入系统,请稍等......\n");
Sleep(1000);
do {
mains_stu();
scanf("%d", &num);
main_stu(num, heads);
} while (1);
}else if (l == -1){
printf(".....\n");
}else {
fflush(stdin);
printf("\n\t\t用户和密码输入错误,按任意键重新输入\n");
Sleep(100);
system("pause");
lc++;
}
}
if (lc == 3){
printf("\n\t\t连续错误三次,程序即将退出。。。。");
Sleep(2000);
exit(-1);
}
return 0;
}
最后 最后
一定要写好文档!!!!!!!!!!!!!!!!!!!!!!!!!!!
|