1、题目 学生健康情况管理系统 【问题描述】 实现学生健康情况管理的几个操作功能(新建、插入、删除、从文件读取、写入文件和查询、屏幕输出等功能)。健康表中学生的信息有学号、姓名、出生日期、性别、身体状况等。 【实验内容】 必做内容 利用顺序存储结构来实现 系统的菜单功能项如下: 1------新建学生健康表 2------向学生健康表插入学生信息 3------在健康表删除学生信息 4------从文件中读取健康表信息 5------向文件写入学生健康表信息 6------在健康表中查询学生信息(按学生学号来进行查找) 7------在屏幕中输出全部学生信息
2、8-----退出
程序如下:
#include
3、 }; struct Sstudent //一个学生的基本信息 { char stuID[12]; //学号 char name[12]; //名字 struct birthday bd; //出生日期 char sex[4]; //性别 char healthcase[10]; //健康情况 Sstudent(){} void input(); //输入学生的基本信息 void output();
4、 //输出学生的基本信息
void operator =(Sstudent s);
bool operator < (Sstudent &s);
bool operator == (Sstudent s);
bool operator > (Sstudent &s);
};
void Sstudent::input() //输入一个学生的信息
{
cout<<"请输入学生信息:"<
5、ame;
cout<<"请输入学生的性别:";
cin>>sex;
cout<<"请输入学生生日的日期(年、月、日):";
cin>>bd.year>>bd.month>>bd.day;
cout<<"请输入学生的健康情况(良好或差):";
cin>>healthcase;
cout< 6、<<"生日: "< 7、);
}
bool Sstudent::operator < (Sstudent &s)
{
if(strcmp(stuID,s.stuID) == -1) //若number 小于 s.number
return true;
else
return false;
}
bool Sstudent::operator == (Sstudent s)
{
if( !strcmp(name,s.name) ) //若name 等于 s.number
if( !strcmp(stuID,s.stuID) ) 8、//若num 等于 s.number
return true;
return false;
}
bool Sstudent::operator > (Sstudent &s)
{
if(strcmp(stuID,s.stuID) == 1) //若number 大于 s.number
return true;
else
return false;
}
class Student
{
public:
Student();
Student(int sz); //构造函数
~Student(){}; 9、//析构函数
void makeEmpty(); //将数组置为空
void SetData(); //初步建立一个线性表
void Search(char ID[12]); //在健康表中查询学生信息(按学生学号来进行查找)
bool Insert(int i,Sstudent s); //向学生健康表插入学生信息
void Remove(int i, Sstudent& s); //在健康表删除学生信息
void Print(); //在屏幕中输出全部学生信息
void Write();
void ReadInsert(Sstude 10、nt s);
Student Read();
private:
Sstudent *stu;
int last;
int maxSize;
};
/*
* 构造函数,初始化数组
*/
Student::Student()
{
maxSize = 50;
last = -1;
stu = new Sstudent[maxSize];
if (stu == NULL)
{
cerr<<"存储分配错误"< 11、z > 0)
{
maxSize = sz;
last = -1;
stu = new Sstudent[maxSize];
if (stu == NULL)
{
cerr<<"存储分配错误"< 12、找)
在表中搜索学号为ID的学生信息,搜索成功返回该学生结点的地址,不成功返回NULL;
*/
void Student::Search(char ID[12])
{
for (int i = 0; i <= last; i++)
{
if (strcmp(ID,stu[i].stuID)==0)
{
stu[i].output();
return;
}
}
cout<<" 不存在此学生。"< 13、
{
int count;
cout<<" 输入学生的个数count = ";
cin>>count;
for (int i = 0; i < count; i++)
{
stu[i].input();
last++;
}
}
/*
* 向学生健康表插入学生信息
将新结点s插入在数组的第i个结点。
*/
bool Student::Insert(int i,Sstudent s)
{
if (last == maxSize -1)
{
cout<<" 表满!不能插入"< 14、 //插入不成功
}
if (i < 0 || i > last + 1)
{
cerr<<"参数i不合理,不能插入"< 15、emove(int i, Sstudent& s)
{
if (last == -1)
{
cerr<<"健康表为空,不能删除!!!"< 16、u[j];
}
last--;
}
/*
* 将健康表中所有的学生信息输出
*/
void Student::Print()
{
for (int i = 0; i <= last; i++)
{
stu[i].output();
}
}
/*
* 向文件写入学生健康表信息
*/
void Student::Write()
{
ofstream fop; //以二进制方式打开stu.txt文件
fop.open("stu.txt",ios::out|ios::binary|ios::trunc);
i 17、f(fop.fail()) //文件打开失败
{
cout<<"文件打开失败!"< 18、ream fip; //以二进制方式打开stu.txt文件
fip.open("stu.txt",ios::binary|ios::in);
if(fip.fail()) //文件打开失败
{
cout<<"文件打开失败!"< 19、fip)
{
break;
}
student.ReadInsert(s);
}
fip.close();
cout<<"读写成功"< 20、"< 21、来进行查找)"< 22、menu();
cout<<" 请输入你的选择(1~8):";
cin>>choose;
switch (choose)
{
case 1://新建学生健康表
student.SetData();
student.Print();
break;
case 2://向学生健康表插入学生信息
cout<<"在哪一个位置插入学生信息 i=?";
cin>>i;
student.Insert(i,s);
break;
case 3://在健康表删除学生信息
cout<<"删除第i个元素 i=? " 23、
cin>>i;
student.Remove(i,s);
break;
case 4://从文件中读取健康表信息
student = student.Read();
break;
case 5://向文件写入学生健康表信息
student.Write();
break;
case 6://在健康表中查询学生信息(按学生学号来进行查找)
cout<<"请输入查询学生的学号: ";
cin>>ID;
student.Search(ID);
break;
case 7://在屏幕中输出全部学生信息
student.Print();
break;
case 8://退出
exit(1);
break;
default:
cout<<"choose 输入错误!!!请重新输入choose :"<






