学生成绩管理系统2019年1月4日
以下内容仅供娱乐,欢迎随时探讨,请多指教!
用链式存储结构(单链表)和文件来存储学生的基本信息以及各门功课的考试成绩,实现对学生信息及成绩进行录入、查询、添加、删除、修改、保存和读取等操作。具体要求如下:
(1)功能要求
①能通过登录进入系统;
②能进行个性化修饰,修改系统背景颜色;
③能对学生姓名、性别、民族、年龄、地址等信息以及线性代数、英语、高等数学、C语言等功课成绩通过窗口进行录入,也能够从文件导入这些信息;
④能对学生的成绩进行修改;
⑤能对学生的成绩进行删除;
⑥能对学生的成绩进行查询;
⑦能添加学生的成绩;
⑧能对学生的所有数据进行保存;
⑨能进行按总分高低排序并显示学生信息;
⑩能对系统密码进行修改。
(2)性能需求:
①系统安全、可靠;
②功能齐全;
③操作方便、界面友好。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include<windows.h>
#include<conio.h>
#define LENGTH sizeof(struct Student)
#define M 21 //设置密码位数为20
char password[M]; //设置初始密码
struct Student { //定义学生信息结构体
long int snu;//学号
char name[20];//姓名
char sex[10];//性别
char nationality[20];//民族
int sage;//年龄
char saddress[20];//地址
float fLine;//线代成绩
float English;//英语成绩
float maths;//高数成绩
float c_language;//c语言成绩
float sumscore;//总成绩
struct Student *next;
};
/*函数定义*/
void NewPause();//清空输入流并无回显暂停等待回车
void Outbiaozhi();//此函数用于制作表头
void OutTableHead();//该函数用于输出格式头
void outputlink(struct Student *temp);//输出显示链表
void changestu(struct Student *head);//修改学生信息的功能函数
void Search(struct Student *temp);//此函数用于查询函数
void Search_by_num(struct Student *temp);//按学号查询函数
void Search_by_name(struct Student *temp);//按姓名查询函数
void Search_by_mohu(struct Student *temp);//按模糊查询函数
void Search_by_nationality(struct Student *temp);//按民族查询函数
int passyanz();//此函数用于验证密码,密码支持20位的字符
int outmainmenu();//该函数用于输出主界面
int savefilelink(struct Student *temp);//该函数用于存储学生成绩到文件
struct Student *DeleteLink(struct Student *temp);//该函数用于删除学生成绩
struct Student *createlink_list();//该函数用于建立单向链表
struct Student *IndexLink(struct Student *h,int Judge);//该函数用于统计学生成绩并显示之
struct Student *LoadLink();//该函数用于从文件读取学生成绩
struct Student *SortLink(struct Student *h);//该函数用于排序学生成绩,采用冒泡法
struct Student *Insertlink(struct Student *temp,struct Student *stu);//插入学生信息功能函数定义,多函数调用
void changepassword(); //该函数用于修改系统密码
struct Student *sort(struct Student *temp);//用于排序链表
struct Student *SortLink_c_language(struct Student *h);//该函数用于排序学生成绩(按总成绩),采用冒泡法
struct Student *SortLink_maths(struct Student *h);//该函数用于排序学生成绩(按总成绩),采用冒泡法
/*函数定义*/
int main()//程序总入口点,主函数
{
system("color f9");
int m;
struct Student *temp;
temp=NULL;
if(passyanz()==1) { //密码验证功能
system("pause");
} else exit(0);
//要求用户选择载入学生信息的方式
printf("请选择载入学生信息的方式:\n");
printf("1.从当前窗口录入\n");
printf("2.从已有的文件(txt文件)录入\n");
printf("请选择: ");
while(!scanf("%d",&m)) { //排除输入错误的情况
printf("输入序号有误,请重新输入: ");
fflush(stdin);
}
while(m < 1 || m > 2) { //排除输入错误的情况
printf("请重新选择选择录入方式:\n");
printf("1.从当前界面录入\n");
printf("2.从已有文件(txt文件)录入\n");
printf("请选择:");
fflush(stdin);//清空输入缓冲区
/*
fflush(stdin) 会清空输入缓冲区中的内容,读取时输入缓冲区中的内容会被scanf函数逐个取走,
正常case下scanf()函数可以根据返回值判断成功取走的数目;当发生异常读取的时候,如应该读取一个整形,
结果输入缓冲区内当前的内容是个字符串,发生读取异常。发生读取异常之后,输入缓冲区中的内容并未被取走,
那么下次循环之时,scanf()函数发现输入缓冲区中有内容(显然编译器不会关心这个内容是不是合法),
于是不再等待user输入,直接尝试读取输入缓冲区中的内容,显而易见的又是一次读取异常,如此反复。
*/
while(!scanf("%d",&m)) {
printf("输入序号有误,请重新输入:");
fflush(stdin);
}
printf("\n");
}
if (m == 1) { //当前窗口录入
temp=createlink_list();
} else { //对文件录入的处理
temp=LoadLink();
}
while(1) {
switch(outmainmenu()) {
case 1:
changestu(temp);
break; //修改学生数据
case 2:
temp=DeleteLink(temp);
break; //删除学生数据
case 3:
Search(temp);
break; //查询学生数据
case 4:
temp=Insertlink(temp,NULL);
break; //插入学生数据
case 5:
savefilelink(temp);
break; //储存学生数据
case 6:
temp=sort(temp);
break; //冒泡法排序学生成绩
case 7:
if(passyanz() == 1)
changepassword();
break; //修改系统密码
case 0:
exit(0); //退出
default:
printf("非法输入!!!\n");
break;
}
}
system("pause");
return 0;
}
int passyanz() //此函数用于验证密码
{
FILE *fp;
fp=fopen("c:\\aaAA\\user.txt","r");
if(fp == NULL) {
printf("打开失败!\n");
getch();
} else {
fscanf(fp,"%s",password);
printf("打开成功,读写成功!1\n");
fclose(fp);
}
int x,n=1;
system("cls");
Outbiaozhi();
printf("\n\n");
printf("输入用户名:\n");
char name[20];
scanf("%s",name);
printf("tips:初始密码为123\n");
for(;; n++) {
if(n<=3) {
char ch,inpassword[M];
int i=0;
printf("请输入密码:");
while((ch=getch())!='\r' && i<=M) {
if(ch=='\b') {
if(i>0) {
i--;
printf("\b \b");// 密码支持退格的实现
} else
putchar(7);
} else {
inpassword[i++]=ch;
printf("*");
}
}
inpassword[i]='\0';
if(strcmp(inpassword,password) == 0) {
printf("\n密码正确\t请继续操作\n");
x=1;
return x;
} else {
printf("\n密码错误\t您还有%d次机会\n",3-n);
}
} else {
printf("\n密码均错误\t无法继续操作!\n");
x=0;
return x;
}
}
system("pause");
}
void NewPause() //清空输入流并无回显暂停等待回车
{
int c;
while ( (c = getchar()) != '\n' && c != EOF )
clearerr(stdin);
getchar();
}
int outmainmenu() //该函数用于输出主界面
{
system("cls");//实现清屏
Outbiaozhi();
printf("\n\n");
printf("1.修改学生数据\n");
printf("2.删除学生数据\n");
printf("3.查询学生数据\n");
printf("4.插入学生数据\n");
printf("5.储存学生数据\n");
printf("6.排序学生数据\n");
printf("7.修改系统密码\n");
printf("0.退出管理系统\n");
printf("\n\n\n");
printf("请输入您的选项:");
int temp;
fflush(stdin); //用来清空输入缓存
scanf("%d",&temp);
return (temp);
}
void Outbiaozhi() //此函数用于制作表头
{
int i;
HANDLE hOut;
// 获取输出流的句柄
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hOut,
FOREGROUND_GREEN | // 前景色_绿色
FOREGROUND_INTENSITY | // 前景色_加强
COMMON_LVB_UNDERSCORE); // 添加下划线
//以下用制表符制表
printf(" ┏");
for(i=1; i<=42; i++)printf("-");
printf("┓\n ");
printf("\t\t");
printf("学生成绩管理系统");
printf("\n ┗");
for(i=1; i<=42; i++)printf("-");
printf("┛");
}
void OutTableHead() //该函数用于输出格式头
{
printf("\n学号\t\t姓名\t性别\t民族\t年龄\t地址\t 线代\t英语\t高数\tc语言\t总分\n");
}
void outputlink(struct Student *temp) //输出显示链表
{
system("cls");
Outbiaozhi();
printf("\n\n");
OutTableHead();
while(temp!=NULL) {
printf("%ld\t",temp->snu);
printf("%s\t",temp->name);
printf("%s\t",temp->sex);
printf("%s\t",temp->nationality);
printf("%d\t",temp->sage);
printf("%s\t",temp->saddress);
printf("%.1f\t",temp->fLine);
printf("%.1f\t",temp->English);
printf("%.1f\t",temp->maths);
printf("%.1f\t",temp->c_language);
printf("%.1f\t",temp->sumscore);
printf("\n");
temp=temp->next;
}
printf("\n\n\n");
printf("按回车键返回");
NewPause();
}
struct Student *createlink_list() //该函数用于建立单向链表
{
system("cls");
Outbiaozhi();
printf("\n\n");
printf("请输入学生成绩,以输入学号0结束\n\n\n");
struct Student *head,*temp1,*temp2,*temp3;
head=NULL;
temp1=(struct Student *)malloc(sizeof(struct Student));
printf("请输入学生学号:");
fflush(stdin);//清空缓冲区,为了确保不影响后面的数据读取
scanf("%ld",&temp1->snu);
if(temp1->snu!=0) {
printf("请输入学生姓名:");
scanf("%s",temp1->name);
printf("请输入学生性别:");
scanf("%s",temp1->sex);
printf("请输入学生民族:");
scanf("%s",temp1->nationality);
do {
printf("请输入学生年龄:");
scanf("%d",&temp1->sage);
} while(temp1->sage < 0||temp1->sage > 100);
printf("请输入学生地址:");
scanf("%s",temp1->saddress);
do {
printf("请输入线代成绩:");
scanf("%f",&temp1->fLine);
} while(temp1->fLine < 0||temp1->fLine > 100);
do {
printf("请输入英语成绩:");
scanf("%f",&temp1->English);
} while(temp1->English < 0||temp1->English > 100);
do {
printf("请输入高数成绩:");
scanf("%f",&temp1->maths);
} while(temp1->maths < 0||temp1->maths > 100);
do {
printf("请输入c语言成绩:");
scanf("%f",&temp1->c_language);
} while(temp1->c_language < 0||temp1->c_language > 100);
temp1->sumscore=temp1->fLine+temp1->English+temp1->maths+temp1->c_language;
while(temp1->snu!=0) {
if(head==NULL)head=temp1;
temp2=(struct Student *)malloc(sizeof(struct Student));
temp1->next=temp2;//前一节点的后继指针指向新开辟的节点
temp3=temp1;//保留住前一节点的指针
temp1=temp2;//方便后面的循环
system("cls");
Outbiaozhi();
printf("\n\n");
printf("请输入学生成绩,以学号0结束\n\n\n");
printf("请输入学生学号:");
scanf("%ld",&temp1->snu);
if(temp1->snu!=0) {
printf("请输入学生姓名:");
scanf("%s",temp1->name);
printf("请输入学生性别:");
scanf("%s",temp1->sex);
printf("请输入学生民族:");
scanf("%s",temp1->nationality);
do {
printf("请输入学生年龄:");
scanf("%d",&temp1->sage);
} while(temp1->sage < 0||temp1->sage > 100);
printf("请输入学生地址:");
scanf("%s",temp1->saddress);
do {
printf("请输入线代成绩:");
scanf("%f",&temp1->fLine);
} while(temp1->fLine < 0||temp1->fLine > 100);
do {
printf("请输入英语成绩:");
scanf("%f",&temp1->English);
} while(temp1->English < 0||temp1->English > 100);
do {
printf("请输入高数成绩:");
scanf("%f",&temp1->maths);
} while(temp1->maths < 0||temp1->maths > 100);
do {
printf("请输入c语言成绩:");
scanf("%f",&temp1->c_language);
} while(temp1->c_language < 0||temp1->c_language > 100);
temp1->sumscore=temp1->fLine+temp1->English+temp1->maths+temp1->c_language;
} else {
temp3->next=NULL;//前节点的后继指针为空 ,链表结束于前节点
}
}
head=IndexLink(head,0);//直接对输入链表进行排序
}
free(temp1);//释放新开辟的未用节点,节省内存
return head;
}
void changestu(struct Student *head) //修改学生信息的功能函数
{
struct Student *p1,*p2;
int cho,k,n=0;
long int snu;
system("cls");
Outbiaozhi();
printf("\n\n");
if (head == NULL) { //对空链表的处理
printf("没有学生信息,结束修改\n ");
printf("按回车键返回");
NewPause();
return;
}
printf("请输入需要修改的学生学号: ");
while(!scanf("%ld",&snu)) { //接受用户输入的学号并且进行查错
printf("输入学号有误,请重新输入: ");
fflush(stdin);
}
do {
p2 = p1 = head;
while(p1->snu != snu) { //查找学生学号
if (p1->next == NULL)
break;
p2 = p1;
p1 = p1->next;
}
if (p1->snu == snu) { //查找成功
printf("已找到该学生,该学生的信息为: \n");
system("cls");
Outbiaozhi();
printf("\n\n");
OutTableHead();
printf("%ld\t",p1->snu);
printf("%s\t",p1->name);
printf("%s\t",p1->sex);
printf("%s\t",p1->nationality);
printf("%d\t",p1->sage);
printf("%s\t",p1->saddress);
printf("%.1f\t",p1->fLine);
printf("%.1f\t",p1->English);
printf("%.1f\t",p1->maths);
printf("%.1f\t",p1->c_language);
printf("%.1f\t",p1->sumscore);
printf("\n\n\n");
n= 0;
do {
if (n== 0) //开关,当第一次循环时 n=0 执行 IF 语句
printf("选择修改的内容\n");
else
printf("序号输入错误,请重新选择\n");
n= 1; //打开开关,以在以下操作用户输入序号超出范围时控制上面的分支语句,进而可以更好地向用户提示信息
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("9.高数成绩\n");
printf("10.c语言成绩\n");
printf("11.总成绩\n");
printf("12.全部\n");
printf("请选择序号: ");
fflush(stdin);
while(!scanf("%d",&cho)) { //接受序号并查错
printf("输入序号有误,请重新输入: ");
fflush(stdin);
}
} while(cho > 12|| cho < 1);
switch(cho) { //对序号进行多分支处理
case 1: {
printf("请输入该学生改正的学号信息: ");
while(!scanf("%ld",&p1->snu)) {
printf("输入改正信息有误,请重新输入: ");
fflush(stdin);
}
break;
}
case 2: {
printf("请输入该学生改正的姓名信息: ");
while(!scanf("%s",p1->name)) {
printf("输入改正信息有误,请重新输入: ");
fflush(stdin);
}
break;
}
case 3: {
printf("请输入该学生改正的性别信息: ");
while(!scanf("%s",p1->sex)) {
printf("输入改正信息有误,请重新输入: ");
fflush(stdin);
}
break;
}
case 4: {
printf("请输入该学生改正的民族信息: ");
while(!scanf("%s",p1->nationality)) {
printf("输入改正信息有误,请重新输入: ");
fflush(stdin);
}
break;
}
case 5: {
printf("请输入该学生改正的年龄信息: ");
while(!scanf("%d",&p1->sage)) {
printf("输入改正信息有误,请重新输入: ");
fflush(stdin);
}
break;
}
case 6: {
printf("请输入该学生改正的地址信息: ");
while(!scanf("%s",p1->saddress)) {
printf("输入改正信息有误,请重新输入: ");
fflush(stdin);
}
break;
}
case 7: {
printf("请输入该学生改正的线代成绩信息: ");
while(!scanf("%f",&p1->fLine)) {
printf("输入改正信息有误,请重新输入: ");
fflush(stdin);
}
break;
}
case 8: {
printf("请输入该学生改正的英语成绩信息: ");
while(!scanf("%f",&p1->English)) {
printf("输入改正信息有误,请重新输入: ");
fflush(stdin);
}
break;
}
case 9: {
printf("请输入该学生改正的高数成绩信息: ");
while(!scanf("%f",&p1->maths)) {
printf("输入改正信息有误,请重新输入: ");
fflush(stdin);
}
break;
}
case 10: {
printf("请输入该学生改正的c语言成绩信息:");
while(!scanf("%f",&p1->c_language)) {
printf("输入改正信息有误,请重新输入:");
fflush(stdin);
}
break;
}
case 11: {
printf("请输入该学生改正的总成绩信息:");
while(!scanf("%f",&p1->sumscore)) {
printf("输入改正信息有误,请重新输入:");
fflush(stdin);
}
break;
}
case 12: {
printf("请输入该学生全部要改正的信息:");
while(!scanf("%ld %s %s %s %d %s %f %f %f %f %f",&p1->snu
,p1->name,p1->sex,p1->nationality
,&p1->sage,p1->saddress,&p1->fLine,&p1->English
,&p1->maths,&p1->c_language,&p1->sumscore)) {
printf("输入改正信息有误,请重新输入:");
fflush(stdin);
}
break;
}
}
if (cho == 1 || cho == 12) { //对修改过学号的学生进行重新排序
if (p1 == head) { //当该学生在链表头时,删除链表头节点
head = head->next;
} else if (p1->next == NULL) { //当该学生在链表尾时,删除链表尾节点
p2->next = NULL;
} else { //当该学生在链表中时,删除该学生对应的节点
p2->next = p1->next;
}
head = Insertlink(head,p1); //利用插入学生信息功能函数,进行该学生的重新排序
}
printf("修改成功!\n");
//询问用户是否继续
printf("1.继续修改其他学生信息\n");
printf("2.退出修改\n");
printf("请选择: ");
while(!scanf("%d",&k)) { //接受用户输入的序号,并进行排错
printf("输入序号有误,请重新输入: ");
fflush(stdin);
}
if (k == 1) { //接受下一次修改的学生学号
printf("请输入需要修改的学生学号: ");
while(!scanf("%ld",&snu)) {
printf("输入修改信息有误,请重新输入: ");
fflush(stdin);
}
} else if (k != 2) { //排错
printf("输入有误,请重新输入\n");
}
} else { //查找不到学生时要求用户进行重新输入学生序号
k = 1;
printf("找不到该学生信息,请重新输入需要修改的学生学号: ");
fflush(stdin);
while(!scanf("%ld",&snu)); //接受用户重新输入的学号并进行排错
{
printf("输入修改信息有误,请重新输入: ");
fflush(stdin);
}
}
} while(k == 1);
printf("\n");
system("pause");
}
struct Student *Insertlink(struct Student *temp,struct Student *stu)//插入学生信息功能函数定义,多函数调用
{
struct Student *p1,*p2;
system("cls");
Outbiaozhi();
printf("\n\n");
if (stu == NULL) { //对于传入插入学生信息为空时要求用户输入插入的学生信息
stu=(struct Student*)malloc(LENGTH);
printf("请输入学生姓名:");
scanf("%s",stu->name);
printf("请输入学生性别:");
scanf("%s",stu->sex);
printf("请输入学生民族:");
scanf("%s",stu->nationality);
do {
printf("请输入学生年龄:");
scanf("%d",&stu->sage);
} while(stu->sage < 0||stu->sage > 100);
printf("请输入学生地址:");
scanf("%s",stu->saddress);
do {
printf("请输入线代成绩:");
scanf("%f",&stu->fLine);
} while(stu->fLine < 0||stu->fLine > 100);
do {
printf("请输入英语成绩:");
scanf("%f",&stu->English);
} while(stu->English < 0||stu->English > 100);
do {
printf("请输入高数成绩:");
scanf("%f",&stu->maths);
} while(stu->maths < 0||stu->maths > 100);
do {
printf("请输入c语言成绩:");
scanf("%f",&stu->c_language);
} while(stu->c_language < 0||stu->c_language > 100);
stu->sumscore=stu->fLine+stu->English+stu->maths+stu->c_language;
}
if (temp == NULL) { //对于链表为空的情况的处理
temp = stu;
temp->next = NULL;
} else { //在链表中插入学生信息
p1 = p2 = temp;
while(stu->snu > p2->snu && p1->next != NULL) { //查找适合位置的前一个学生
p2 = p1;
p1 = p1->next;
}
}
if (p2 == p1) { //插入的学生正好为链表头的情况
if (stu->snu < p2->snu) { //插入在表头前
temp = stu;
stu->next = p2;
} else { //插入在表头后
p2->next = stu;
stu->next = NULL;
}
} else { //插入的学生在链表中的情况
if (stu->snu < p1->snu) { //插入到p1指向的学生前
p2->next = stu;
stu->next= p1;
} else { //插入到p1指向的学生后
p1->next = stu;
stu->next = NULL;
}
}
printf("插入成功!\n");
return (temp);
}
struct Student *DeleteLink(struct Student *temp) //该函数用于删除学生成绩
{
struct Student *psctSaveHead=temp,*psctNewTemp;
int iSearchNum;
char cJudge;
system("cls");
Outbiaozhi();
printf("\n\n");
if(temp!=NULL) {
printf("请在下面输入学生学号,输入0返回\n\n\n");
printf("请输入删除的学号:");
fflush(stdin);
scanf("%d",&iSearchNum);
if(iSearchNum==0)return (temp);
while((temp->snu!=iSearchNum)&&(temp->next!=NULL)) {
psctNewTemp=temp;
temp=(temp->next);
}
if(temp->snu==iSearchNum) {
system("cls");
Outbiaozhi();
printf("\n\n");
printf("您要删除的数据是:\n");
OutTableHead();
printf("%ld\t",temp->snu);
printf("%s\t",temp->name);
printf("%s\t",temp->sex);
printf("%s\t",temp->nationality);
printf("%d\t",temp->sage);
printf("%s\t",temp->saddress);
printf("%.1f\t",temp->fLine);
printf("%.1f\t",temp->English);
printf("%.1f\t",temp->maths);
printf("%.1f\t",temp->c_language);
printf("%.1f\t",temp->sumscore);
printf("\n");
printf("\n\n\n");
printf("确定删除(y/n)?");
fflush(stdin);
scanf("%c",&cJudge);
if(cJudge=='y'||cJudge=='Y') {
if(temp==psctSaveHead) {
temp=psctSaveHead;
psctSaveHead=(psctSaveHead->next);
free(temp);
} else if(temp->next==NULL) {
psctNewTemp->next=NULL;
free(temp);
} else {
psctNewTemp->next=temp->next;
free(temp);
}
return (psctSaveHead);
} else
return (psctSaveHead);
} else {
system("cls");
Outbiaozhi();
printf("\n\n");
printf("未能找到该成员信息,按回车键返回\n");
NewPause();
return (psctSaveHead);
}
} else {
printf("尚未创建或读取列表,按回车键返回");
NewPause();
return (psctSaveHead);
}
}
void Search_by_num(struct Student *temp) //按学号查询函数
{
long int num;
struct Student *p1;
printf("请输入学生的学号:");
scanf("%ld",&num);
p1=temp;
while(num!=p1->snu&&p1->next!=NULL)
p1=p1->next;
if(num==p1->snu) {
system("cls");
Outbiaozhi();
printf("\n\n");
OutTableHead();
printf("%ld\t",temp->snu);
printf("%s\t",temp->name);
printf("%s\t",temp->sex);
printf("%s\t",temp->nationality);
printf("%d\t",temp->sage);
printf("%s\t",temp->saddress);
printf("%.1f\t",temp->fLine);
printf("%.1f\t",temp->English);
printf("%.1f\t",temp->maths);
printf("%.1f\t",temp->c_language);
printf("%.1f\t",temp->sumscore);
printf("\n");
printf("按回车键返回主菜单");
NewPause();
} else
printf("没有该学生信息,请核对!");
}
void Search_by_name(struct Student *temp) //按姓名查询函数
{
char name[10];
struct Student *p1;
printf("请输入学生的姓名:");
scanf("%s",name);
p1=temp;
while(strcmp(name,p1->name)&&p1->next!=NULL)
p1=p1->next;
if(!strcmp(name,p1->name)) {
system("cls");
Outbiaozhi();
printf("\n\n");
OutTableHead();
printf("%ld\t",temp->snu);
printf("%s\t",temp->name);
printf("%s\t",temp->sex);
printf("%s\t",temp->nationality);
printf("%d\t",temp->sage);
printf("%s\t",temp->saddress);
printf("%.1f\t",temp->fLine);
printf("%.1f\t",temp->English);
printf("%.1f\t",temp->maths);
printf("%.1f\t",temp->c_language);
printf("%.1f\t",temp->sumscore);
printf("\n");
printf("\n\n\n");
printf("按回车键返回主菜单");
NewPause();
} else
printf("没有该学生信息,请核对!");
}
void Search_by_mohu(struct Student *temp)//按模糊查询函数
{
char name[10];
printf("请输入学生的姓名:");
scanf("%s",name);
struct Student *p1=temp;
struct Student *result=NULL;
system("cls");
Outbiaozhi();
printf("\n\n");
OutTableHead();
while(p1) {
for(int i=0; i < strlen(name); i++) {
if(strchr(p1->name,name[i]) || strchr(p1->nationality,name[i])) {
result=p1;
printf("%ld\t",p1->snu);
printf("%s\t",p1->name);
printf("%s\t",p1->sex);
printf("%s\t",p1->nationality);
printf("%d\t",p1->sage);
printf("%s\t",p1->saddress);
printf("%.1f\t",p1->fLine);
printf("%.1f\t",p1->English);
printf("%.1f\t",p1->maths);
printf("%.1f\t",p1->c_language);
printf("%.1f\t",p1->sumscore);
printf("\n");
break;
}
}
p1=p1->next;
}
if(result == NULL)
printf("没有该学生信息,请核对!\n");
NewPause();
}
void Search_by_nationality(struct Student *temp)//按民族查询函数
{
char nationality[20];//民族
struct Student *p1;
printf("请输入学生的民族:");
scanf("%s",nationality);
p1=temp;
while(strcmp(nationality,p1->nationality)&&p1->next!=NULL)
p1=p1->next;
if(!strcmp(nationality,p1->nationality)) {
system("cls");
Outbiaozhi();
printf("\n\n");
OutTableHead();
printf("%ld\t",temp->snu);
printf("%s\t",temp->name);
printf("%s\t",temp->sex);
printf("%s\t",temp->nationality);
printf("%d\t",temp->sage);
printf("%s\t",temp->saddress);
printf("%.1f\t",temp->fLine);
printf("%.1f\t",temp->English);
printf("%.1f\t",temp->maths);
printf("%.1f\t",temp->c_language);
printf("%.1f\t",temp->sumscore);
printf("\n");
printf("按回车键返回主菜单");
NewPause();
} else
printf("没有该学生信息,请核对!");
}
void Search(struct Student *temp) //此函数用于查询函数
{
system("cls");
Outbiaozhi();
printf("\n\n");
unsigned int cho;
struct Student *p1= temp;
if (temp == NULL) { //对查询空链表时的操作
printf("没有学生信息,请按回车键结束查询返回主菜单\n");
NewPause();
return;
}
printf("\n\n");
printf("请选择查询方式:\n");
printf("1.学号\n");
printf("2.姓名\n");
printf("3.民族\n");
printf("4.模糊姓名\n");
printf("取消,请按0\n");
printf("\n\n");
printf("请选择:\n");
while(!scanf("%u",&cho)) { //对错误输入数据的处理
printf("输入有误,请重新输入序号: ");
fflush(stdin);
}
while(cho != 1 && cho != 2 && cho != 0&& cho != 3&& cho != 4) { //处理不能处理的功能序号
printf("抱歉,没有此功能,请重新输入功能序号: ");
while(!scanf("%u",&cho)) { //接收用户重新输入的功能序号
printf("输入序号有误,请重新输入序号: ");
fflush(stdin);
}
printf("\n"); //输出回车
}
switch(cho) {
case 0:
return;
case 1:
Search_by_num(p1);
break;
case 2:
Search_by_name(p1);
break;
case 3:
Search_by_nationality(p1);//按民族查询函数
break;
case 4:
Search_by_mohu(p1);//按模糊查询函数
break;
default:
printf("\n无效选项!");
break;
}
}
struct Student *IndexLink(struct Student *h,int Judge)//该函数用于统计学生成绩并显示之
{
struct Student *endpt,*u,*v,*p;
u=(struct Student *)malloc(sizeof(struct Student));
u->next=h;
h=u;
for(endpt=NULL; endpt!=h; endpt=p)
for(p=u=h; u->next->next!=endpt; u=u->next)
if(u->next->snu > u->next->next->snu) {
v= u->next->next;
u->next->next=v->next;
v->next=u->next;
u->next=v;
p=u->next->next;
}
u=h;
h=h->next;
free(u);
if(Judge==1)outputlink(h) ;
return (h);
}
struct Student *sort(struct Student *temp)//用于排序链表
{
system("cls");
unsigned int cho;
Outbiaozhi();
printf("\n\n");
printf("请选择排序方式:\n");
printf("1.总成绩\n");
printf("2.c语言\n");
printf("3.高数\n");
printf("请选择:\n");
while(!scanf("%u",&cho)) { //对错误输入数据的处理
printf("输入有误,请重新输入序号: ");
fflush(stdin);
}
while(cho != 1 && cho != 2 && cho != 0&& cho != 3) { //处理不能处理的功能序号
printf("抱歉,没有此功能,请重新输入功能序号: ");
while(!scanf("%d",&cho)) { //接收用户重新输入的功能序号
printf("输入序号有误,请重新输入序号: ");
fflush(stdin);
}
printf("\n"); //输出回车
}
switch(cho) {
case 0:
return temp;
case 1:
temp=SortLink(temp);
break;
case 2:
temp=SortLink_c_language(temp);
break;
case 3:
temp=SortLink_maths(temp);
break;
default:
printf("\n无效选项!");
break;
}
return temp;
}
struct Student *SortLink(struct Student *h)//该函数用于排序学生成绩(按总成绩),采用冒泡法
{
if (h == NULL) { //对查询空链表时的操作
printf("没有学生信息,请按回车键结束查询返回主菜单\n");
NewPause();
return h;
}
struct Student *endpt,*u,*v,*p;
system("cls");
Outbiaozhi();
printf("\n\n");
u =(struct Student*)malloc(sizeof(struct Student));
u->next=h;
h = u;
for(endpt=NULL; endpt!=h; endpt=p)
for(p=u=h; u->next->next!=endpt; u=u->next)
if(u->next->sumscore < u->next->next->sumscore) {
/* 两相邻结点比较 */
v = u->next->next;
u->next->next = v->next;
v->next = u->next;
u->next = v;
p = u->next->next;
}
u = h;
h = h->next;
free(u);
outputlink(h);
return h;
}
struct Student *SortLink_maths(struct Student *h)//该函数用于排序学生成绩(按数学),采用冒泡法
{
if (h == NULL) { //对查询空链表时的操作
printf("没有学生信息,请按回车键结束查询返回主菜单\n");
NewPause();
return h;
}
struct Student *endpt,*u,*v,*p;
system("cls");
Outbiaozhi();
printf("\n\n");
u =(struct Student*)malloc(sizeof(struct Student));
u->next=h;
h = u;
for(endpt=NULL; endpt!=h; endpt=p)
for(p=u=h; u->next->next!=endpt; u=u->next)
if(u->next->maths < u->next->next->maths) {
/* 两相邻结点比较 */
v = u->next->next;
u->next->next = v->next;
v->next = u->next;
u->next = v;
p = u->next->next;
}
u = h;
h = h->next;
free(u);
outputlink(h);
return h;
}
struct Student *SortLink_c_language(struct Student *h)//该函数用于排序学生成绩(按c语言),采用冒泡法
{
if (h == NULL) { //对查询空链表时的操作
printf("没有学生信息,请按回车键结束查询返回主菜单\n");
NewPause();
return h;
}
struct Student *endpt,*u,*v,*p;
system("cls");
Outbiaozhi();
printf("\n\n");
u =(struct Student*)malloc(sizeof(struct Student));
u->next=h;
h = u;
for(endpt=NULL; endpt!=h; endpt=p)
for(p=u=h; u->next->next!=endpt; u=u->next)
if(u->next->c_language < u->next->next->c_language) {
/* 两相邻结点比较 */
v = u->next->next;
u->next->next = v->next;
v->next = u->next;
u->next = v;
p = u->next->next;
}
u = h;
h = h->next;
free(u);
outputlink(h);
return h;
}
int savefilelink(struct Student *temp) //该函数用于存储学生成绩到文件
{
if (temp == NULL) { //对空链表的处理
printf("没有学生信息,结束存储\n ");
printf("按回车键返回");
NewPause();
return 1;
}
FILE *SaveFile;
char position[100];
system("cls");
Outbiaozhi();
printf("\n\n");
printf("请输入保存文件的路径:\n");
scanf("%s",position);
if(strcmp(position,"0")==0)return (0);
if((SaveFile=fopen(position,"wt"))==NULL) {
system("cls");
Outbiaozhi();
printf("\n\n");
printf("无法打开该文件!\n");
return 1;
} else {
while(temp!=NULL) {
fprintf(SaveFile,"%ld %s %s %s %d %s %f %f %f %f %f\n",
temp->snu,temp->name,temp->sex,temp->nationality,
temp->sage,temp->saddress,temp->fLine,temp->English,
temp->maths,temp->c_language,temp->sumscore);
temp=temp->next;
}
printf("已成功保存文件,请按回车键返回!");
NewPause();
fclose(SaveFile);
return 1;
}
}
struct Student *LoadLink() //该函数用于从文件读取学生成绩
{
FILE *pfLoadFile;
char position[100];
system("cls");
Outbiaozhi();
printf("\n\n");
printf("请输入需要读取文件的路径:\n");
scanf("%s",position);
if(strcmp(position,"0")==0)return(0);
if((pfLoadFile=fopen(position,"rt"))==NULL) {
system("cls");
Outbiaozhi();
printf("\n\n");
printf("无法打开该文件!\n");
printf("请按回车键返回!");
NewPause();
return NULL;
} else {
struct Student *head,*temp1,*temp2;
head=NULL;
if(!feof(pfLoadFile)) {
temp1=(struct Student *)malloc(sizeof(struct Student));
fscanf(pfLoadFile,"%ld %s %s %s %d %s %f %f %f %f %f\n",
&(temp1->snu),(temp1->name),(temp1->sex),(temp1->nationality),
&(temp1->sage),(temp1->saddress),&(temp1->fLine),&(temp1->English),
&(temp1->maths),&(temp1->c_language),&(temp1->sumscore));
while(!feof(pfLoadFile)) {
if(head==NULL)head=temp1;
temp2=(struct Student *)malloc(sizeof(struct Student));
temp1->next=temp2; //前一节点的后继指针指向新开辟的节点
temp1=temp2; //方便后面的循环
fscanf(pfLoadFile,"%ld %s %s %s %d %s %f %f %f %f %f\n",
&(temp1->snu),(temp1->name),(temp1->sex),
(temp1->nationality),&(temp1->sage),(temp1->saddress),
&(temp1->fLine),&(temp1->English),&(temp1->maths),
&(temp1->c_language),&(temp1->sumscore));
}
temp1->next=NULL;
fclose(pfLoadFile);
printf("已成功导入文件,请按回车键返回!");
NewPause();
return head;
} else {
fclose(pfLoadFile);
printf("已成功导入文件,请按回车键返回!");
NewPause();
return NULL;
}
}
}
void changepassword() //该函数用于修改系统密码
{
char ch1,ch2,passwordtemp[M],password2[M];
int i=0,j=0,x;
do {
i=0,j=0;
printf("请输入新密码\n");
while((ch1=getch())!='\r' && i<=M) {
if(ch1=='\b') {
if(i>0) {
i--;
printf("\b \b");// 密码支持退格的实现
} else
putchar(7);
} else {
passwordtemp[i++]=ch1;
printf("*");
}
}
passwordtemp[i]='\0';
printf("\n请确认新密码\n");
while((ch2=getch())!='\r' && j<=M) {
if(ch2=='\b') {
if(j>0) {
j--;
printf("\b \b");// 密码支持退格的实现
} else
putchar(7);
} else {
password2[j++]=ch2;
printf("*");
}
}
password2[j]='\0';
if(strcmp(passwordtemp,password2)==0) {
x=0;
printf("\n密码修改成功!\n");
system("pause");
} else {
x=1;
printf("\n两次输入密码不同,请再设置一遍\n");
}
} while(x);
for(i=0; i<=M; i++) {
password[i]=passwordtemp[i];
}
FILE *fp;
fp=fopen("c:\\aaAA\\user.txt","w");
if(fp == NULL) {
printf("打开失败!\n");
getch();
} else {
fprintf(fp,"%s",password);
printf("打开成功,读写成功!2\n");
fclose(fp);
}
}