C++单链表 学生管理系统
这个程序是我好几天的心血,欢迎大家指正!!!
该程序需要新建三个txt文件。1.login.txt用来存放注册用户的用户名与密码。 2.login2.txt用于登录时将login.txt文件中的每行用户名和密码单独存放,比较用户输入的用户名密码是否正确。3.studentlist.txt用于存放学生的信息。

1.程序准备工作(需要的包,设置界面样式:system等)

① 运行程序需要导入的包

#include<stdio.h>
#include<stdlib.h>
#include <fstream>
#include <ctime>
using namespace std;
#include <string.h>
#include <iostream>
using namespace std;

② 编辑进入学生系统的主界面(可根据自己的喜好修改界面样式)

void pr1()
{printf("\t\t\t\t\t*************************\n");
}
//输出界面选项
void pr2()
{printf("\t\t\t\t\t* 请选择需要进行的操作:*\n\
\t\t\t\t\t* 1.创建学生表          *\n\
\t\t\t\t\t* 2.查看学生信息        *\n\
\t\t\t\t\t* 3.删除学生信息        *\n\
\t\t\t\t\t* 4.插入学生信息        *\n\
\t\t\t\t\t* 5.修改学生信息        *\n\
\t\t\t\t\t* 6.查找学生信息        *\n\
\t\t\t\t\t* 7.按学号排序          *\n\
\t\t\t\t\t* 8.按成绩排序          *\n\
\t\t\t\t\t* 9.查看一个班级学生信息*\n\
\t\t\t\t\t* 10.保存到文件中       *\n\
\t\t\t\t\t* 11.从文件中导入       *\n\
\t\t\t\t\t* 12.读取文件中的数据   *\n\
\t\t\t\t\t* 13.退出               *\n");
}

学生系统主界面效果示意图,背景和字体颜色可以根据自己喜好调整。本人用的是黑色背景,字体颜色是绿色:system(“color 01”)

2.设置登录界面,以及注册界面

该程序有点复杂,因为要考虑多种登录注册时需要遇见的情况(登录时账号密码错误,忘记密码,注册用户名已存在等)
上面也介绍过了,需要新建两个txt文件:login.txt,login2.txt。login.txt文件用来储存所有已经注册过的用户名与密码,login2.txt用于程序在执行登录、找回密码以及检验注册的用户名是否存在时使用

//生成验证码
void myrand(char str[],int leng)
{srand(int(time(0)));//产生随机种子,保证每次的数据都不重复char temp;for (int i=0;i<leng;i++){switch (rand()%3){case 0:temp = rand()%9+'1';break;case 1:temp = rand()%26+'a';break;case 2:temp = rand()%26+'A';break;}str[i]=temp;  }
}
void login()
{int i,j,run=1;char username[50],password[50],namepass[100];printf("\t\t\t\t\t欢迎您进入学生系统的主界面!\n");printf("\t\t\t\t\t【1】我已经注册过了!\n");printf("\t\t\t\t\t【2】未注册,现在注册!\n"); printf("\t\t\t\t\t请选择:");scanf("%d",&i);while(run==1){if(i==2)//注册用户{int len,y=1; system("title 注册界面");printf("\t\t\t\t====================欢迎注册====================\n");printf("\t\t\t\t\t欢迎新用户注册!\n");len=strlen(username);ifstream fp("C:\\Users\\Desktop\\login.txt");string line;FILE *f;while(y==1)//判断新用户名是否注册过{char str[50];printf("\t\t\t\t\t请输入您的用户名:");scanf("%s",username);while(getline(fp,line)){y=1;ofstream fp1("C:\\Users\\Desktop\\login2.txt");fp1<<line<<endl;fp1.close();f=fopen("C:\\Users\\Desktop\\login2.txt","r");while(fgets(str,50,f)!=0){str[strlen(str)-1]='\0';fclose(f);}for(int k=0;k<(len-1);k++){if(username[k]!=str[k]){y=0;break;}}if(y==1){printf("\t\t\t\t\t该用户名已存在!请重新输入!\n");break;}}}//如果没有注册过,则开始设置密码,并将用户名密码存入login.txt中printf("\t\t\t\t\t请输入您的密码:");scanf("%s",password);fstream ff;ff.open("C:\\Users\\Desktop\\login.txt",ios::out|ios::app);ff<<username;ff<<password;ff<<"\n";ff.close();printf("\t\t\t\t\t注册成功!\n");printf("\t\t\t\t\t");system("pause");system("cls");}system("title 登录界面");//登录操作printf("\t\t\t\t====================欢迎登录====================\n");printf("\t\t\t\t\t请输入您的用户名:"); scanf("%s",username);printf("\t\t\t\t\t请输入您的密码:");scanf("%s",password);strcpy(namepass,strcat(username,password));char str[50];FILE *f;ifstream fp("C:\\Users\\Desktop\\login.txt");string line;while(getline(fp,line))//判断用户名与密码是否正确{ofstream fp1("C:\\Users\\Desktop\\login2.txt");fp1<<line<<endl;fp1.close();f=fopen("C:\\Users\\Desktop\\login2.txt","r");while(fgets(str,50,f)!=0){str[strlen(str)-1]='\0';fclose(f);if(strcmp(namepass,str)==0){char yan[6],ren[6],to=1;while(to){myrand(yan,6);//随机生成一个验证码cout<<"\t\t\t\t\t请输入验证码(区分大小写)|"<<yan<<"|:";scanf("%s",ren);if(strcmp(yan,ren)==0){printf("\t\t\t\t\t登录成功!\n");to=0;}if(to==1)printf("\t\t\t\t\t验证码有误,请重新输入!\n");}run=0;printf("\t\t\t\t\t");system("pause");system("cls");}}}if(run==1){printf("\t\t\t\t账号或密码错误,请输入正确的账号和密码!(1.重新输入 2.忘记密码):");scanf("%d",&j);system("cls");if(j==2){run=2;} }if(run==2){system("title 找回密码");printf("\t\t\t\t====================找回密码====================\n");int ulen,k,go=1;char str[50];FILE *f;ifstream fp("C:\\Users\\Desktop\\login.txt");printf("\t\t\t\t\t请输入你的用户名:");scanf("%s",username);ulen=strlen(username);string line;while(getline(fp,line)){go=1;ofstream fp1("C:\\Users\\Desktop\\login2.txt");fp1<<line<<endl;fp1.close();f=fopen("C:\\Users\\Desktop\\login2.txt","r");while(fgets(str,50,f)!=0){str[strlen(str)-1]='\0';fclose(f);}for(k=0;k<(ulen-1);k++){if(username[k]!=str[k]){go=0;break;}}if(go==1){k=k+1;printf("\t\t\t\t\t");cout<<"用户"<<username<<",你的密码为:";for(k;k<strlen(str);k++)cout<<str[k];run=1;printf("\n");break;}}if(go==0){printf("\t\t\t\t\t该用户名没有在此网站注册!请注册登录!\n");i=2;run=1;printf("\t\t\t\t\t");system("pause");system("cls");}printf("\t\t\t\t\t");system("pause");system("cls");    }}
}

注册界面

登录界面

再次注册,发现该用户名已被注册。
登录时忘记密码。

3.初始化链表,创建结构体,以及对链表的多种操作

① 创建链表结构体

num:学号 score:成绩 sex:性别 name:姓名 cla:班级 pnext:指向下一个节点

typedef struct Node
{long int num;float score;char sex[20];char name[20];char cla[20];struct Node * pnext;
}N,*P;
//创建链表
P create()
{P phead=(P)malloc(sizeof(N));if(phead==NULL){printf("分配内存失败,退出程序\n");exit(-1);}phead->pnext=NULL;return phead;
}

② 在phead链表的末尾加入一个last节点

//在链表的末尾加入节点
void connect(P phead,P last)
{while(phead->pnext!=NULL)//将指针指向链表的末尾{phead=phead->pnext;}phead->pnext=last;
}

③ 计算链表中节点个数

//计算链表节点的个数
int length(P phead)
{int count=0;while(phead->pnext!=NULL)//遍历整个链表{phead=phead->pnext;count++;}return count;
}

④ 交换链表中相邻的两个节点(主要用于后面的冒泡排序)

//交换链表中相邻的两个数据
void numexchange(P head)
{P left=head->pnext;P right=left->pnext;P three=right->pnext;head->pnext=right;right->pnext=left;left->pnext=three;
}

⑤判断放入的学号在链表中是否已经存在

bool input(P phead,long int num)
{while(phead->pnext!=NULL){phead=phead->pnext;if(phead->num==num)return false;}if(phead->pnext==NULL)return true;
}

4.文件操作(导入,写入,读取)

①将txt文件中的数据导入到链表中

//导入txt文件中学生的信息
void putfile(P phead)
{int i=0,j;j=getlines(); FILE *fp;fp = fopen("C:\\Users\\Desktop\\studentlist.txt","r");while(true) {P p = create();if(fscanf(fp,"%ld\t%s\t%s\t%s\t%f\n",&p->num,p->sex,p->name,p->cla,&p->score)==j){}phead->pnext = p;phead = phead->pnext;i++;if(i==5)break;}fclose(fp);printf("\t\t\t\t\t导入信息成功!");system("pause");
}

txt文件中的内容
导入数据到链表中,并显示出来。

②读取txt文件中的数据,并输出

//读取文件中的数据
void duqufile()
{char str[50];ifstream fp("C:\\Users\\楷哥\\Desktop\\studentlist.txt");string line;printf("\t\t\t\t\t学号\t性别\t姓名\t班级\t成绩\t\n"); while(getline(fp,line)){cout<<"\t\t\t\t\t"<<line<<endl;}
}

③将数据写入txt文件

//将学生信息保存到文件中
void getfile(P phead)
{FILE *outfile;if((outfile = fopen("C:\\Users\\楷哥\\Desktop\\studentlist.txt", "w")) == NULL){printf("\t\t\t\t打开文件失败!");      }phead=phead->pnext; while(phead){fprintf(outfile, "%d\t%s\t%s\t%s\t%.2f\n", phead->num, phead->sex, phead->name, phead->cla, phead->score);phead=phead->pnext;}fclose(outfile);
}

前面铺垫了这么多准备工作,终于到达程序的重点了!!!(●’◡’●)(●’◡’●)

5.新建学生信息表,对学生信息的增、删、改、查以及排序等操作。

①新建学生信息表

system("color 01");
system("title   创建学生表");
printf("\t\t\t\t====================创建学生表====================\n");
printf("\t\t\t\t请输入学生数量:");
scanf("%d",&n);
for(int i=0;i<n;i++)
{printf("\t\t\t\t=====================(%d)=====================\n\n",i+1);P last=(P)malloc(sizeof(N));if(last==NULL){printf("\t\t\t\t分配内存失败,退出程序\n");exit(-1);}printf("\t\t\t\t请输入第%d个学生的学号:",(i+1));scanf("%ld",&num);if(input(phead,num)==1)//判断新放入的学号之前是否已经存在(一个学号只能对应一个学生!){printf("\t\t\t\t请输入第%d个学生的性别、姓名、班级、成绩:",(i+1));last->num=num;scanf("%s",last->sex);scanf("%s",last->name);scanf("%s",last->cla);scanf("%f",&last->score);last->pnext=NULL;connect(phead,last);printf("\n");}else{printf("\t\t\t\t你输入的学号在学生表中已经存在,请重新输入!\n");i--;}
}
printf("\t\t\t\t====================创建成功!====================\n\n");
printf("\t\t\t\t");system("pause");system("cls");
break;

②展示学生信息表内容

//展示链表中的数据
void show(P phead)
{printf("\t\t\t\t该学生系统共有%d名学生。\n\n",length(phead)); printf("\t\t\t\t学号\t性别\t姓名\t班级\t成绩  \n");while(phead->pnext!=NULL){phead=phead->pnext;printf("\t\t\t\t%ld\t%s\t%s\t%s\t%.2f\n",phead->num,phead->sex,phead->name,phead->cla,phead->score);}
}

③插入学生信息

编辑插入函数

//插入学生信息
void insert(P phead,long int num)
{while(phead->pnext!=NULL){phead=phead->pnext;}P last=(P)malloc(sizeof(N));if(last==NULL){printf("\t\t\t\t分配内存失败,退出程序\n");exit(-1);}last->num=num;printf("\t\t\t\t请输入需要插入学生信息的性别、姓名、班级、成绩:");scanf("%s",last->sex);scanf("%s",last->name);scanf("%s",last->cla);scanf("%f",&last->score);last->pnext=NULL;phead->pnext=last;
}
system("color 05");
system("title   插入学生信息");
printf("\t\t\t\t===================插入学生信息===================\n\n");
printf("\t\t\t\t请输入你需要插入学生的学号:");
scanf("%d",&num);
while(input(phead,num)==0)//判断插入学生的学号是否存在!
{printf("\t\t\t\t你输入的学号在表中已存在!请重新输入!\n");printf("\t\t\t\t请输入你要插入学生的学号:");scanf("%d",&num);
}
insert(phead,num);
printf("\t\t\t\t插入成功!学生系统信息如下::\n");
show(phead);
printf("\n");
printf("\t\t\t\t");system("pause");system("cls");
break;

④删除学生信息

删除学生信息函数

//删除学生信息
bool del(P phead,long int num)
{while(phead->pnext!=NULL){if(phead->pnext->num==num)break;phead=phead->pnext;}if(phead->pnext==NULL)return false;else{P ptail=phead->pnext->pnext;free(phead->pnext);phead->pnext=ptail;return true;}
}
system("color 04");
system("title   删除学生信息");
printf("\t\t\t\t===================删除学生信息===================\n\n");
printf("\t\t\t\t请输入你需要删除学生的学号:");
scanf("%d",&num);
while(del(phead,num)==0)
{printf("\t\t\t\t输入的学号有误,请重新输入:");scanf("%d",&num);
}
printf("\t\t\t\t删除成功!学生系统信息如下:\n");
show(phead);
printf("\n");
printf("\t\t\t\t");system("pause");system("cls");
break;

⑤修改学生信息

修改学生信息函数

//修改学生信息
void revise(P phead,long int num)
{int i,n,run=1;char choose[5];P hhh=phead;while(phead->pnext!=NULL){phead=phead->pnext;if(phead->num==num)break;}while(run){printf("\t\t\t\t请输入你需要修改的内容(1.学号 2.性别 3.姓名 4.班级 5.成绩):");scanf("%d",&i);switch(i){case 1:printf("\t\t\t\t你需要将该学生的学号修改为:");scanf("%d",&n);while(input(hhh,n)==0){printf("\t\t\t\t该学生表中已有该学号的学生,无法修改,是否继续修改该学生学号(yes or no):");scanf("%s",choose);if(choose[0]=='n')break;printf("\t\t\t\t你需要将该学生的学号修改为:");scanf("%d",&n);}phead->num=n;break;case 2:printf("\t\t\t\t你需要将该学生的性别修改为:");scanf("%s",phead->sex);break;case 3:printf("\t\t\t\t你需要将该学生的姓名修改为:");scanf("%s",phead->name);break;case 4: printf("\t\t\t\t你需要将该学生的班级修改为:");scanf("%s",phead->cla);break;case 5:printf("\t\t\t\t你需要将该学生的成绩修改为:");scanf("%f",&phead->score);break;}printf("\t\t\t\t是否继续修改该学生的其他内容(yes or no):");scanf("%s",choose);if(choose[0]=='n')run=0;}
}
system("color 06");
system("title   修改学生信息");
printf("\t\t\t\t===================修改学生信息===================\n\n");
printf("\t\t\t\t请输入你需要修改学生的学号:");
scanf("%d",&num);
while(input(phead,num)==1)
{printf("\t\t\t\t你输入的学号在表中不存在!请重新输入!\n");printf("\t\t\t\t请输入你需要修改学生的学号:");scanf("%d",&num);
}
revise(phead,num);
printf("\t\t\t\t修改成功!学生系统信息如下::\n");
show(phead);
printf("\n");
printf("\t\t\t\t");system("pause");system("cls");
break;

⑥查找学生信息

查找学生信息函数

//查找学生信息
void find(P phead,long int num)
{while(phead->pnext!=NULL){phead=phead->pnext;if(phead->num==num)break;}printf("\t\t\t\t该学生的信息为:学号:%d 性别:%s 姓名:%s 班级:%s 成绩:%.2f\n",phead->num,phead->sex,phead->name,phead->cla,phead->score);
}
system("color 07");
system("title   查找学生信息");
printf("\t\t\t\t===================查找学生信息===================\n\n");
printf("\t\t\t\t请输入你需要查找学生信息的学号:");
scanf("%d",&num);
while(input(phead,num)==1)
{printf("\t\t\t\t该学生系统中没有该学号的学生,请重新输入!\n");printf("\t\t\t\t请输入你需要查找学生信息的学号:");scanf("%d",&num);
}
find(phead,num);
printf("\n");
printf("\t\t\t\t");system("pause");system("cls");
break;

⑦按学号排序

学号排序函数

//按学号排序
void numsort(P phead)
{int n,i,j;n=length(phead);for(i=n-1;i>=1;i--){P head=phead;for(j=0;j<i;j++){if(head->pnext->num>head->pnext->pnext->num){numexchange(head);}head=head->pnext;}}
}
system("color F3");
system("title   按学号排序");
printf("\t\t\t\t===================按学号排序===================\n\n");
numsort(phead);
printf("\t\t\t\t按学号排序成功!学生排序如下:\n\n");
show(phead);
printf("\n");
printf("\t\t\t\t");system("pause");system("cls");
break;

⑧按成绩排序

成绩排序函数

//按成绩排序
void scoresort(P phead)
{int n,i,j;n=length(phead);for(i=n-1;i>=1;i--){P head=phead;for(j=0;j<i;j++){if(head->pnext->score<head->pnext->pnext->score){numexchange(head);}head=head->pnext;}}
}
system("color F0");
system("title   按成绩排序");
printf("\t\t\t\t===================按成绩排序===================\n\n");
scoresort(phead);
printf("\t\t\t\t按成绩排序成功!学生排序如下:\n\n");
show(phead);
printf("\n");
printf("\t\t\t\t");system("pause");system("cls");
break;

⑨按班级分类

//按班级分类
void findcla(P phead)
{char cla[20]; printf("\t\t\t\t请输入你需要查找的班级名称:");scanf("%s",cla);printf("\t\t\t\t该班级的学生信息为:\n");printf("\t\t\t\t学号\t性别\t姓名\t班级\t成绩\n");while(phead->pnext!=NULL){phead=phead->pnext;if(strcmp(cla,phead->cla)==0){printf("\t\t\t\t%ld\t%s\t%s\t%s\t%.2f\n",phead->num,phead->sex,phead->name,phead->cla,phead->score);}else continue;}
}
system("color F4");
system("title   按班级分类");
printf("\t\t\t\t===================按班级分类===================\n\n");
findcla(phead);
printf("\t\t\t\t");system("pause");system("cls");
break;

总结

以上的所有程序(并不完整)就是这个学生操作系统的主干部分,读者可以根据自己的喜好进行一些更改,有一些地方确实时间复杂度很高,但小编能力有限/(ㄒoㄒ)/~~,所以有什么需要改进的地方也可以和码码匠商量。

总程序代码!!!

#include<stdio.h>
#include<stdlib.h>
#include <fstream>
#include <ctime>
using namespace std;
#include <string.h>
#include <iostream>
using namespace std;
void pr1()
{printf("\t\t\t\t\t*************************\n");
}
//输出界面选项
void pr2()
{printf("\t\t\t\t\t* 请选择需要进行的操作:*\n\
\t\t\t\t\t* 1.创建学生表          *\n\
\t\t\t\t\t* 2.查看学生信息        *\n\
\t\t\t\t\t* 3.删除学生信息        *\n\
\t\t\t\t\t* 4.插入学生信息        *\n\
\t\t\t\t\t* 5.修改学生信息        *\n\
\t\t\t\t\t* 6.查找学生信息        *\n\
\t\t\t\t\t* 7.按学号排序          *\n\
\t\t\t\t\t* 8.按成绩排序          *\n\
\t\t\t\t\t* 9.查看一个班级学生信息*\n\
\t\t\t\t\t* 10.保存到文件中       *\n\
\t\t\t\t\t* 11.从文件中导入       *\n\
\t\t\t\t\t* 12.读取文件中的数据   *\n\
\t\t\t\t\t* 13.退出               *\n");
}
//生成验证码
void myrand(char str[],int leng)
{srand(int(time(0)));//产生随机种子,保证每次的数据都不重复char temp;for (int i = 0; i < leng; i++){switch (rand() % 3){case 0:temp = rand() % 9 + '1';break;case 1:temp = rand() % 26 + 'a';break;case 2:temp = rand() % 26 + 'A';break;}str[i]=temp;  }
}
//创建每个节点的结构体
typedef struct Node
{long int num;float score;char sex[20];char name[20];char cla[20];struct Node * pnext;
}N,*P;
//创建链表
P create()
{P phead=(P)malloc(sizeof(N));if(phead==NULL){printf("分配内存失败,退出程序\n");exit(-1);}phead->pnext=NULL;return phead;
}//在链表的末尾加入节点
void connect(P phead,P last)
{while(phead->pnext!=NULL){phead=phead->pnext;}phead->pnext=last;
}
//计算链表节点的个数
int length(P phead)
{int count=0;while(phead->pnext!=NULL){phead=phead->pnext;count++;}return count;
}
//展示链表中的数据
void show(P phead)
{printf("\t\t\t\t该学生系统共有%d名学生。\n\n",length(phead)); printf("\t\t\t\t学号\t性别\t姓名\t班级\t成绩  \n");while(phead->pnext!=NULL){phead=phead->pnext;printf("\t\t\t\t%ld\t%s\t%s\t%s\t%.2f\n",phead->num,phead->sex,phead->name,phead->cla,phead->score);}
}
//交换链表中相邻的两个数据
void numexchange(P head)
{P left=head->pnext;P right=left->pnext;P three=right->pnext;head->pnext=right;right->pnext=left;left->pnext=three;
}
//得到学生信息表txt文件中的排数
int getlines()
{int i=0;ifstream fp("C:\\Users\\Desktop\\studentlist.txt");string line;while(getline(fp,line)){i++;}return i;
}
//导入txt文件中学生的信息
void putfile(P phead)
{int i=0,j;j=getlines(); FILE *fp;fp = fopen("C:\\Users\\Desktop\\studentlist.txt","r");while(true) {P p = create();if(fscanf(fp,"%ld\t%s\t%s\t%s\t%f\n",&p->num,p->sex,p->name,p->cla,&p->score)==j){}phead->pnext = p;phead = phead->pnext;i++;if(i==5)break;}fclose(fp);printf("\t\t\t\t\t导入信息成功!");system("pause");
}
//将学生信息保存到文件中
void getfile(P phead)
{FILE *outfile;if((outfile = fopen("C:\\Users\\Desktop\\studentlist.txt", "w")) == NULL){printf("\t\t\t\t打开文件失败!");      }phead=phead->pnext; while(phead){fprintf(outfile, "%d\t%s\t%s\t%s\t%.2f\n", phead->num, phead->sex, phead->name, phead->cla, phead->score);phead=phead->pnext;}fclose(outfile);
}
//读取文件中的数据
void duqufile()
{char str[50];ifstream fp("C:\\Users\\Desktop\\studentlist.txt");string line;printf("\t\t\t\t\t学号\t性别\t姓名\t班级\t成绩\t\n"); while(getline(fp,line)){cout<<"\t\t\t\t\t"<<line<<endl;}
}
void login()
{int i,j,run=1;char username[50],password[50],namepass[100];printf("\t\t\t\t\t欢迎您进入学生系统的主界面!\n");printf("\t\t\t\t\t【1】我已经注册过了!\n");printf("\t\t\t\t\t【2】未注册,现在注册!\n"); printf("\t\t\t\t\t请选择:");scanf("%d",&i);while(run==1){if(i==2){int len,y=1; system("title 注册界面");printf("\t\t\t\t====================欢迎注册====================\n");printf("\t\t\t\t\t欢迎新用户注册!\n");len=strlen(username);ifstream fp("C:\\Users\\Desktop\\login.txt");string line;FILE *f;while(y==1){char str[50];printf("\t\t\t\t\t请输入您的用户名:");scanf("%s",username);while(getline(fp,line)){y=1;ofstream fp1("C:\\Users\\Desktop\\login2.txt");fp1<<line<<endl;fp1.close();f=fopen("C:\\Users\\Desktop\\login2.txt","r");while(fgets(str,50,f)!=0){str[strlen(str)-1]='\0';fclose(f);}for(int k=0;k<(len-1);k++){if(username[k]!=str[k]){y=0;break;}}if(y==1){printf("\t\t\t\t\t该用户名已存在!请重新输入!\n");break;}}}printf("\t\t\t\t\t请输入您的密码:");scanf("%s",password);fstream ff;ff.open("C:\\Users\\Desktop\\login.txt",ios::out|ios::app);ff<<username;ff<<password;ff<<"\n";ff.close();printf("\t\t\t\t\t注册成功!\n");printf("\t\t\t\t\t");system("pause");system("cls");}system("title 登录界面");printf("\t\t\t\t====================欢迎登录====================\n");printf("\t\t\t\t\t请输入您的用户名:"); scanf("%s",username);printf("\t\t\t\t\t请输入您的密码:");scanf("%s",password);strcpy(namepass,strcat(username,password));char str[50];FILE *f;ifstream fp("C:\\Users\\Desktop\\login.txt");string line;while(getline(fp,line)){ofstream fp1("C:\\Users\\Desktop\\login2.txt");fp1<<line<<endl;fp1.close();f=fopen("C:\\Users\\Desktop\\login2.txt","r");while(fgets(str,50,f)!=0){str[strlen(str)-1]='\0';fclose(f);if(strcmp(namepass,str)==0){char yan[6],ren[6],to=1;while(to){myrand(yan,6);cout<<"\t\t\t\t\t请输入验证码(区分大小写)|"<<yan<<"|:";scanf("%s",ren);if(strcmp(yan,ren)==0){printf("\t\t\t\t\t登录成功!\n");to=0;}if(to==1)printf("\t\t\t\t\t验证码有误,请重新输入!\n");}run=0;printf("\t\t\t\t\t");system("pause");system("cls");}}}if(run==1){printf("\t\t\t\t账号或密码错误,请输入正确的账号和密码!(1.重新输入 2.忘记密码):");scanf("%d",&j);system("cls");if(j==2){run=2;} }if(run==2){system("title 找回密码");printf("\t\t\t\t====================找回密码====================\n");int ulen,k,go=1;char str[50];FILE *f;ifstream fp("C:\\Users\\Desktop\\login.txt");printf("\t\t\t\t\t请输入你的用户名:");scanf("%s",username);ulen=strlen(username);string line;while(getline(fp,line)){go=1;ofstream fp1("C:\\Users\\Desktop\\login2.txt");fp1<<line<<endl;fp1.close();f=fopen("C:\\Users\\Desktop\\login2.txt","r");while(fgets(str,50,f)!=0){str[strlen(str)-1]='\0';fclose(f);}for(k=0;k<(ulen-1);k++){if(username[k]!=str[k]){go=0;break;}}if(go==1){k=k+1;printf("\t\t\t\t\t");cout<<"用户"<<username<<",你的密码为:";for(k;k<strlen(str);k++)cout<<str[k];run=1;printf("\n");break;}}if(go==0){printf("\t\t\t\t\t该用户名没有在此网站注册!请注册登录!\n");i=2;run=1;printf("\t\t\t\t\t");system("pause");system("cls");}printf("\t\t\t\t\t");system("pause");system("cls"); }}
}
//向链表中放入数据
bool input(P phead,long int num)
{while(phead->pnext!=NULL){phead=phead->pnext;if(phead->num==num)return false;}if(phead->pnext==NULL)return true;
}
//删除学生信息
bool del(P phead,long int num)
{while(phead->pnext!=NULL){if(phead->pnext->num==num)break;phead=phead->pnext;}if(phead->pnext==NULL)return false;else{P ptail=phead->pnext->pnext;free(phead->pnext);phead->pnext=ptail;return true;}
}
//插入学生信息
void insert(P phead,long int num)
{while(phead->pnext!=NULL){phead=phead->pnext;}P last=(P)malloc(sizeof(N));if(last==NULL){printf("\t\t\t\t分配内存失败,退出程序\n");exit(-1);}last->num=num;printf("\t\t\t\t请输入需要插入学生信息的性别、姓名、班级、成绩:");scanf("%s",last->sex);scanf("%s",last->name);scanf("%s",last->cla);scanf("%f",&last->score);last->pnext=NULL;phead->pnext=last;
}
//修改学生信息
void revise(P phead,long int num)
{int i,n,run=1;char choose[5];P hhh=phead;while(phead->pnext!=NULL){phead=phead->pnext;if(phead->num==num)break;}while(run){printf("\t\t\t\t请输入你需要修改的内容(1.学号 2.性别 3.姓名 4.班级 5.成绩):");scanf("%d",&i);switch(i){case 1:printf("\t\t\t\t你需要将该学生的学号修改为:");scanf("%d",&n);while(input(hhh,n)==0){printf("\t\t\t\t该学生表中已有该学号的学生,无法修改,是否继续修改该学生学号(yes or no):");scanf("%s",choose);if(choose[0]=='n')break;printf("\t\t\t\t你需要将该学生的学号修改为:");scanf("%d",&n);}phead->num=n;break;case 2:printf("\t\t\t\t你需要将该学生的性别修改为:");scanf("%s",phead->sex);break;case 3:printf("\t\t\t\t你需要将该学生的姓名修改为:");scanf("%s",phead->name);break;case 4: printf("\t\t\t\t你需要将该学生的班级修改为:");scanf("%s",phead->cla);break;case 5:printf("\t\t\t\t你需要将该学生的成绩修改为:");scanf("%f",&phead->score);break;}printf("\t\t\t\t是否继续修改该学生的其他内容(yes or no):");scanf("%s",choose);if(choose[0]=='n')run=0;}
}
//查找学生信息
void find(P phead,long int num)
{while(phead->pnext!=NULL){phead=phead->pnext;if(phead->num==num)break;}printf("\t\t\t\t该学生的信息为:学号:%d 性别:%s 姓名:%s 班级:%s 成绩:%.2f\n",phead->num,phead->sex,phead->name,phead->cla,phead->score);
}
//按学号排序
void numsort(P phead)
{int n,i,j;n=length(phead);for(i=n-1;i>=1;i--){P head=phead;for(j=0;j<i;j++){if(head->pnext->num>head->pnext->pnext->num){numexchange(head);}head=head->pnext;}}
}
//按成绩排序
void scoresort(P phead)
{int n,i,j;n=length(phead);for(i=n-1;i>=1;i--){P head=phead;for(j=0;j<i;j++){if(head->pnext->score<head->pnext->pnext->score){numexchange(head);}head=head->pnext;}}
}
//按班级分类
void findcla(P phead)
{char cla[20]; printf("\t\t\t\t请输入你需要查找的班级名称:");scanf("%s",cla);printf("\t\t\t\t该班级的学生信息为:\n");printf("\t\t\t\t学号\t性别\t姓名\t班级\t成绩\n");while(phead->pnext!=NULL){phead=phead->pnext;if(strcmp(cla,phead->cla)==0){printf("\t\t\t\t%ld\t%s\t%s\t%s\t%.2f\n",phead->num,phead->sex,phead->name,phead->cla,phead->score);}else continue;}
}int main()
{system("title 学生管理系统");system("color F1");printf("\t\t\t\t==============欢迎使用学生管理系统==============\n\n");login();int n,num,choose,run=1;P phead=NULL; phead=create();while(run){system("color 0A");pr1();pr2();pr1();printf("\n\t\t\t\t请选择你要进行操作:"); scanf("%d",&choose);system("cls");printf("\n");switch(choose){case 1:system("color 01");system("title   创建学生表");printf("\t\t\t\t====================创建学生表====================\n");printf("\t\t\t\t请输入学生数量:");scanf("%d",&n);for(int i=0;i<n;i++){printf("\t\t\t\t=====================(%d)=====================\n\n",i+1);P last=(P)malloc(sizeof(N));if(last==NULL){printf("\t\t\t\t分配内存失败,退出程序\n");exit(-1);}printf("\t\t\t\t请输入第%d个学生的学号:",(i+1));scanf("%ld",&num);if(input(phead,num)==1){printf("\t\t\t\t请输入第%d个学生的性别、姓名、班级、成绩:",(i+1));last->num=num;scanf("%s",last->sex);scanf("%s",last->name);scanf("%s",last->cla);scanf("%f",&last->score);last->pnext=NULL;connect(phead,last);printf("\n");}else{printf("\t\t\t\t你输入的学号在学生表中已经存在,请重新输入!\n");i--;}}printf("\t\t\t\t====================创建成功!====================\n\n");printf("\t\t\t\t");system("pause");system("cls");break;case 2:system("color 02");system("title   查看学生信息");printf("\t\t\t\t===================查看学生信息===================\n\n");show(phead);printf("\n");printf("\t\t\t\t");system("pause");system("cls");break;case 3:system("color 04");system("title   删除学生信息");printf("\t\t\t\t===================删除学生信息===================\n\n");printf("\t\t\t\t请输入你需要删除学生的学号:");scanf("%d",&num);while(del(phead,num)==0){printf("\t\t\t\t输入的学号有误,请重新输入:");scanf("%d",&num);}printf("\t\t\t\t删除成功!学生系统信息如下:\n");show(phead);printf("\n");printf("\t\t\t\t");system("pause");system("cls");break;case 4:system("color 05");system("title   插入学生信息");printf("\t\t\t\t===================插入学生信息===================\n\n");printf("\t\t\t\t请输入你需要插入学生的学号:");scanf("%d",&num);while(input(phead,num)==0){printf("\t\t\t\t你输入的学号在表中已存在!请重新输入!\n");printf("\t\t\t\t请输入你要插入学生的学号:");scanf("%d",&num);}insert(phead,num);printf("\t\t\t\t插入成功!学生系统信息如下::\n");show(phead);printf("\n");printf("\t\t\t\t");system("pause");system("cls");break;case 5:system("color 06");system("title   修改学生信息");printf("\t\t\t\t===================修改学生信息===================\n\n");printf("\t\t\t\t请输入你需要修改学生的学号:");scanf("%d",&num);while(input(phead,num)==1){printf("\t\t\t\t你输入的学号在表中不存在!请重新输入!\n");printf("\t\t\t\t请输入你需要修改学生的学号:");scanf("%d",&num);}revise(phead,num);printf("\t\t\t\t修改成功!学生系统信息如下::\n");show(phead);printf("\n");printf("\t\t\t\t");system("pause");system("cls");break;case 6:system("color 07");system("title   查找学生信息");printf("\t\t\t\t===================查找学生信息===================\n\n");printf("\t\t\t\t请输入你需要查找学生信息的学号:");scanf("%d",&num);while(input(phead,num)==1){printf("\t\t\t\t该学生系统中没有该学号的学生,请重新输入!\n");printf("\t\t\t\t请输入你需要查找学生信息的学号:");scanf("%d",&num);}find(phead,num);printf("\n");printf("\t\t\t\t");system("pause");system("cls");break;case 7:system("color F3");system("title   按学号排序");printf("\t\t\t\t===================按学号排序===================\n\n");numsort(phead);printf("\t\t\t\t按学号排序成功!学生排序如下:\n\n"); show(phead);printf("\n");printf("\t\t\t\t");system("pause");system("cls");break;case 8:system("color F0");system("title   按成绩排序");printf("\t\t\t\t===================按成绩排序===================\n\n");scoresort(phead);printf("\t\t\t\t按成绩排序成功!学生排序如下:\n\n"); show(phead);printf("\n");printf("\t\t\t\t");system("pause");system("cls");break;case 9:system("color F4");system("title   按班级分类");printf("\t\t\t\t===================按班级分类===================\n\n");findcla(phead);printf("\t\t\t\t");system("pause");system("cls");break;case 10:system("title   保存到文件中");getfile(phead);printf("\t\t\t\t\t保存成功!\n");printf("\t\t\t\t");system("pause");system("cls");break;case 11:system("color F3");system("title   txt导入数据");printf("\t\t\t\t===================txt导入数据===================\n\n");putfile(phead);break; case 12:system("color F2");system("title   txt读取数据");printf("\t\t\t\t===================txt读取数据===================\n\n");duqufile();printf("\t\t\t\t\t读取成功!\n");printf("\t\t\t\t");system("pause");system("cls");break;case 13:run=0;system("color F4"); cout<<"\t\t\t\t------------------__--__-----------------------\n";cout<<"\t\t\t\t-----------------/--"<<"\\"<<"/--"<<"\\"<<"----------------------"<<"\n";cout<<"\t\t\t\t----------------/--------"<<"\\"<<"---------------------\n";cout<<"\t\t\t\t----------------"<<"\\"<<"感谢使用/---------------------\n";cout<<"\t\t\t\t-----------------"<<"\\"<<"------/----------------------\n";cout<<"\t\t\t\t------------------"<<"\\"<<"----/-----------------------\n";cout<<"\t\t\t\t-------------------"<<"\\"<<"--/------------------------\n";cout<<"\t\t\t\t--------------------"<<"\\"<<"/-------------------------\n";cout<<"\t\t\t\t-----------------退出成功!--------------------\n";printf("\n");break;   }}return 0;
}

C++单链表学生管理系统(有登录界面)相关推荐

  1. C语言 学生成绩管理系统 带登录界面

    C语言 学生成绩管理系统 带登录界面 C语言课程设计 思路 部分展示 代码片段 C语言课程设计 先上要求: 思路 为了方便简单,直接利用结构体数组来存储学生学生,最后根据功能编写函数即可. 部分展示 ...

  2. 【学生系统】——登录界面

    登录窗体可谓是一个系统的门面,这个门面的简洁程度.为人民服务的程度以及易操作程度将直接影响用户对这个系统的喜爱程度,也就是说第一眼很大程度的决定了用户是否选择你的系统. 关于学生信息管理系统登录界面其 ...

  3. 【python】学生管理系统GUI可视化界面版本

    关于学生管理系统GUI版本的实现 参考文献: (14条消息) 使用Python中的tkinter模块实现GUI界面的学生信息管理系统_基于tkinter的学生信息管理系统_Marshal_A的博客-C ...

  4. php+Vue单页面学生管理系统

    Php学生管理系统 引言:学生实训,老师要求用php代码写学生管理系统作为实训内容.之前作业都是拜托同学交,此次作业是自由发挥的,故从星期天学习Php的基本语法.如字符串拼接,function的写法, ...

  5. 学生管理系统之登录错误 233

    学生登录系统在最初对于新手而言可能有一些陌生和不知所措,在这里先给大家做一个总结. 在要开始做学生系统的时候,肯定电脑上要先安装一个数据库---SQL  SERVER,然后登录的时候就用Windows ...

  6. C语言基础篇02:单链表实现学生成绩管理系统

    单链表实现学生成绩管理系统 前言 需求分析 详细设计 增加成绩信息 删除成绩信息 修改成绩信息 查询学生信息和浏览学生信息 总结 前言 上篇已经讲过单链表的基本实现,这篇将以一个简单的管理系统入手. ...

  7. 教育培训机构学生管理系统

    摘  要 计算机网络如果结合使用信息管理系统,能够提高管理员管理的效率,改善服务质量.优秀的教育培训机构学生管理系统能够更有效管理教育培训机构学生信息业务规范,帮助管理者更加有效管理教育培训机构学生信 ...

  8. java与数据库综合实训_JAVA数据库学生管理系统实训报告

    <JAVA数据库学生管理系统实训报告>由会员分享,可在线阅读,更多相关<JAVA数据库学生管理系统实训报告(43页珍藏版)>请在人人文库网上搜索. 1.实训报告实训名称:学生成 ...

  9. 学生管理系统(Java+MySQL+GUI)

    系统要求 设计一个学生管理系统,能够实现简单的学生管理功能. 数据库stu包含两个表: ①user:用户表,字段为(id,password),用于实现登录功能. ②student:学生表,字段为(sn ...

最新文章

  1. const在函数前与函数后的区别 [转]
  2. Dubbo配置文件详解
  3. 交易所频频被盗,你该如何保护自己的数字资产?
  4. Angularjs中文教程
  5. 干货丨详解深度学习的一些关键术语
  6. C 语言 *** glibc detected *** free(): invalid next size (fast): 0x0000000000be1010 ***
  7. Xamarin Live Player Preview 2: 连续运行和调试应用程序
  8. 第三次学JAVA再学不好就吃翔(part65)--正则表达式
  9. 永磁交流伺服电机的工作原理与更换新编码器后的常规零位校正方法
  10. 手把手教你用.NET Core写爬虫
  11. 浏览器linux安装失败,LINUX 上安装WAS 提示没有浏览器问题
  12. Leetcode376.摆动序列
  13. python 打开xml文件修改其中的值,通过点选图像获得其像素值
  14. verilog赋多位值_verilog语句两个always块对同一个变量赋值问题!【恢复】
  15. python同步油管用户信息
  16. 使用VBA在WORD中插入漂亮的代码
  17. Python Numpy
  18. linux 修改网卡mac地址,Ubuntu 更改mac地址
  19. [附源码]计算机毕业设计JAVA景区门票系统
  20. Word目录:【同一篇文档设置多个独立目录】详细过程

热门文章

  1. Python组合数据
  2. 网易云音乐数据服务之路
  3. Malcolm的新书:Outliers
  4. unity游戏动画 从入门到住院 二 模型导入
  5. 2019年互联网公司月饼颜值大比拼!
  6. ae-概述、流程、菜单01
  7. linux parted 直接删除分区,CentOS7硬盘分区,删除分区,格式化分区硬盘,支持4T硬盘,fdisk,parted简单用法...
  8. 适用于 GNU/Linux 的字型
  9. 投资理财--熊市笨小孩式交易75-25
  10. Robocup2D入门笔记(1)——概述