#include "SeqList.h"
#include"menus.h"
FILE *stream;
int main()
{
char n='a';
SeqList temp;
menus();
cout<<"请选择功能(0--清屏)\t";
while(n!='9')
{
cin>>n;
switch ( n )
{
case '0':
{
system("cls");
menus();
break;
}
case '1' :
{
SeqList v;
cout<<"学生健康表(最多可存100人)已经生成了! ";
cout<<"请开始插入学生信息!\t"<<endl;
break;
}
case '2' :
{
int z;
T exp;
cout<<"你要插在第几位同学的后面呢?(范围0-"<<temp.Length()<< " ) ";
cin >> z ;
if(z < 0 || z > temp.Length () )
{
cout<<"你的输入不在0-"<<temp.Length()<< " 范围内,输入有误,请重新选择功能 "<<endl;
}
else
{
cout << " 请输入学号:"; cin >> exp.number;
cout << " 请输入姓名:"; cin >> exp.name;
cout << " 请输入出生(年:月:日) "; cin >> exp.dob;
cout << " 请输入性别(F/M):"; cin >> exp.sex;
cout << " 请输入生体状况:"; cin >> exp.condition;
temp.Insert(z,exp);
cout<<"******学生插入成功******"<<endl;
}
break ;
}
case '3' :
{
if(temp.Length()>0)
{
char z;
T exp;
cout<<"请输入你要删除的学生的学号:\t";
cin>> exp.number;
int i=temp.Search(exp);
if(temp.Search(exp)!=-1)
{
cout<<"*******你确定要删除"<<temp.data[i].name<<"吗?(确定y,取消n)******";
cin>>z;
if(z=='y')
{
temp.Remove(temp.Search(exp),exp);
cout<<"******该名学生已被删除。******"<<endl<<endl;
}
else
cout<<"学号"<<exp.number<<"的"<<temp.data[i].name<<"同学未被删除!";
}
else
cout<<"******该学号不存在!******"<<endl;
}
else
cout<<"健康表里空空如也,快去插入学生吧。"<<endl;
break;
}
case '4':
{
if(temp.Length()>0)
{
char z='a';
T exp;
cout<<"请输入你要修改的学生的学号:\t";
cin>> exp.number;
int i=temp.Search(exp);
if(i!=-1)
{
exp=temp.data[i];
while(z!='e')
{
cout<<"你要修改的是:"<<endl;
cout<<"学号(m),姓名(n),性别(s),出生日期(d),健康状况(c),结束(e)"<<endl;
cin>>z;
switch (z)
{
case 'm':
{
cout<<"请输入学号:";
cin>>exp.number;
break;
}
case 'n':
{
cout<<"请输入姓名:";
cin>>exp.name;
break;
}
case 'd':
{
cout<<"请输入出生日期(年/月/日):";
cin>>exp.dob;
break;
}
case 's':
{
cout<<"请输入性别:(F/M)";
cin>>exp.sex;
break;
}
case 'c':
{
cout<<"请输入健康状况:";
cin>>exp.condition;
break;
}
case 'e':
{break;}
default:
{
cout<<"输入有误!"<<endl;
break;
}
}
}
cout<<"*******你确定要修改"<<temp.data[i].name<<"吗?(确定y,取消n) ";
char k;
cin>>k;
if(k=='y') {temp.data[i]=exp;cout<<"修改成功。"<<endl;}
else cout<<"该生未被修改。"<<endl;
}
else
cout<<"******该学号不存在!******"<<endl;
}
else
cout<<"健康表里空空如也,快去插入学生吧。"<<endl;
break;
}
case '5':
{
if( (stream = fopen( "c:\\fread.txt", "r+t" )) != NULL )
{
int numread=0;
/* Attempt to read in 25 characters */
numread=fread( temp.data, sizeof( struct Student ), defaultSize, stream );
fclose( stream );
temp.last=numread-1;
cout<< "读取文件成功!"<< "读取学生" <<numread <<" 个!\n";
}
else
cout<< "由于某种原因,打不开文件\n" ;
break;
}
case '6':
{
if( (stream = fopen( "c:\\fread.txt", "w+t" )) != NULL )
{ int numwritten;
/* Write 25 characters to stream */
numwritten = fwrite( temp.data, sizeof( struct Student ), temp.Length(), stream );
cout<< "写入文件成功!"<<" 写入学生"<< numwritten <<"个!\n";
fclose( stream );
}
else
cout<< "由于某种原因,打不开文件\n";
break;
}
case '7':
{
T exp;
int i;
if(temp.Length()>0)
{
cout<<"请输入你要查找的学生的学号:\t";
cin>>exp.number;
if(temp.Search(exp)>-1)
{
i=temp.Search(exp);
cout << " 学号:"<<temp.data[i].number<<endl;
cout << " 姓名:"<< temp.data[i].name<<endl;
cout << " 出生(年/月/日) "<< temp.data[i].dob<<endl;
cout << " 性别:(F/M)"<<temp.data[i].sex<<endl;
cout << " 生体状况:"<< temp.data[i].condition<<endl;
}
else
cout << "学号为"<<exp.number<<"的学生未被录入系统"<<endl;
}
else
cout<<"健康表里空空如也,快去插入学生吧。"<<endl;
break;
}
case '8':
{
if(temp.Length()>0)
{
temp.Output();
}
else
cout<<"健康表里空空无也,快去插入学生吧。"<<endl;
break;}
case '9':
{ break;}
default:
{
cout<<"输入有误!"<<endl;
break;
}
}
cout<<"请选择功能(0--清屏)\t";
}
//getchar();
return 0;
}