student.cppstudent.cpp该学生管理系统就是用的是vs2013编辑器,实现了功能如下
(1):用户的登录
(2)运用双连表进行信息的插入
(3)学生信息的查询,删除。
(4)对学生信息的打印
(5)运用双链表对学生分数的排序
(6)释放运行空间,对空间进行回收处理,退出学生管理系统
//student.h
#pragma once
#include
#include
#include
#include
#include
using namespace std;
typedef struct student
{
char name[20];
char sex;
int age;
float score;
int classNun;
struct student*next;
struct student*pre;
}STU, *pSTU;//pFind[100]用于查找个人信息的数组
//typedef struct pFstudent
//{
// char name[20];
// char sex;
// int age;
// float score;
// int classNun;
//}Find[100];
int load();
void meun();
void insertStudentdata(pSTU pHead);//插入学生信息
void showStudentdata(pSTU pHead);//显示学生信息
void searchStudentdata(pSTU pHead);//搜索学生信息
void showaftersdstudentdata(pSTU myList, int i);//显示要查询的学生信息
void deleteStudentdata(pSTU pHead);//删除学生信息
void sortStudentdata(pSTU pHead);//将各个学生的分数进行排序//按照分数的从小到大排序
void freeallStudentdata(pSTU pHead);//释放所有学生信息
student.cpp
#include"student.h"
int load()
{
char userName[20];
char password[20];//用户名自己输入的密码
char name[20], word[20];//文件读取的账号密码
FILE* fp = fopen("admin.txt", "r");
if (fp == NULL) return 0;//打开文件失败
while (1)
{
rewind(fp);//要将指针至于最头部
cout << "输入账号和密码" << endl;
cout << "账号:" << endl;
cin >> userName;
cout << "密码:" << endl;
cin >> password;
while (1)
{
fscanf(fp, "%s\t%s\n", name, word);//账户 密码
if (feof(fp)) break;//直接读到文件末尾,无须比较
if (strcmp(name, userName) == 0 && strcmp(word, password) == 0)
{
cout << "用户密码正确" << endl;
fclose(fp);
return 1;
}
//else
// return 0;
}
}
}
void meun()//菜单项
{
int choice;
pSTU pHead = (pSTU)malloc(sizeof(struct student));
pHead->pre = pHead;
pHead->next = pHead;
while (1)
{
system("cls");
cout << " -------------欢迎进入学生管理系统!---------------" << endl;
cout << " --------------1. 录入学生信息!-------------------" << endl;
cout << " --------------2. 查询学生信息!-------------------" << endl;
cout << " --------------3. 删除学生信息!-------------------" << endl;
cout << " --------------4. 打印学生信息!-------------------" << endl;
cout << " --------------5.将各个学生的分数进行排序!----------------" << endl;
cout << " --------------6.退出学生学生管理系统!----------------" << endl;
cout << "-----------------------------------请输入你要进行的操作-----------------"<< endl;
cin >> choice;
switch (choice)
{
case 1:insertStudentdata(pHead); break;
case 2:searchStudentdata(pHead); break;
case 3:deleteStudentdata(pHead); break;
case 4:showStudentdata(pHead); break;
case 5: sortStudentdata(pHead); break;
case 6:freeallStudentdata(pHead); return ;
default:cout << "输入有误,请重新输入" << endl; _sleep(1000); meun(); break; //如果出入错误,他就进入了死循环??
}
}
}
void insertStudentdata(pSTU pHead)
{
char choice;
//while (1)
//{
pSTU temp = (pSTU)malloc(sizeof(struct student));
cout << "请输入学生姓名:" << endl;
cin >> temp->name;
//getchar();
cout << "请输入学生性别:" << endl;
cin >> temp->sex;
//getchar();
cout << "请输入学生年龄:" << endl;
cin >> temp->age;
cout << "请输入学生分数:" << endl;
cin >> temp->score;
cout << "请输入学生班级:" << endl;
cin >> temp->classNun;
pHead->next->pre = temp;
temp->next = pHead->next;
pHead->next = temp;
temp->pre = pHead;
//cout << "是否想继续进行操作 y-确定,n-退出" << endl;
//cin >> choice;
/*switch (choice)
{
case 'y':insertStudentdata(pHead); break;
case 'n':meun(); return ;
}*/
//}
}
void showStudentdata(pSTU pHead)
{
cout << "学生信息具体如下:" << endl;
pSTU p = pHead->next;
while (p != pHead)
{
cout << "姓名:" << p->name << ' ' << "年龄:" << p->age << ' ' << "班级:" << p->classNun << ' ' << "分数:" << p->score << ' ' << "性别:" << p->sex << endl;
p = p->next;
}
_sleep(20000);
}
void searchStudentdata(pSTU pHead)
{
char searName[20]; int length = 0; pSTU myList[100];//顺序表//length 用于记录查询学生信息char ;char Find[100];
cout << "请输入你要查找人的姓名!" << endl;
cin >> searName;
pSTU pFind = pHead->next;
while (pFind != pHead)
{
if (strcmp(searName, pFind->name) == 0)
{
myList[length++] = pFind;//保留要找的地址
}
pFind = pFind->next;
}
if (length==0)
{
cout << "没有找到该人信息!" << endl;
_sleep(20000);
}
if (length > 0)
{
cout << "查询的结果如下:" << endl;
for (int j = 0; j < length; j++)
{
cout << "姓名:" << myList[j]->name << ' ' << "年龄:" << myList[j]->age << ' ' << "班级:" << myList[j]->classNun << ' ' << "分数:" << myList[j]->score << ' ' << "性别:" << myList[j]->sex << endl;
}
_sleep(20000);
//showaftersdstudentdata(pHead, length);//显示要查询的学生信息
}
}
void deleteStudentdata(pSTU pHead)
{
char deleName[20]; int length = 0; pSTU myList[100];
cout << "请选择你要选择删除的姓名" << endl;
cin >> deleName;
pSTU pFind = pHead->next;
while (pFind != pHead)
{
if (strcmp(deleName, pFind->name) == 0)
{
myList[length++] = pFind;//保留要找的地址
}
pFind = pFind->next;
}
if (length == 0)
{
cout << "没有找到该人信息!" << endl;
_sleep(20000);
}
if (length > 0)
{
cout << "查询的结果如下:" << endl;
for (int j = 0; j < length; j++)
{
cout << "姓名:" << myList[j]->name << ' ' << "年龄:" << myList[j]->age << ' ' << "班级:" << myList[j]->classNun << ' ' << "分数:" << myList[j]->score << ' ' << "性别:" << myList[j]->sex << endl << "编号" << j << endl;
}
_sleep(20000);
//showaftersdstudentdata(pHead, length);//显示要查询的学生信息
}
int choice;
cout << "请输入你要删除的接节点:" << endl;
cin >> choice;
if (choice < 0 || choice >= length)
{
cout << "输入有误" << endl;
_sleep(20000);
}
else
{
pSTU temp = myList[choice];
temp->next->pre = temp->pre;
temp->pre->next = temp->next;
free(temp);
}
}
void sortStudentdata(pSTU pHead)//按照分数的从小到大排序
{
cout << "正在排序,请稍后.......";
pSTU temp,exTemp;
for (pSTU psort = pHead->next; psort != pHead; psort = psort->next)//选择排序
{
temp = psort;
for (pSTU qsort = psort->next; qsort != pHead; qsort = qsort->next)
{
if (temp->score > qsort->score)
{
temp = qsort;
}
}
if (temp != psort)
{
strcpy(exTemp->name, temp->name);
exTemp->age = temp->age;
exTemp->classNun = temp->classNun;
exTemp->sex = temp->sex;
exTemp->score = temp->score;
}
}
_sleep(10000);
}
void freeallStudentdata(pSTU pHead)//释放所有学生信息
{
pSTU p = pHead->next;
pSTU q;
while(p!= pHead)
{
q = p->next;
free(p);
p = q;
}
free(pHead);
}
//void showaftersdstudentdata(pSTU myList, int length)
//{
// for (int j = 0; j < length; j++)
// {
// cout << "姓名:" << myList[j].name << ' ' << "年龄:" << myList[j].age << ' ' << "班级:" << myList[j].classNun << ' ' << "分数:" << myList[j].score << ' ' << "性别:" << myList[j].sex << endl;
// }
// _sleep(20000);
//}
//主函数
#include"student.h"
int main()
{
if (load() == 1)
{
meun();
}
while (1);
}