# include & ltfstream.h & gt
# include & ltiomanip.h & gt
Static int n = 0;;
int comp(char*,char *);
Class students
{
Public:
void getdata()
{
tag = ' #
Cout & lt& lt "(name, ID number, class score):";
CIN & gt; & gt name & gt& gt number & gt& gtClass & gt& gt score;
}
char gettag()
{
Return label;
}
Invalid display ()
{
if(tag=='# ')
cout & lt& ltsetiosflags(ios::left)
& lt& ltsetw( 10)& lt; & lt name & lt setw (18) < & lt number & lt setw (20) < & ltClass & lt& ltsetw(20)& lt; & lt score & lt& ltendl
}
char *getname()
{
Returns the name;
}
Private:
Char tag;
Character name [12];
Character number [18];
Char class [20];
char score[6];
};
class?teacher/head?teacher
{
Public:
void getdata()
{
tag = ' #
Cout & lt& lt "(name, ID number, professional title college):";
CIN & gt; & gt name & gt& gtNo.>& gt Chen Zhi>& gt Xueyuan;
}
char gettag()
{
Return label;
}
Invalid display ()
{
if(tag=='# ')
cout & lt& ltsetiosflags(ios::left)
& lt& ltsetw( 10)& lt; & lt name & lt setw (18) < & lt number & lt setw (20) < < Chen Zhi < < setw (20) <; & lt snowfield & lt& ltendl
}
char *getname()
{
Returns the name;
}
Private:
Char tag;
Character name [12];
Character number [18];
Charles Chen Zhi [20];
Cha Xueyuan [30];
};
Class students and teachers
{
Public:
void getdata()
{
tag = ' #
Cout & lt& lt "(name, ID number, class score, professional title institution):";
CIN & gt; & gt name & gt& gt number & gt& gtClass & gt& gt score & gt& gt Chen Zhi>& gt Xueyuan;
}
char gettag()
{
Return label;
}
Invalid display ()
{
if(tag=='# ')
cout & lt& ltsetiosflags(ios::left)
& lt& ltsetw( 10)& lt; & lt name & lt setw (18) < & lt number & lt setw (20) < & ltClass & lt& ltsetw(20)& lt; < lt score < lt setw (20) < < Chen Zhi < < setw (20) <; & lt snowfield & lt& ltendl
}
char *getname()
{
Returns the name;
}
Private:
Char tag;
Character name [12];
Character number [18];
Char class [20];
Double integral;
Charles Chen Zhi [20];
Cha Xueyuan [30];
};
void func 1()
{
Ofstream output ("myfrd.dat");
Student s;
Cout & lt& lt "input data"
Cout & lt& lt "Number of students:";
CIN & gt; & gtn;
for(int I = 0; I & ltn;; i++)
{
Cout & lt& lt "first"
s . get data();
output . write((char *)& amp; s,sizeof(s));
};
output . close();
}
void func2()
{
ifstream input(" my frd . dat ");
Student s;
Cout & lt& lt "output data"
cout & lt& ltsetiosflags(ios::left)
& lt& ltsetw( 10)& lt; & lt "Name"
input . read((char *)& amp; s,sizeof(s));
While (input)
{
s . disp();
input . read((char *)& amp; s,sizeof(s));
};
input . close();
}
void func3()
{
char sname[ 10];
Ifstream file ("myfrd.dat");
Student one;
file . seekg(0);
Cout & lt& lt "Enter the name to query (only last name can be entered):";
CIN & gt; & gtsname
Cout & lt& lt "Output query results:"
cout & lt& ltsetiosflags(ios::left)
& lt& ltsetw( 10)& lt; & lt "Name"
file . read((char *)& amp; First, sizeof(one)););
While (file)
{
if(comp(one.getname(),sname)== 1)
one . disp();
file . read((char *)& amp; First, sizeof(one)););
};
file . close();
}
void func4()
{
fstream outapp("MyFrd.dat ",IOs::app);
Student one;
Cout < < "Add data:";
one . get data();
out app . write((char *)& amp; First, sizeof(one)););
out app . close();
}
void func5()
{
char sname[ 12];
int I = 0;
fstream outdel("MyFrd.dat ",IOs::in | IOs::out);
Student one;
outdel . seekg(0);
Cout & lt& lt "Enter the name to be deleted (only last name can be entered):";
CIN & gt; & gtsname
And (! outdel.eof())
{
outdel . seekp(sizeof(student)* I);
outdel . read((char *)& amp; First, sizeof(one)););
if(comp(one.getname(),sname)= = 1 & amp; & ampone.gettag()=='# ')
{
outdel . seekp(sizeof(student)* I);
outdel . put(' * ');
}
i++;
}
outdel . close();
}
void func6()
{
fstream outdel("student.dat ",IOs::in);
fstream temp("temp ",IOs::out | IOs::trunc);
Student s;
And (! outdel.eof())
{
outdel . read((char *)& amp; S, sizeof (student));
if(s.gettag()=='# ')
temp . write((char *)& amp; S, sizeof (student));
}
outdel . close();
temp . close();
fstream outdel 1(" my frd . dat ",IOs::out | IOs::trunc);
fstream temp 1("temp ",IOs::in);
And (! temp 1.eof())
{
temp 1 . read((char *)& amp; S, sizeof (student));
outdel 1 . write((char *)& amp; S, sizeof (student));
}
outdel 1 . close();
temp 1 . close();
Cout & lt& lt "This record has been physically deleted"
}
void func7()
{
Ofstream output ("myfrd1.dat");
Teacher's;
Cout & lt& lt "input data"
Cout & lt& lt "Number of teachers:";
CIN & gt; & gtn;
for(int I = 0; I & ltn;; i++)
{
Cout & lt& lt "first"
s . get data();
output . write((char *)& amp; s,sizeof(s));
};
output . close();
}
void func8()
{
Ifstream input ("myfrd1.dat");
Teacher's;
Cout & lt& lt "output data"
cout & lt& ltsetiosflags(ios::left)
& lt& ltsetw( 10)& lt; & lt "Name"
input . read((char *)& amp; s,sizeof(s));
While (input)
{
s . disp();
input . read((char *)& amp; s,sizeof(s));
};
input . close();
}
void func9()
{
char sname[ 10];
Ifstream file ("myfrd1.dat");
Teacher one;
file . seekg(0);
Cout & lt& lt "Enter the name to query (only last name can be entered):";
CIN & gt; & gtsname
Cout & lt& lt "Output query results:"
cout & lt& ltsetiosflags(ios::left)
& lt& ltsetw( 10)& lt; & lt "Name"
file . read((char *)& amp; First, sizeof(one)););
While (file)
{
if(comp(one.getname(),sname)== 1)
one . disp();
file . read((char *)& amp; First, sizeof(one)););
};
file . close();
}
void func0()
{
fstream out app(" my frd . dat 1 ",IOs::app);
Teacher one;
Cout < < "Add data:";
one . get data();
out app . write((char *)& amp; First, sizeof(one)););
out app . close();
}
void func0 1()
{
char sname[ 12];
int I = 0;
fstream outdel(" myfrd 1 . dat ",IOs::in | IOs::out);
Teacher one;
outdel . seekg(0);
Cout & lt& lt "Enter the name to be deleted (only last name can be entered):";
CIN & gt; & gtsname
And (! outdel.eof())
{
outdel . seekp(sizeof(teacher)* I);
outdel . read((char *)& amp; First, sizeof(one)););
if(comp(one.getname(),sname)= = 1 & amp; & ampone.gettag()=='# ')
{
outdel . seekp(sizeof(teacher)* I);
outdel . put(' * ');
}
i++;
}
outdel . close();
}
void func02()
{
fstream outdel("teacher.dat ",IOs::in);
fstream temp("temp ",IOs::out | IOs::trunc);
Teacher's;
And (! outdel.eof())
{
outdel . read((char *)& amp; S, sizeof (teacher));
if(s.gettag()=='# ')
temp . write((char *)& amp; S, sizeof (teacher));
}
outdel . close();
temp . close();
fstream outdel 1(" myfrd 1 . dat ",IOs::out | IOs::trunc);
fstream temp 1("temp ",IOs::in);
And (! temp 1.eof())
{
temp 1 . read((char *)& amp; S, sizeof (teacher));
outdel 1 . write((char *)& amp; S, sizeof (teacher));
}
outdel 1 . close();
temp 1 . close();
Cout & lt& lt "This record has been physically deleted"
}
void func03()
{
Ofstream output ("myfrd2.dat");
Student teacher's;
Cout & lt& lt "input data"
Cout & lt& lt "Number of students:";
CIN & gt; & gtn;
for(int I = 0; I & ltn;; i++)
{
Cout & lt& lt "first"
s . get data();
output . write((char *)& amp; s,sizeof(s));
};
output . close();
}
void func04()
{
ifstream input(" my frd 2 . dat ");
Student teacher's;
Cout & lt& lt "output data"
cout & lt& ltsetiosflags(ios::left)
& lt& ltsetw( 10)& lt; & lt "Name"
input . read((char *)& amp; s,sizeof(s));
While (input)
{
s . disp();
input . read((char *)& amp; s,sizeof(s));
};
input . close();
}
void func05()
{
char sname[ 10];
Ifstream file ("myfrd2.dat");
Student teacher one;
file . seekg(0);
Cout & lt& lt "Enter the name to query (only last name can be entered):";
CIN & gt; & gtsname
Cout & lt& lt "Output query results:"
cout & lt& ltsetiosflags(ios::left)
& lt& ltsetw( 10)& lt; & lt "Name"
file . read((char *)& amp; First, sizeof(one)););
While (file)
{
if(comp(one.getname(),sname)== 1)
one . disp();
file . read((char *)& amp; First, sizeof(one)););
};
file . close();
}
void func06()
{
fstream outapp("MyFrd2.dat ",IOs::app);
Student teacher one;
Cout < < "Add data:";
one . get data();
out app . write((char *)& amp; First, sizeof(one)););
out app . close();
}
void func07()
{
char sname[ 12];
int I = 0;
fstream outdel("MyFrd2.dat ",IOs::in | IOs::out);
Student teacher one;
outdel . seekg(0);
Cout & lt& lt "Enter the name to be deleted (only last name can be entered):";
CIN & gt; & gtsname
And (! outdel.eof())
{
outdel . seekp(sizeof(student teacher)* I);
outdel . read((char *)& amp; First, sizeof(one)););
if(comp(one.getname(),sname)= = 1 & amp; & ampone.gettag()=='# ')
{
outdel . seekp(sizeof(student teacher)* I);
outdel . put(' * ');
}
i++;
}
outdel . close();
}
void func08()
{
fstream outdel(" student teacher . dat ",IOs::in);
fstream temp("temp ",IOs::out | IOs::trunc);
Student teacher's;
And (! outdel.eof())
{
outdel . read((char *)& amp; s,sizeof(student teacher));
if(s.gettag()=='# ')
temp . write((char *)& amp; s,sizeof(student teacher));
}
outdel . close();
temp . close();
fstream outdel 1(" my frd 2 . dat ",IOs::out | IOs::trunc);
fstream temp 1("temp ",IOs::in);
And (! temp 1.eof())
{
temp 1 . read((char *)& amp; s,sizeof(student teacher));
outdel 1 . write((char *)& amp; s,sizeof(student teacher));
}
outdel 1 . close();
temp 1 . close();
Cout & lt& lt "This record has been physically deleted"
}
void func09()
{
char sname[ 10];
Ifstream file ("myfrd.dat");
Student one;
file . seekg(0);
Cout & lt& lt "Enter the name to be modified (only last name can be entered):";
CIN & gt; & gtsname
Cout & lt& lt "Output query results:"
cout & lt& ltsetiosflags(ios::left)
& lt& ltsetw( 10)& lt; & lt "Name"
file . read((char *)& amp; First, sizeof(one)););
While (file)
{
if(comp(one.getname(),sname)== 1)
one . disp();
file . read((char *)& amp; First, sizeof(one)););
};
file . close();
Ofstream output ("myfrd.dat");
Student s;
Cout & lt& lt "Re-enter data:"
s . get data();
output . write((char *)& amp; s,sizeof(s));
output . close();
}
void func 10()
{
char sname[ 10];
Ifstream file ("myfrd1.dat");
Teacher one;
file . seekg(0);
Cout & lt& lt "Enter the name to be modified (only last name can be entered):";
CIN & gt; & gtsname
Cout & lt& lt "Output query results:"
cout & lt& ltsetiosflags(ios::left)
& lt& ltsetw( 10)& lt; & lt "Name"
file . read((char *)& amp; First, sizeof(one)););
While (file)
{
if(comp(one.getname(),sname)== 1)
one . disp();
file . read((char *)& amp; First, sizeof(one)););
};
file . close();
Ofstream output ("myfrd1.dat");
Teacher's;
Cout & lt& lt "Re-enter data:"
s . get data();
output . write((char *)& amp; s,sizeof(s));
output . close();
}
void func 1 1()
{
char sname[ 10];
Ifstream file ("myfrd2.dat");
Student teacher one;
file . seekg(0);
Cout & lt& lt "Enter the name to be modified (only last name can be entered):";
CIN & gt; & gtsname
Cout & lt& lt "Output query results:"
cout & lt& ltsetiosflags(ios::left)
& lt& ltsetw( 10)& lt; & lt "Name"
file . read((char *)& amp; First, sizeof(one)););
While (file)
{
if(comp(one.getname(),sname)== 1)
one . disp();
file . read((char *)& amp; First, sizeof(one)););
};
file . close();
Ofstream output ("myfrd2.dat");
Student teacher's;
Cout & lt& lt "Re-enter data:"
s . get data();
output . write((char *)& amp; s,sizeof(s));
output . close();
}
int comp(char s 1[],char s2[])
{
int I = 0;
while(s 1[i]! = ' \ 0 ' & amp& amps2[i]! = ' \ 0 ' & amp& amps 1[i]==s2[i])
i++;
if(s 1[I]= = ' \ 0 ' | | S2[I]= = ' \ 0 ')
Returns1;
other
Returns 0;
}
void main()
{
int sel
do
{
Cout & lt& lt "Please enter (1: Input Data 2: Output Data 3: Query by Name".
CIN & gt; & gtsel
Switch (selection)
{
Case 1:
char a,b;
while( 1)
{
Cout & lt& lt "Please enter the object of your choice (student (1), teacher (2), graduate student (3)):;
CIN & gt; & gta;
if(a==' 1 ')
func 1();
else if(a=='2 ')
func 7();
else if(a=='3 ')
func 03();
other
Cout & lt& lt "Input error!" & lt& ltendl
Cout & lt& lt "Continue? (Yes/No) ";
CIN & gt; & gtb;
And (b! = ' y ' & amp& ampb! = ' Y ' & amp& ampb! = ' n ' & amp& ampb! ='N ')
{
Cout & lt& lt "Sorry, you have the wrong number! Please re-enter: ";
CIN & gt; & gtb;
}
if(b=='n'||b=='N ')
Break;
}
Break;
Case 2:
char c,d;
while( 1)
{
Cout & lt& lt "Please enter the object of your choice (student (1), teacher (2), graduate student (3)):;
CIN & gt; & gtc;
if(c==' 1 ')
func 2();
else if(c=='2 ')
func 8();
else if(c=='3 ')
func 04();
other
Cout & lt& lt "Input error!" & lt& ltendl
Cout & lt& lt "Continue? (Yes/No) ";
CIN & gt; & gtd;
And (d! = ' y ' & amp& ampd! = ' Y ' & amp& ampd! = ' n ' & amp& ampd! ='N ')
{
Cout & lt& lt "Sorry, you have the wrong number! Please re-enter: ";
CIN & gt; & gtd;
}
if(d=='n'||d=='N ')
Break;
}
Break;
Case 3:
char e,f;
while( 1)
{
Cout & lt& lt "Please enter the object of your choice (student (1), teacher (2), graduate student (3)):;
CIN & gt; & gte;
if(e==' 1 ')
func 3();
else if(e=='2 ')
func 9();
else if(e=='3 ')
func 04();
other
Cout & lt& lt "Input error!" & lt& ltendl
Cout & lt& lt "Continue? (Yes/No) ";
CIN & gt; & gtf;
And (b! = ' y ' & amp& ampb! = ' Y ' & amp& ampb! = ' n ' & amp& ampb! ='N ')
{
Cout & lt& lt "Sorry, you have the wrong number! Please re-enter: ";
CIN & gt; & gtf;
}
if(f=='n'||f=='N ')
Break;
}
Break;
Case 4:
char g,h;
while( 1)
{
Cout & lt& lt "Please enter the object of your choice (student (1), teacher (2), graduate student (3)):;
CIN & gt; & gtg;
if(g==' 1 ')
func 4();
else if(g=='2 ')
func 0();
else if(g=='3 ')
func 06();
other
Cout & lt& lt "Input error!" & lt& ltendl
Cout & lt& lt "Continue? (Yes/No) ";
CIN & gt; & gth;
And (h! = ' y ' & amp& amph! = ' Y ' & amp& amph! = ' n ' & amp& amph! ='N ')
{
Cout & lt& lt "Sorry, you have the wrong number! Please re-enter: ";
CIN & gt; & gth;
}
if(h=='n'||h=='N ')
Break;
}
Break;
Case 5:
char m,n;
while( 1)
{
Cout & lt& lt "Please enter the object of your choice (student (1), teacher (2), graduate student (3)):;
CIN & gt; & gtm;
if(m==' 1 ')
func 5();
else if(m=='2 ')
func 0 1();
else if(m=='3 ')
func 07();
other
Cout & lt& lt "Input error!" & lt& ltendl
Cout & lt& lt "Continue? (Yes/No) ";
CIN & gt; & gtn;
And (n! = ' y ' & amp& ampn! = ' Y ' & amp& ampn! = ' n ' & amp& ampn! ='N ')
{
Cout & lt& lt "Sorry, you have the wrong number! Please re-enter: ";
CIN & gt; & gtn;
}
if(n=='n'||n=='N ')
Break;
}
Break;
Case 6:
char x,z;
while( 1)
{
Cout & lt& lt "Please enter the object of your choice (student (1), teacher (2), graduate student (3)):;
CIN & gt; & gtx;
if(x==' 1 ')
func 6();
else if(x=='2 ')
func 02();
else if(x=='3 ')
func 08();
other
Cout & lt& lt "Input error!" & lt& ltendl
Cout & lt& lt "Continue? (Yes/No) ";
CIN & gt; & gtz;
And (z! = ' y ' & amp& ampz! = ' Y ' & amp& ampz! = ' n ' & amp& ampz! ='N ')
{
Cout & lt& lt "Sorry, you have the wrong number! Please re-enter: ";
CIN & gt; & gtz;
}
if(z=='n'||z=='N ')
Break;
}
Break;
Case 7:
char s,t;
while( 1)
{
Cout & lt& lt "Please enter the object of your choice (student (1), teacher (2), graduate student (3)):;
CIN & gt; & gts;
if(s==' 1 ')
func 09();
else if(s=='2 ')
func 10();
else if(s=='3 ')
func 1 1();
other
Cout & lt& lt "Input error!" & lt& ltendl
Cout & lt& lt "Continue? (Yes/No) ";
CIN & gt; & gtt;
while(t! = ' y ' & amp& ampt! = ' Y ' & amp& ampt! = ' n ' & amp& ampt! ='N ')
{
Cout & lt& lt "Sorry, you have the wrong number! Please re-enter: ";
CIN & gt; & gtt;
}
if(t=='n'||t=='N ')
Break;
}
Break;
Default value:
Cout & lt& lt "Input error!" & lt& ltendl
Break;
}
}
while(sel & gt; = 1。 & ampsel & lt=6);
}