📄 del.cpp
字号:
//删除数据
#include<iostream.h>
#include"main.h"
#include"classes.h"
void del()
{
int choice;
student st;
teacher te;
graduatestudent gr;
doctor dc;
char key[23];
cout<<"********** 删除 **********\n";
while(1)
{cout<<"请键入操作选择\n"
<<"1:按编号查找删除\t"
<<"0:退出\n";
cin>>choice;
switch(choice)
{
case 1: //按编号检索
{
cout<<"编号:\n?";
cin>>key;
fstream f;
fstream iof("student.dat",ios::binary|ios::in|ios::out);
f.seekg(0,ios::beg);
f.seekg(0, ios::end); // 读指针移到文件末尾
long posEnd=f.tellg(); // 记录文件尾位置
do
{
f.read((char*)&st,sizeof(250));
}
while(st.number!=key&&f.tellg()!=posEnd);
if(st.number==key)
cout<<st.number
<<'\t'<<st.idcard
<<'\t'<<st.name
<<'\t'<<st.sex
<<'\t'<<st.birthday
<<'\t'<<st.politics
<<'\t'<<st.marriage
<<'\t'<<st.knowledge
<<'\t'<<st.job
<<'\t'<<st.worktime
<<'\t'<<st.state
<<'\t'<<st.entertime
<<'\t'<<st.educationalsystem
<<'\t'<<st.institute
<<'\t'<<st.specialty
<<'\t'<<st.grade
<<'\t'<<st.theclass
<<'\t'<<st.theclass
<<endl;
else
{
cout<<"没有学生编号\n";
continue;
}
iof.close();
fstream iof1("teacher.dat",ios::binary|ios::in|ios::out);
f.seekg(0,ios::beg);
f.seekg(0, ios::end); // 读指针移到文件末尾
posEnd=f.tellg() ; // 记录文件尾位置
do
{
f.read((char*)&te,sizeof(240));
}
while(te.number!=key&&f.tellg()!=posEnd);
if(te.number==key)
cout<<te.number
<<'\t'<<te.idcard
<<'\t'<<te.name
<<'\t'<<te.sex
<<'\t'<<te.birthday
<<'\t'<<te.politics
<<'\t'<<te.marriage
<<'\t'<<te.knowledge
<<'\t'<<te.job
<<'\t'<<te.worktime
<<'\t'<<te.state
<<'\t'<<te.salary
<<'\t'<<te.cteacher
<<'\t'<<te.forclass
<<'\t'<<te.lesson
<<endl;
else
{
cout<<"没有教师编号\n";
continue;
}
iof1.close();
fstream iof2("graduatestudent.dat",ios::binary|ios::in|ios::out);
f.seekg(0,ios::beg);
f.seekg(0, ios::end); // 读指针移到文件末尾
posEnd=f.tellg() ; // 记录文件尾位置
do
{
f.read((char*)&gr,sizeof(290));
}
while(gr.number!=key&&f.tellg()!=posEnd);
if(gr.number==key)
cout<<gr.number
<<'\t'<<gr.idcard
<<'\t'<<gr.name
<<'\t'<<gr.sex
<<'\t'<<gr.birthday
<<'\t'<<gr.politics
<<'\t'<<gr.marriage
<<'\t'<<gr.knowledge
<<'\t'<<gr.job
<<'\t'<<gr.worktime
<<'\t'<<gr.state
<<'\t'<<gr.entertime
<<'\t'<<gr.educationalsystem
<<'\t'<<gr.institute
<<'\t'<<gr.specialty
<<'\t'<<gr.grade
<<'\t'<<gr.theclass
<<'\t'<<gr.cteacher
<<'\t'<<gr.forclass
<<'\t'<<gr.salary
<<endl;
else
{
cout<<"没有研究生编号\n";
continue;
}
iof2.close();
fstream iof3("doctor.dat",ios::binary|ios::in|ios::out);
f.seekg(0,ios::beg);
f.seekg(0, ios::end); // 读指针移到文件末尾
posEnd=f.tellg() ; // 记录文件尾位置
do
{
f.read((char*)&dc,sizeof(270));
}
while(dc.number!=key&&f.tellg()!=posEnd);
if(dc.number==key)
cout<<dc.number
<<'\t'<<dc.idcard
<<'\t'<<dc.name
<<'\t'<<dc.sex
<<'\t'<<dc.birthday
<<'\t'<<dc.politics
<<'\t'<<dc.marriage
<<'\t'<<dc.knowledge
<<'\t'<<dc.job
<<'\t'<<dc.worktime
<<'\t'<<dc.state
<<'\t'<<dc.salary
<<'\t'<<dc.forclass
<<'\t'<<dc.lesson
<<'\t'<<dc.treatment
<<endl;
else
{
cout<<"没有教授类编号\n";
continue;
}
iof3.close();
break;
}
case 0:return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -