#include "T_List.h"
class Student:public Object
{
private:
char *Class; //班级
char *Num; //学号
char *Name; //姓名
char Sex; //性别
double Score; //学费
friend istream& operator>>(istream&,Student&); //重载插入符
public:
Student() //构造函数
{
Class=NULL;
Num=NULL;
Name=NULL;
Sex=0;
Score=0;
}
~Student() //析构函数
{
if(Class)delete[]Class;
if(Num) delete[]Num;
if(Name) delete[]Name;
}
double GetData(){return Score;} //获取成绩
void Show() //输出函数
{
cout<<setw(15)<<Class<<setw(15)<<Num<<setw(15)<<Name<<setw(10)<<Sex<<setw(10)<<Score<<endl;
}
int IsEqual(char tag,char *s) //信息对比
{
switch(tag){
case '1':{
return(strcmp(Num,s)==0); }break;
case '2':{
return(strcmp(Name,s)==0);}break;
default:return 0;break;
}
}
void Change(char tag) //修改函数
{
switch (tag)
{
case '1':{
cout<<"Please input the new Class:";
char temp[16];
cin>>temp;
delete[]Class;
Class=new char [strlen(temp)+1];
strcpy_s(Class,strlen(temp)+1,temp);
break;
}
case '2':{
cout<<"Please input the new Num:";
char temp[16];
cin>>temp;
delete[]Num;
Num=new char [strlen(temp)+1];
strcpy_s(Num,strlen(temp)+1,temp);
break;
}
case '3':{
cout<<"Please input the new Name:";
char temp[16];
cin>>temp;
delete[]Name;
Name=new char [strlen(temp)+1];
strcpy_s(Name,strlen(temp)+1,temp);
break;
}
case '4':{
cout<<"Please input the new Sex:";
char temp;
cin>>temp;
Sex=temp;
break;
}
case '5':{
cout<<"Please input the new Score:";
double temp;
cin>>temp;
Score=temp;
break;
}
default:break;
}
}
};
istream& operator>>(istream &in,Student &s)
{
in.get();
char str[81];
cout<<"Please input the Class:";
in.getline(str,81);
s.Class=new char [strlen(str)+1];
strcpy_s(s.Class,strlen(str)+1,str);
cout<<"Please input the Num:";
in.getline(str,81);
s.Num=new char [strlen(str)+1];
strcpy_s(s.Num,strlen(str)+1,str);
cout<<"Please input the Name:";
in.getline(str,81);
s.Name=new char [strlen(str)+1];
strcpy_s(s.Name,strlen(str)+1,str);
cout<<"Please input the Sex (F/M):";
in>>s.Sex;
cout<<"Please input the Score:";
in>>s.Score;
return in;
}
void Menu()
{
cout<<" - Student Management System Menu -"<<endl
<<" 1.Input Student Information."<<endl
<<" 2.Delete Student Information."<<endl
<<" 3.Search Student Information."<<endl
<<" 4.Change Student Information."<<endl
<<" 5.Output Student Information."<<endl
<<" 0.Esc."<<endl<<endl
<<"Please input your choose:";
}
void main()
{
Student *st; //学生指针
Node *pn; //结点指针
List StudentList;//构造学生信息链表
int choose; //用于菜单选择
char term; //用于判断是否折回重新录入查找信息
char tag; //修改类别标识符
char Isearch[21]; //用于储存查找信息
while(1)
{
Menu();
cin>>choose;
if(choose==1)
{
loop1: cout<<"Begin to Enter the Student Information:\n";
st=new Student();
cin>>*st;
pn = new Node;
pn->FillInfo(st);
StudentList.AddNode(pn); //增加节点
cout<<"Want to Enter New Student Information? (y/n)";
cin>>term;
if(term=='y'||term=='Y')
goto loop1;
else
system("cls");
}
if(choose==2)
{
if(StudentList.Getcount()==0){
cout<<"The StudentList have not Student."<<endl
<<"Press any key to continue.";
cin.get();cin.get();}
else{
loop2: cout<<"Please input the search type(1.use Num to Seach 2.use Name to Seach): ";
cin>>tag;
if(tag=='1'){
cout<<"Please input the Num of the Student:";
cin>>Isearch;
pn=StudentList.LookUp(tag,Isearch);}
else if(tag=='2'){
cout<<"Please input the Name of the Student:";
cin>>Isearch;
pn=StudentList.LookUp(tag,Isearch);}
else{
cout<<"Illegal input. Return to choose."<<endl;
goto loop2;}
if(pn){
cout<<"Find it, the student's Information:"<<endl;
cout<<setw(15)<<" Class"<<setw(15)<<" Num"<<setw(15)<<" Name"<<setw(10)<<" Sex"<<setw(10)<<"Score"<<endl;
pn->print();
cout<<"Sure you want to delete it ? (y/n): ";
cin>>term;
if(term=='y'||term=='Y'){
StudentList.DeleteNode(pn); // 删除节点
cout<<"Delete it now...";}
else
cout<<"Return to Menu...";
Sleep(1000);
}
else{
cout<<"Can't find the Student."<<endl
<<"Do you want to Reinput the Search Information? (y/n)";
cin>>term;
if(term=='y'||term=='Y')
goto loop2;
}
}
system("cls");
}
if(choose==3) //查找结点
{
if(StudentList.Getcount()==0){
cout<<"The StudentList have not Student."<<endl
<<"Press any key to continue.";
cin.get();cin.get();}
else{
loop3: cout<<"Please input the search type(1.use Num to Seach 2.use Name to Seach): ";
cin>>tag;
if(tag=='1'){
cout<<"Please input the Num of the Student:";
cin>>Isearch;
pn=StudentList.LookUp(tag,Isearch);}
else if(tag=='2'){
cout<<"Please input the Name of the Student:";
cin>>Isearch;
pn=StudentList.LookUp(tag,Isearch);}
else{
cout<<"Illegal input. Return to choose."<<endl;
goto loop3;}
if(pn){
cout<<"Find it, the Student's Information:"<<endl;
cout<<setw(15)<<" Class"<<setw(15)<<" Num"<<setw(15)<<" Name"<<setw(10)<<" Sex"<<setw(10)<<"Score"<<endl;
pn->print();
cout<<"Press any key to continue.";
cin.get();
cin.get();
}
else{
cout<<"Can't find the Student."<<endl
<<"Do you want to Reinput the Search Information? (y/n)";
cin>>term;
if(term=='y'||term=='Y')
goto loop3;
}
}
system("cls");
}
if(choose==4) //修改结点信息
{
if(StudentList.Getcount()==0)
cout<<"The StudentList have not Student."<<endl;
else{
loop4: cout<<"Please input the search type(1.use Num to Seach 2.use Name to Seach): ";
cin>>tag;
if(tag=='1'){
cout<<"Please input the Num of the Student:";
cin>>Isearch;
pn=StudentList.LookUp(tag,Isearch);}
else if(tag=='2'){
cout<<"Please input the Name of the Student:";
cin>>Isearch;
pn=StudentList.LookUp(tag,Isearch);}
else{
cout<<"Illegal input. Return to choose."<<endl;
goto loop4;}
if(pn){
cout<<"Find it, the Student's Information:"<<endl;
cout<<setw(15)<<" Class"<<setw(15)<<" Num"<<setw(15)<<" Name"<<setw(10)<<" Sex"<<setw(10)<<"Score"<<endl;
pn->print();
loop5: cout<<"Which Information want to change(1.Class 2.Num 3.Name 4.Sex 5.Score) : ";
cin>>tag;
pn->Change(tag);
cout<<"Finshed. Do you want to change other? (y/n)";
cin>>term;
if(term=='y'||term=='Y')
goto loop5;
else{
cout<<"Modify Succeed.The new Information:"<<endl;
cout<<setw(15)<<" Class"<<setw(15)<<" Num"<<setw(15)<<" Name"<<setw(10)<<" Sex"<<setw(10)<<"Score"<<endl;
pn->print();
}
}
else{
cout<<"Can't find the Student."<<endl
<<"Do you want to Reinput the Search Information? (y/n)";
cin>>term;
if(term=='y'||term=='Y')
goto loop4;
}
}
cout<<"Press any key to continue.";
cin.get();
cin.get();
system("cls");
}
if(choose==5) //输入线性表信息
{
cout<<"The StudentList have "<<StudentList.Getcount()<<" Student."<<endl;
cout<<setw(15)<<" Class"<<setw(15)<<" Num"<<setw(15)<<" Name"<<setw(10)<<" Sex"<<setw(10)<<"Score"<<endl;
StudentList.ShowList( );
cout<<"Press any key to continue.";
cin.get();
cin.get();
system("cls");
}
if(choose==0) //Esc
break;
}
}