#include <iostream>
#include "main.h"
#include <string>
#include <sstream>
using namespace std;
extern Student *HEAD;
void main(){
HEAD = new Student;
HEAD->next = NULL;
MainInterfce();
FreeStudentList();
}
void MainInterfce(){
string inputStr;
do
{
cout << "===========主界面=================" << endl;
cout << "1、输入学生信息" << endl;
cout << "2、根据学生信息ID,查询学生信息" << endl;
cout << "3、输出所有学生信息" << endl;
cout << "4、根据学生信息ID,删除学生信息" << endl;
cout << "5、根据学生成绩,对学生信息降序排序" << endl;
cout << "6、退出本程序" << endl;
cout << "请输入功能号" << endl;
cout << "==================================" << endl;
cin >> inputStr;
stringstream str(inputStr);
int choice;
str >> choice;
switch (choice)
{
case 1:
InputStudent();
break;
case 2:
GetStudentInterface();
break;
case 3:
PrintAll();
break;
case 4:
DeleteStudentInterface();
break;
case 5:
SortByScore();
break;
default:
break;
}
} while (inputStr != "6");
cout << "本程序结束!" << endl;
}
void GetStudentInterface(){
string inputStr;
do
{
cout << "=========查询界面=================" << endl;
string str;
cout << "请输入要查询的学生学号:";
cin >> str;
Student *s = GetStudentById(str);
PrintStudent(s);
cout << "是否继续查询,输入Y继续" << endl;
cin >> inputStr;
} while (inputStr == "Y" || inputStr == "y");
cout << "==================================" << endl;
}
void DeleteStudentInterface(){
string inputStr;
do
{
cout << "=========删除界面=================" << endl;
string str;
cout << "请输入要删除的学生学号:";
cin >> str;
DeleteStudentById(str);
PrintAll();
cout << "是否继续删除,输入Y继续" << endl;
cin >> inputStr;
} while (inputStr == "Y" || inputStr == "y");
cout << "==================================" << endl;
}
//输入学生信息
void InputStudent(){
Student *stu;
string inputStr;
do
{
cout << "=========输入界面=================" << endl;
stu = new Student;
cout << "请输入学生的学号:";
cin >> stu->id;
cout << "请输入学生的姓名:";
cin >> stu->name;
cout << "请输入学生的成绩:";
cin >> stu->score;
stu->next = NULL;
AddStudent(stu);
cout << "\n是否继续输入,输入Y继续:";
cin >> inputStr;
} while (inputStr == "Y" || inputStr == "y");
cout << "==================================" << endl;
}
//输出单个学生的信息
void PrintStudent(Student *stuInfo){
if (stuInfo != NULL)
{
cout << "学号:" << stuInfo->id << " 姓名:" << stuInfo->name
<< " 成绩:" << stuInfo->score << endl;
}
}
//打印输出全部学生信息
void PrintAll(){
if (HEAD->next == NULL)
{
cout << "没有学生信息!" << endl;
return;
}
cout << "=========所有学生信息=============" << endl;
Student *p = HEAD->next;
do
{
cout << "学号:"<< p->id<< " 姓名:" << p->name <<" 成绩:" << p->score << endl;
p = p->next;
} while (p!=NULL);
cout << "==================================" << endl;
}