1、实验目的
理解并掌握线性表的顺序实现算法和链式实现算法
2、实验内容(包括自己设计增加的内容等)
编写程序将线性表用顺序表和双链表实现创建、插入、删除、输出及排序等基本操作。
题目:
32、输入10个学生的信息,每个学生含有成员名为“学号、姓名、英语、 数学、政治、计算机、语文、历史、总分、平均分、名次”,分别编写六个函数求:
(1)输入一个学生的学号,查询该学生的信息并输出,若不存在显示没找到。
(2)输入一个学生的信息,将该学生信息进行添加。
(3)输入一个已存在学生的学号信息,删除该学生的信息后输出。
(4)求每个学生的总分、平均分并输出所有信息;
(5)求英语、数学、政治、计算机、语文、历史等课程的平均分并输出结果;
(6) 按总分从高到低求出每个学生的名次,(同分同名次,名次依次加1),完成后输出所有信息。
要求:
10个学生的数据用文件存储,每个学生的结构体用数组和单链表,首先建立一个具有10个学生数据的单链表或数组,并编写输出程序,然后程序执行后先显示“菜单”,当输入为0时,退出系统,当输入为1时,执行第(1)个函数;当输入为2时,执行第(2)个函数;当输入为3时,执行第(3)个函数;当输入为4时,执行第(4)个函数;当输入为5时,执行第(5)个函数;当输入为6时,执行第(6)个函数;当输入其他数字时,提示输入有错误。(自己补了:当输入7时,可以查看管理系统;当输入8时,可以导出管理系统;当输入9时,可以导入管理系统;当输入10时,可以清空管理系统)
接下来是用数组实现的源代码:
//第32题:学生管理系统__数组实现
//一、头文件 模块
#include <iostream> //C++标准库
#include <string> //字符串处理用到的头文件
#include <fstream> //文件处理用到的头文件
#include <iomanip> //用于小数位处理
using namespace std;
//定义学生管理系统能接纳的最大人数
#define MAX 100
//二、数据定义模块
class Student //定义学生的相关属性
{
public:
string name; //姓名
string ID; //学号
int eng; //英语
int math; //数学
int pol; //政治
int com; //计算机
int chi; //语文
int his; //历史
int sco; //总分
float avg; //平均分
int rank; //排名
};
class studentbook //定义学生管理系统相关属性
{
public:
Student studentarray[MAX]; //学生管理系统中保存的学生数组
int size; //学生管理系统中学生个数
};
//三、函数声明模块
void menu(); //查看菜单
//(0)退出管理系统
void end();
//(1)输入一个学生的学号,查询该学生的信息并输出,若不存在显示没找到。
int IDfind(studentbook* abs);
//(2)输入一个学生的信息,将该学生信息作为第五个记录信息插入后输出。
void addStudent(studentbook* abs);
//(3)输入一个已存在学生的学号信息,删除该学生的信息后输出。
void deleteStudent(studentbook* abs);
//(4)求每个学生的总分、平均分并输出所有信息;
void scoreStudent(studentbook* abs);
//(5)求英语、数学、政治、计算机、语文、历史等课程的平均分并输出结果;
void avgClass(studentbook* abs);
//(6)按总分从高到低求出每个学生的名次,(同分同名次,名次依次加1),完成后输出所有信息。
void ranking(studentbook* abs);
//(7)查看管理系统
void showStudent(const studentbook* abs);
//(8)导出管理系统
void ofstudentbook(const studentbook* abs);
//(9)导入管理系统
void ifstudentbook(studentbook* abs);
//(10)清空管理系统
void cleanStudent(studentbook* abs);
//四、主函数模块
int main()
{
int select;//定义选择的操作
studentbook abs;//定义指针->addressbook类型
abs.size = 0;//设置size初始值为0
while (true)
{
cout << endl;
menu(); //展示菜单
//输入对应操作
cout << "请输入对应序号:";
cin >> select;
//根据输入序号对应到哪一步操作
switch (select)
{
case 0: //退出管理系统
end();
break;
case 1: //输出学生信息
IDfind(&abs);
break;
case 2: //添加学生信息
addStudent(&abs);
break;
case 3: //删除学生信息
deleteStudent(&abs);
break;
case 4: //求总分、平均分
scoreStudent(&abs);
break;
case 5: //求课程平均分
avgClass(&abs);
break;
case 6: //学生名次
ranking(&abs);
break;
case 7: //查看管理系统
showStudent(&abs);
break;
case 8: //导出管理系统
ofstudentbook(&abs);
break;
case 9: //导入管理系统
ifstudentbook(&abs);
break;
case 10://清空管理系统
cleanStudent(&abs);
break;
default:
cout<<"请重新输入:"<<endl;
continue;
}
}
return 0;
}
//函数实现模块
//查看菜单->函数
void menu()
{
system("cls");
cout << "***************" << endl;
cout << "0. 退出管理系统" << endl;
cout << "1. 查询学生信息" << endl;
cout << "2. 添加学生信息" << endl;
cout << "3. 删除学生信息" << endl;
cout << "4. 总分、平均分" << endl;
cout << "5. 求课程平均分" << endl;
cout << "6. 输出学生名次" << endl;
cout << "7. 查看管理系统" << endl;
cout << "8. 导出管理系统" << endl;
cout << "9. 导入管理系统" << endl;
cout << "10.清空管理系统" << endl;
cout << "***************" << endl;
}
//0:退出管理系统->函数
void end()
{
cout << "欢迎下次使用!" << endl;
exit(0); //退出程序
}
//1.通过学号查找学生信息
int IDfind(studentbook* abs)
{
string ID; //定义查找的学号
cout << "请输入查找学生的学号:" ;
cin >> ID; //输入查找的学号
for (int i=0; i< abs->size; i++) //借助for循环,寻找需要查找的学生
{
//借助compare函数,如果两个字符串的compare==0,则返回编号
if (ID.compare(abs->studentarray[i].ID) == 0)
{
cout<<endl;
cout<<"查询结果如下:"<<endl;
cout<<"姓名:"<<abs->studentarray[i].name<<" 英语:"<<abs->studentarray[i].eng<<" 数学:"<<abs->studentarray[i].math<<" 政治:"<<abs->studentarray[i].pol<<" 计算机:"<<abs->studentarray[i].com<<" 语文:"<<abs->studentarray[i].chi<<" 历史:"<<abs->studentarray[i].his;
}
}
cout<<endl;
system("pause");
}
//2.添加学生信息->函数
void addStudent(studentbook* abs)
{
//判断管理系统人数是否已满,若已满则不进行添加
if (abs->size >= MAX)
{
cout << "管理系统人数已满" << endl;
}
else
{
cout << "请输入姓名:";
cin >> abs->studentarray[abs->size].name;
cout << "请输入学号:";
cin >> abs->studentarray[abs->size].ID;
cout << "请输入英语成绩:";
cin >> abs->studentarray[abs->size].eng;
cout << "请输入数学成绩:";
cin >> abs->studentarray[abs->size].math;
cout << "请输入政治成绩:";
cin >> abs->studentarray[abs->size].pol;
cout << "请输入计算机成绩:";
cin >> abs->studentarray[abs->size].com;
cout << "请输入语文成绩:";
cin >> abs->studentarray[abs->size].chi;
cout << "请输入历史成绩:";
cin >> abs->studentarray[abs->size].his;
abs->size++;//abs指向size后,size再加一
cout << "学生信息添加成功" << endl;
}
system("pause");
}
//3.删除学生信息->函数
void deleteStudent(studentbook* abs)
{
int n;
string ID; //定义查找的学号
cout << "请输入删除学生的学号:" << endl;
cin >> ID; //输入查找的学号
for (int i=0; i<abs->size; i++) //借助for循环,寻找需要查找的学生
{
//借助compare函数,如果两个字符串的compare==0,则返回编号
if (ID.compare(abs->studentarray[i].ID) == 0)
{n=i;break;}
else {n=-1;}
}
//判断是否查找正确,正确则对应personarray中的第几个,错误则n为-1
if (n!=-1)
{
abs->studentarray[n] = abs->studentarray[abs->size-1]; //拿最后一个去替换掉将删除的联系人
abs->size--; //通讯录人数-1
cout << "删除成功" << endl;
}
else
{
cout << "查无此人" << endl;
}
system("pause");
}
//4.求总分、平均值
void scoreStudent(studentbook* abs)
{
for (int i = 0; i < abs->size; i++)
{
//计算总成绩
abs->studentarray[i].sco=abs->studentarray[i].eng+abs->studentarray[i].math+abs->studentarray[i].pol+abs->studentarray[i].com+abs->studentarray[i].chi+abs->studentarray[i].his;
//计算平均值
abs->studentarray[i].avg=abs->studentarray[i].sco/6.0;
cout<<abs->studentarray[i].name<<"的总分为:"<<abs->studentarray[i].sco<<"\t平均分为:"<<setprecision(4)<<abs->studentarray[i].avg<<endl;
}
system("pause");
}
//5.课程平均分
void avgClass(studentbook* abs)
{
float avg_eng=0,avg_math=0,avg_pol=0,avg_com=0,avg_chi=0,avg_his=0;
int num=0;
for (int i = 0; i < abs->size; i++)
{
avg_eng=avg_eng+abs->studentarray[i].eng;
num=num+1;
}
avg_eng=avg_eng/num;
cout<<"英语学科平均分为:"<<avg_eng<<endl;
for (int i = 0; i < abs->size; i++)
{
avg_math=avg_math+abs->studentarray[i].math;
}
avg_math=avg_math/num;
cout<<"数学学科平均分为:"<<avg_math<<endl;
for (int i = 0; i < abs->size; i++)
{
avg_pol=avg_pol+abs->studentarray[i].pol;
}
avg_pol=avg_pol/num;
cout<<"政治学科平均分为:"<<avg_pol<<endl;
for (int i = 0; i < abs->size; i++)
{
avg_com=avg_com+abs->studentarray[i].com;
}
avg_com=avg_com/num;
cout<<"计算机学科平均分为:"<<avg_com<<endl;
for (int i = 0; i < abs->size; i++)
{
avg_chi=avg_chi+abs->studentarray[i].chi;
}
avg_chi=avg_chi/num;
cout<<"语文学科平均分为:"<<avg_chi<<endl;
for (int i = 0; i < abs->size; i++)
{
avg_his=avg_his+abs->studentarray[i].his;
}
avg_his=avg_his/num;
cout<<"历史学科平均分为:"<<avg_his<<endl;
system("pause");
}
//6.学生名次排名
void ranking(studentbook* abs)
{
// 用冒泡排序按总分从高到低排序
for (int i = 0; i < abs->size - 1; i++) {
for (int j = 0; j < abs->size - i - 1; j++) {
if (abs->studentarray[j].sco < abs->studentarray[j + 1].sco) {
Student temp = abs->studentarray[j];
abs->studentarray[j] = abs->studentarray[j + 1];
abs->studentarray[j + 1] = temp;
}
}
}
// 计算排名
for (int i = 0; i < abs->size; i++) {
abs->studentarray[i].rank = i + 1;
cout<<abs->studentarray[i].name<<"的排名为:"<<abs->studentarray[i].rank<<"\t";
if(i==abs->size/2-1) {cout<<endl;}
}
cout<<endl;
system("pause");
}
//7.查看管理系统->函数
void showStudent(const studentbook* abs)
{
if (abs->size) //判断人数是否为零
{
//借助for循环,逐个输出学生的相关信息
for (int i = 0; i < abs->size; i++)
{
cout<< "姓名:" << abs->studentarray[i].name
<< "\t学号:" << abs->studentarray[i].ID
<< "\t\t英语:" << abs->studentarray[i].eng
<< "\t数学:" << abs->studentarray[i].math
<< "\t政治:" << abs->studentarray[i].pol
<< "\t计算机:" << abs->studentarray[i].com
<< "\t语文:" << abs->studentarray[i].chi
<< "\t历史:" << abs->studentarray[i].his
<< endl;
}
}
else
{
//如果人数为0则输出学生管理系统为空
cout << "学生管理系统为空" << endl;
}
system("pause");
}
//8.导出学生管理系统->函数
void ofstudentbook(const studentbook* abs)
{
ofstream ofs;//使用了 ofstream 类型的对象 ofs
ofs.open("学生管理系统.txt", ios::out); //打开文件,并使用 ios::out 模式输出数据
ofs << "姓名\t\t学号\t\t英语\t\t数学\t\t政治\t\t计算机\t\t语文\t\t历史" << endl;
for (int i = 0; i < abs->size; i++)
{
ofs << abs->studentarray[i].name
<< "\t\t" << abs->studentarray[i].ID
<< "\t" << abs->studentarray[i].eng
<< "\t\t" << abs->studentarray[i].math
<< "\t\t" << abs->studentarray[i].pol
<< "\t\t" << abs->studentarray[i].com
<< "\t\t" << abs->studentarray[i].chi
<< "\t\t" << abs->studentarray[i].his
<< endl; //通过 ofs 对象进行数据的写入
}
ofs.close(); //关闭文件
cout << "导出学生管理系统成功" << endl;
system("pause");
}
//9.导入管理系统->函数
void ifstudentbook(studentbook* abs)
{
string temp;
ifstream ifs; //使用了 ifstream 类型的对象 ifs
ifs.open("学生管理系统.txt", ios::in); //打开文件,以 ios::in 模式打开一个名为“学生管理系统.txt”的文件
if (ifs.is_open())
{
getline(ifs, temp); //将文件上方的标签输入到临时字符串
while (ifs >> abs->studentarray[abs->size].name >>abs->studentarray[abs->size].ID >>abs->studentarray[abs->size].eng >>abs->studentarray[abs->size].math >>abs->studentarray[abs->size].pol >>abs->studentarray[abs->size].com >>abs->studentarray[abs->size].chi >>abs->studentarray[abs->size].his)
{
abs->size++; //人数+1
}
ifs.close(); //关闭文件
cout << "导入学生管理系统成功" << endl;
}
else
{
cout << "文件打开失败" << endl;
}
system("pause");
}
//10.清空管理系统->函数
void cleanStudent(studentbook* abs)
{
abs->size = 0; //将管理系统清空
cout << "管理系统已清空" << endl;
system("pause");
}
接下来是用链表实现的源代码:
//第32题:学生管理系统__链表实现
//一、头文件 模块
#include <iostream> //C++标准库
#include <string> //字符串处理用到的头文件
#include <fstream> //文件处理用到的头文件
#include <iomanip> //用于小数位处理 #include <iostream>
using namespace std;
#define MAX 100
//二、类的定义
//定义类-学生
class Student {
public:
string name;
string ID;
int eng;
int math;
int pol;
int com;
int chi;
int his;
int sco;
float avg;
int rank;
};
//定义一个结点
class Node {
public:
Student data;
Node* next;
};
//定义类-学生通讯录
class studentbook {
public:
Node* head;
int size;
};
//三、函数声明模块
void menu(); //查看菜单
//(0)退出管理系统
void end();
//(1)输入一个学生的学号,查询该学生的信息并输出,若不存在显示没找到。
int IDfind(studentbook* abs);
//(2)输入一个学生的信息,将该学生信息作为第五个记录信息插入后输出。
void addStudent(studentbook* abs);
//(3)输入一个已存在学生的学号信息,删除该学生的信息后输出。
void delStudent(studentbook* abs);
//(4)求每个学生的总分、平均分并输出所有信息;
void calScore(studentbook* abs);
//(5)求英语、数学、政治、计算机、语文、历史等课程的平均分并输出结果;
void calSubjectAvg(studentbook* abs);
//(6)按总分从高到低求出每个学生的名次,(同分同名次,名次依次加1),完成后输出所有信息。
void calRank(studentbook* abs);
//(7)查看管理系统
void printAll(studentbook* abs);
//(8)导出管理系统
void ofstudentbook(const studentbook* abs);
//(9)导入管理系统
void ifstudentbook(studentbook* abs);
//(10)清空管理系统
void cleanStudent(studentbook* abs);
//主函数模块
int main()
{
studentbook stuBook;
stuBook.head = NULL;
stuBook.size = 0;
int choice = 0;
do
{
menu();
cout << "请输入您的选择:";
cin >> choice;
switch (choice)
{
case 0: end(); break;
case 1: IDfind(&stuBook); break;
case 2: addStudent(&stuBook); break;
case 3: delStudent(&stuBook); break;
case 4: calScore(&stuBook); break;
case 5: calSubjectAvg(&stuBook) ; break;
case 6: calRank(&stuBook); break;
case 7: printAll(&stuBook); break;
case 8: ofstudentbook(&stuBook); break;
case 9: ifstudentbook(&stuBook); break;
case 10: cleanStudent(&stuBook); break;
default: cout << "输入有误,请重新输入!" << endl; break;
}
}
while (choice != 0);
}
//查看菜单->函数
void menu()
{
system("cls");
cout << "***************" << endl;
cout << "0. 退出管理系统" << endl;
cout << "1. 查询学生信息" << endl;
cout << "2. 添加学生信息" << endl;
cout << "3. 删除学生信息" << endl;
cout << "4. 总分、平均分" << endl;
cout << "5. 求课程平均分" << endl;
cout << "6. 输出学生名次" << endl;
cout << "7. 查看管理系统" << endl;
cout << "8. 导出管理系统" << endl;
cout << "9. 导入管理系统" << endl;
cout << "10.清空管理系统" << endl;
cout << "***************" << endl;
}
//0.退出管理系统
void end() {
cout << "欢迎下次使用!" << endl;
system("pause");
exit(0);
}
//1.查询学生信息
int IDfind(studentbook* abs)
{
Node* p = abs->head;
string ID;
cout << "请输入学生的学号:";
cin >> ID;
bool found = false; // 用于标记是否找到了学生信息
while (p != NULL) {
if (p->data.ID == ID) {
cout << "姓名:" << p->data.name << "\t";
cout << "英语:" << p->data.eng << "\t";
cout << "数学:" << p->data.math << "\t";
cout << "政治:" << p->data.pol << "\t";
cout << "计算机:" << p->data.com << "\t";
cout << "语文:" << p->data.chi << "\t";
cout << "历史:" << p->data.his << endl;
found = true; // 标记找到了学生信息
break; // 跳出循环
}
p = p->next;
}
if (!found) { // 如果没有找到学生信息
cout << "没找到该学生信息" << endl;
}
system("pause");
return 0;
}
//2.添加学生信息
void addStudent(studentbook* abs)
{
Node* p = abs->head;
Student stu;
cout << "请输入学生的姓名:";
cin >> stu.name;
cout << "请输入学生的学号:";
cin >> stu.ID;
cout << "请输入学生的英语成绩:";
cin >> stu.eng;
cout << "请输入学生的数学成绩:";
cin >> stu.math;
cout << "请输入学生的政治成绩:";
cin >> stu.pol;
cout << "请输入学生的计算机成绩:";
cin >> stu.com;
cout << "请输入学生的语文成绩:";
cin >> stu.chi;
cout << "请输入学生的历史成绩:";
cin >> stu.his;
stu.sco = stu.eng + stu.math + stu.pol + stu.com + stu.chi + stu.his;
stu.avg = stu.sco / 6.0;
Node* newNode = new Node();
newNode->data = stu;
newNode->next = NULL;
if (abs->head == NULL) {
abs->head = newNode;
abs->size++;
return;
}
while (p != NULL && p->next != NULL && p->next->data.sco > stu.sco)
{
p = p->next;
}
newNode->next = p->next;
p->next = newNode;
abs->size++;
system("pause");
}
//3.删除学生信息
void delStudent(studentbook* abs)
{
Node* p = abs->head;
string ID;
cout << "请输入要删除的学生学号:";
cin >> ID;
while (p != NULL && p->data.ID != ID) {
p = p->next;
}
if (p == NULL) {
cout << "没找到该学生信息" << endl;
system("pause");
return;
}
Node* q = p->next;
if (p == abs->head) { // 如果要删除的节点是头节点
abs->head = q; // 将头节点指向下一个节点
} else { // 如果要删除的节点不是头节点
Node* prev = abs->head;
while (prev != NULL && prev->next != p) {
prev = prev->next;
}
if (prev != NULL) { // 找到要删除节点的前一个节点
prev->next = q; // 将前一个节点的指针指向下一个节点
}
}
abs->size--;
delete p;
cout << "删除成功!" << endl;
system("pause");
}
//4.求总分和平均分
void calScore(studentbook* abs)
{
Node* p = abs->head;
while (p != NULL)
{
p->data.sco = p->data.eng + p->data.math + p->data.pol + p->data.com + p->data.chi + p->data.his;
p->data.avg = p->data.sco / 6.0;
p = p->next;
}
p = abs->head;
while (p != NULL)
{
cout << p->data.name << "的总分为:" << p->data.sco << "\t\t" << "平均分为:" << setprecision(4)<<p->data.avg<<endl;
p = p->next;
}
system("pause");
}
//5.求各个学科平均分
void calSubjectAvg(studentbook* abs)
{
double eng_avg = 0, math_avg = 0, pol_avg = 0, com_avg = 0, chi_avg = 0, his_avg = 0;
int count = 0;
Node* p = abs->head;
while (p != NULL) {
eng_avg += p->data.eng;
math_avg += p->data.math;
pol_avg += p->data.pol;
com_avg += p->data.com;
chi_avg += p->data.chi;
his_avg += p->data.his;
count++;
p = p->next;
}
eng_avg /= count;
math_avg /= count;
pol_avg /= count;
com_avg /= count;
chi_avg /= count;
his_avg /= count;
cout << "英语的平均分为:" <<setprecision(4)<< eng_avg << endl;
cout << "数学的平均分为:" << setprecision(4)<< math_avg << endl;
cout << "政治的平均分为:" <<setprecision(4)<< pol_avg << endl;
cout << "计算机平均分为:" <<setprecision(4)<< com_avg << endl;
cout << "语文的平均分为:" <<setprecision(4)<< chi_avg << endl;
cout << "历史的平均分为:" <<setprecision(4)<< his_avg << endl;
system("pause");
}
//6. 求排名
void calRank(studentbook* abs)
{
Node* p = abs->head;
double max_score = 0; // 用于跟踪最高总分
while (p != NULL) {
max_score = max(max_score, static_cast<double>(p->data.sco)); // 将sco转换为double类型,然后更新最高总分
p = p->next;
}
p = abs->head;
while (p != NULL) {
p->data.rank = 1; // 初始化排名为1
Node* q = abs->head;
while (q != NULL) {
if (q != p && static_cast<double>(q->data.sco) > p->data.sco) { // 将q的sco转换为double类型,然后比较两个double类型的值
p->data.rank++; // p的排名加一
}
q = q->next;
}
cout << p->data.name << "的排名为:" << p->data.rank << "\t" << "总分为:" << p->data.sco << endl; // 打印排名和总分
p = p->next;
}
system("pause");
}
//7.查看管理系统
void printAll(studentbook* abs)
{
if (abs->head == NULL)
{
cout << "学生管理系统为空" << endl;
system("pause");
return;
}
Node* p = abs->head;
while (p != NULL) {
cout << "姓名:" << p->data.name << "\t\t";
cout << "学号:" << p->data.ID << "\t";
cout << "英语:" << p->data.eng << "\t";
cout << "数学:" << p->data.math << "\t";
cout << "政治:" << p->data.pol << "\t";
cout << "计算机:" << p->data.com << "\t";
cout << "语文:" << p->data.chi << "\t";
cout << "历史:" << p->data.his << endl;
p = p->next;
}
system("pause");
}
//8.导出学生管理系统
void ofstudentbook(const studentbook* abs)
{
studentbook stuBook;
ofstream outfile;
outfile.open("学生管理系统2.txt", ios::out);
Node* p = abs->head;
outfile << "姓名\t\t学号\t\t英语\t\t数学\t\t政治\t\t计算机\t\t语文\t\t历史" << endl;
while (p != NULL) {
outfile << p->data.name
<< "\t\t" << p->data.ID
<< "\t\t" << p->data.eng
<< "\t\t" << p->data.math
<< "\t\t" << p->data.pol
<< "\t\t" << p->data.com
<< "\t\t" << p->data.chi
<< "\t\t" << p->data.his
<< endl; //通过 ofs 对象进行数据的写入
p = p->next;
}
outfile.close(); //关闭文件
cout << "导出成功!" << endl;
system("pause");
}
//9.导入学生管理系统
void ifstudentbook(studentbook* abs)
{
string temp;
ifstream ifs; //使用了 ifstream 类型的对象 ifs
ifs.open("学生管理系统2.txt", ios::in); //打开文件,以 ios::in 模式打开一个名为“学生管理系统.txt”的文件
if (ifs.is_open())
{
getline(ifs, temp); //将文件上方的标签输入到临时字符串
Student stu;
while (ifs >> stu.name >> stu.ID >> stu.eng >> stu.math >> stu.pol >> stu.com >> stu.chi >> stu.his)
{
Node* newNode = new Node(); //创建新结点
newNode->data = stu;
newNode->next = abs->head;
abs->head = newNode;
abs->size++;
}
ifs.close(); //关闭文件
cout << "导入学生管理系统成功" << endl;
}
else
{
cout << "文件打开失败" << endl;
}
system("pause");
}
//10.清空学生管理系统
void cleanStudent(studentbook* abs)
{
studentbook stuBook;
Node* p = abs->head;
while (p != NULL)
{
Node* q = p->next;
delete p;
p = q;
}
abs->head = NULL;
abs->size = 0;
cout << "清空成功!" << endl;
system("pause");
}
由于运行结果图实在太多啦!请自行运行
Tips:请自行创建“学生管理系统.txt”文件和“学生管理系统2.txt”