构建学生信息管理系统
#pragma once
#pragma once
#include<iostream>
#include<string.h>
using namespace std;
//学生特征的抽象
struct student
{
string name = "";
int age = NULL;
string sex = "";
int num = NULL;
string address = "";
long long int tel = NULL;
};
//定义结点
struct Node {
student data;
Node* next;
};
student createStu()
{
student stu;
cout << "请输入你要创建的学生的信息:"<<endl;
cout << "姓名 年龄 性别 学号 地址 电话"<<endl;
cin>> stu.name >> stu.age >> stu.sex >> stu.num >> stu.address >> stu.tel;
return stu;
}
//链表首个结点
Node* createList(student data)
{
Node* head = new Node;
head->data = data;
head->next = NULL;
return head;
};
//增
void insertNode(Node* head, student data)
{
Node* pNode = head;
Node* newNode = new Node;
newNode->data = data;
newNode->next = NULL;
while (pNode->next)
{
pNode = pNode->next;
}
pNode->next = newNode;
}
//删
void deleteAppinNode( Node* head, string name)
{
Node* posNode = head->next;
Node* posFrontNode = head;
if (posNode == NULL)
{
cout << "数据为空,无法删除" << endl;
return;
}
if (posFrontNode->data.name==name)
{
posFrontNode->data = posNode->data;
posFrontNode->next = posNode->next;
delete posNode;
cout << "成功删除!" << endl;
return;
}
while (posNode->data.name!= name)
{
posFrontNode = posNode;
posNode = posFrontNode->next;
if (posNode == NULL)
{
cout << "未找到指定位置,无法删除";
return;
}
}
posFrontNode->next = posNode->next;
delete posNode;
}
//改
void reviseNode(Node* head, string name)
{
Node* pNode = head;
while (pNode)
{
if (pNode->data.name == name)
{
cout << "请输入你修改后的信息" << endl;
cin>> pNode->data.name >> pNode->data.age >> pNode->data.sex >> pNode->data.num >> pNode->data.address >> pNode->data.tel;
return;
}
pNode = pNode->next;
}
cout << " not find";
return;
}
//查
void findNode(Node* head, string name)
{
Node* pNode = head;
while (pNode)
{
if (pNode->data.name == name)
{
cout << "找到的信息如下:"<<endl;
cout << pNode->data.name<<" " << pNode->data.age << " " << pNode->data.sex << " " << pNode->data.num << " " << pNode->data.address << " " << pNode->data.tel<<endl;
return;
}
pNode = pNode->next;
}
cout << "未能找到该学生的信息";
return;
}
//浏览
void outPut(Node* head)
{
Node* pNode = head;
head = head->next;
while (pNode)
{
static int flag = 1;
if (flag)
{
pNode = pNode->next;
flag = 0;
}
cout << pNode->data.name<<" " << pNode->data.age << " " << pNode->data.sex << " " << pNode->data.num << " " << pNode->data.address << " " << pNode->data.tel<<endl;
if (pNode->next)
{
cout << endl;
}
pNode = pNode->next;
}
}
#pragma once
#include <iostream>
using namespace std;
#include <Windows.h>
#include"myFunc.h"
#include"List.h"
#pragma warning (disable :4996)
student stuBegin = {};
extern Node* List = createList(stuBegin);
string user[10] = { "teacher" };//定义用户数组,便于添加管理员
void key1();
void key2();
void read(Node* head, const char* fileName)
{
FILE* fp;
student data;
fp = fopen(fileName, "r");
if (fp == NULL)
{
fp = fopen(fileName, "w+");
}
//读文件
while (fscanf(fp, "%s%d%s%d%s%d", data.name, data.age, data.sex, data.num, data.address, data.tel) != EOF);
{
insertNode(List, data);
}
fclose(fp);
}
void write(Node* head, const char* fileName)
{
FILE* fp;
student data;
fp = fopen(fileName, "w");
Node* pMove = head->next;
while (pMove);
{
fprintf(fp, "%s%d%s%d%s%d", pMove->data.name, pMove->data.age, pMove->data.sex, pMove->data.num, pMove->data.address, pMove->data.tel);
pMove = pMove->next;
}
fclose(fp);
}
//首页
void homeMenu()
{
cout << "\033[1m\033[5m################\033[0m*班级信息管理系统*\033[1m\033[5m###############\033[0m" << endl;
cout << "\033[1m\033[5m#\033[0m\t\t 0.信息浏览 \t\t\033[1m\033[5m#\033[0m" << endl;
cout << "\033[1m\033[5m#\033[0m\t\t 1.信息录入 \t\t\033[1m\033[5m#\033[0m" << endl;
cout << "\033[1m\033[5m#\033[0m\t\t 2.信息删除 \t\t\033[1m\033[5m#\033[0m" << endl;
cout << "\033[1m\033[5m#\033[0m\t\t 3.信息修改 \t\t\033[1m\033[5m#\033[0m" << endl;
cout << "\033[1m\033[5m#\033[0m\t\t 4.信息查找 \t\t\033[1m\033[5m#\033[0m" << endl;
cout << "\033[1m\033[5m#\033[0m\t\t 5.退出登录 \t\t\033[1m\033[5m#\033[0m" << endl;
cout << "\033[1m\033[5m#\033[0m\t\t 6.添加管理员用户 \t\t\033[1m\033[5m#\033[0m" << endl;
cout << "\033[1m\033[5m#\033[0m\t\t\t\t开发者:亢凯民 \033[1m\033[5m#\033[0m" << endl;
cout << "\033[1m\033[5m#\033[0m\t\t\t\t开发版本:1.0.0 \033[1m\033[5m#\033[0m" << endl;
cout << "\033[1m\033[5m################\033[0m*班级信息管理系统*\033[1m\033[5m###############\033[0m" << endl;
}
//子界面
void subMenu()
{
cout << "\033[1m\033[5m################\033[0m*班级信息管理系统*\033[1m\033[5m###############\033[0m" << endl;
cout << endl << endl;
cout << "\t\t 0.返回主页 \t\t" << endl;
cout << "\t\t 1.退出登录 \t\t" << endl;
cout << endl << endl;
cout << "\033[1m\033[5m################\033[0m*班级信息管理系统*\033[1m\033[5m###############\033[0m" << endl;
}
//休眠
void sleep(int time)
{
cout << "\t";
while(time)
{
Sleep(1000);
cout << time / 1000<<"......";
time = time - 1000;
}
cout << endl;
cout << "\a\a";
}
//登录
bool logIn()
{
string userName;
int passWord;
cout << "\t您现在正在登录亢凯民设计的班级信息管理系统" << endl;
cout << "\tEnter your identifying information:";
cin >> userName;
cout << "\tPlease enter password:";
cin >> passWord;
for (auto err : user)
{
if (userName == err && passWord == 123456)
{
return 1;
}
}
cout << "\t非管理人员,无法登录该系统!"<<endl;
cout << "\t正在返回......请重新登录!" << endl;
system("cls");
}
//过渡
void tranSit()
{
system("cls");
cout << "\t成功操作,正在打开界面,请勿关闭..." << endl;
sleep(3000);
system("cls");
}
//选择
void theChoice()
{
L1:
int choice;
cout << " Please enter the action you want to choose:"<<endl;
cin >> choice;
switch (choice)
{
case 6://添加管理员
{
string str;
cout << "Please enter the name of the administrator you want to add:" << endl;
cin >> str;
static int i = 0;
i++;
user[i] = str;
key2();
}
case 5://退出登录
{
tranSit();
system("cls");
key1();
}
case 4://查找学生
{
cout << "请输入你要查找的学生的姓名:";
string name;
cin >> name;
findNode(List, name);
system("pause");
key2();
}
case 3:
{
cout << "请输入你想要修改的学生的姓名!";
string name;
cin >> name;
reviseNode(List, name);
system("pause");
key2();
}
case 2:
{
cout << "请输入你想要删除的学生的姓名!";
string name;
cin >> name;
reviseNode(List, name);
system("pause");
key2();
}
case 1:
{
student stu = createStu();
insertNode(List, stu);
system("pause");
key2();
}
case 0:
{
outPut(List);
system("pause");
key2();
}
default ://重新选择
{
cout << "输入的操作数有误!";
system("cls");
goto L1;
}
}
write(List, "studentInformation.txt");
}
//主函数应该完成的任务
void key1()
{
if (logIn())
{
read(List, "studentInformation.txt");
tranSit();//过渡
homeMenu();//首页
theChoice();//选择
}
}
void key2()
{
tranSit();//过渡
homeMenu();//首页
theChoice();//选择
write(List, "studentInformation.txt");
}
void test()//测试用函数
{
student stu = createStu();
insertNode(List, stu);
findNode(List, "kang");
outPut(List);
}