Look at this code:
//The program needs to establish two text documents, teams.txt and teamlist.txt, on disk D to save team information and score information//
# include & ltiostream & gt
# include & lt string & gt
# include & ltfstream & gt
Use namespace std
Class team {
Private:
Int target;
int cgoal
int pgoal
int win
Int is missing;
Int equals;
int scorce
Public:
char name[20];
Team () {
Target = 0;
CGO al = 0;
p goal = 0;
win = 0;
Lost = 0;
Equal to = 0;
scorce = 0;
}
Void display () {
Cout & lt& lt name & lt<<< target & lt<<<<<<< < lt < lt < lt < lt < lt < lt < lt < lt < lt < lt < lt < lt < lt <
}
void goal chg(int a);
void matchchg(int a,int b);
Invalid Competition (Team & AMPT);
void setIm();
int getS();
int getPG();
};
void Team::goalchg(int a){
If (a>0)
This-> Target+= a;
If (a<0)
This-> CGO al-= a;
p goal = goal-CGO al;
}
void Team::matchchg(int a,int b){
If (a & gtb){
This-> win+= 1;
This-> scorce+= 3;
}
If (a & ltb){
This-> lost+= 1;
}
if(a==b){
This-> Equal to+=1;
This-> scorce+= 1;
}
}
Invalid Team:: Competition (Team & ampt){
int a,b;
Cout & lt& lt "according to the goal of home:";
CIN & gt; & gta;
If (a & lt0){
Cout & lt& lt "warning"<& ltendl
Exit (1);
}
Cout & lt& lt "According to the goal of ihome:";
CIN & gt; & gtb;
if(b & lt; 0){
Cout & lt& lt "warning"<& ltendl
Exit (1);
}
This-> goal chg(a);
This-> goal chg(0-b);
Goal (b);
t . goal chg(0-a);
This-> matchchg(a,b);
t.matchchg(b,a);
}
void Team::setIm(){
Cout & lt& lt "Team name:";
CIN & gt; & gt This-> Name;
}
int Team::getS(){
Return this-> Scholes;
}
int Team::getPG(){
Return this-> pgoal
}
void getteamlist();
fstream team("d:\\teams.txt ",IOs::in | IOs::out | IOs::binary);
void main(){
char name[20];
Team t [5];
int t 1,T2;
char n;
int I;
If (! Team) {
Cout & lt& lt "lost files"<& ltendl
Exit (1);
}
while( 1){
Cout & lt& lt "Have you set up team instant messaging? (Y)" & lt; & ltendl
CIN & gt; & gtn;
if(n=='Y'||n=='y ')
Break;
for(int I = 0; I < = 4; i++){
t[i]。 setIm();
team . write((char *)& amp; t[i],sizeof(t[I]);
}
Break;
}
team.seekg(0,IOs::beg);
for(I = 0; I<5; i++)
team . read((char *)& amp; t[i],sizeof(t[I]);
while( 1){
Cout & lt& lt "Do you have any matches now? (N)" & lt; & ltendl
CIN & gt; & gtn;
if(n=='N'||n=='n ')
Break;
Do {
Cout & lt& lt "Name of main team:";
CIN & gt; & gt name;
for(I = 0; I<5; i++){
if(strcmp(name,t[i])。 name)==0){
t 1 = I;
Break;
}
other
Continue;
}
} while(I = = 5);
Do {
Cout < < "keteam name:";
CIN & gt; & gt name;
for(I = 0; I<5; i++){
if(strcmp(name,t[i])。 name)==0){
T2 = I;
Break;
}
other
Continue;
}
} while(I = = 5);
t[t 1]。 match(t[T2]);
}
team.seekg(0,IOs::beg);
for(I = 0; I<5; i++)
team . write((char *)& amp; t[i],sizeof(t[I]);
getteamlist();
}
void getteamlist(){
Team t1[5];
Hao team;
fstream gamelist(" d:\ \ teamlist . txt ",IOs::in | IOs::out | IOs::binary);
If (! Game list) {
Cout & lt& lt "is wrong! ! "& lt& ltendl
Exit (1);
}
team.seekg(0,IOs::beg);
for(int I = 0; I<5; i++){
team . read((char *)& amp; t 1[i],sizeof(t 1[I]);
}
for(int j = 0; j & lt4; j++)
for(int I = 0; I<4-j; i++){
if(t 1[i].getS()& lt; t 1[i+ 1]。 getS()){
Hao = t 1[I];
t 1[I]= t 1[I+ 1];
T 1[I+ 1]= Hao;
}
if(t 1[i].getS()==t 1[i+ 1]。 getS()){
if(t 1[i].getPG()& lt; t 1[i+ 1]。 getPG()){
Hao = t 1[I];
t 1[I]= t 1[I+ 1];
T 1[I+ 1]= Hao;
}
}
}
Cout & lt& lt "team"
for(I = 0; I<5; i++){
gamelist . write((char *)& amp; t 1[i],sizeof(t 1[I]);
t 1[i]。 Display ();
}
That's basically all I wrote. See if you can use it.