#include <iostream.h>
#include <stdio.h>
#include <conio.h>
void creartorneo(FILE*);
void leerarchivo(FILE*);
void ingresarresultados(FILE*);
void mostrarposiciones(FILE*);
struct sequipos
{
char nombre[];
int equipo[],gf,gc,pts;
}equipo;
int main(){
FILE *torneo;
{
cout<<"Elija una opcion"<<endl<<endl;
cout<<"1-Carga Inicial"<<endl<<"2-Leer archivo"<<endl<<"3-Ingresar Resultados"<<endl<<"4-Mostrar Posiciones"<<endl<<"5-Salir del Programa"<<endl;
cin>>n;
switch(n){
case 1:
creartorneo(torneo);
break;
case 2:
leerarchivo(torneo);
break;
case 3:
ingresarresultados(torneo);
break;
//case 4:{
// mostrarposiciones(torneo);
// }
case 5:
break;
}
}
}
void creartorneo(FILE *torneo)
{
int i,tot;
torneo
=fopen("c:\torneo.dat","wb"); if(torneo!=NULL){
torneo
=fopen("c:\torneo.dat","ab"); cout<<"Ingrese cantidad de equipos ";cin>>tot;
for(i=1;i<=tot;i++){
cout<<"Ingrese nombre del equipo "<<i<<endl;
scanf("%s",equipo.
nombre); fwrite(&equipo
, sizeof(struct sequipos
),1, torneo
); }
}
return;
}
void leerarchivo(FILE*torneo){
int numero=1;
torneo
=fopen("c:\torneo.dat","rb"); if(torneo==NULL){
cout<<"El archivo no existe, por favor creelo!!!!";
}
fread(&equipo
, sizeof(struct sequipos
),1,torneo
); printf("n%d t%s t%d t%d t%d t%d",numero
,equipo.
nombre,equipo.
gf,equipo.
gc,equipo.
pts); fread(&equipo
, sizeof(struct sequipos
),1,torneo
); numero++;
return;
}
void ingresarresultados(FILE*torneo){
char equipo1[25],equipo2[25];
int gf1,gc1,gf2,gc2,pts1,pts2,bandera=1,i=0;
torneo
=fopen("c:\torneo.dat","a+b"); cout<<"Ingrese nombre del equipo 1: ";
cout<<"nIngrese nombre del equipo 2: ";
cout<<"Ingrese goles del equipo 1: "<<endl;cin>>gf1;gc2=gf1;
cout<<"Ingrese goles del equipo 2: "<<endl;cin>>gf2;gc1=gf2;
if(gf1>gf2){
pts1=3;
pts2=0;
}
else if(gf1<gf2)
{pts2=3;
pts1=0;
}else
{pts1=pts2=1;}
fread(&equipo
, sizeof(struct sequipos
),1,torneo
); while(equipo1[i]!=0)
{
if(equipo1[i]==equipo.nombre[i]){
i++;
}else{
bandera=0;
}
}
if(bandera==1){
equipo.pts=pts1;
equipo.gf=gf1;
equipo.gc=gc1;
fwrite(&equipo
, sizeof(struct sequipos
),1, torneo
); break;
}
else{
fread(&equipo
, sizeof(struct sequipos
),1,torneo
); }
}
torneo
=fopen("c:\torneo.dat","a+b");
i=0;bandera=1;
fread(&equipo
, sizeof(struct sequipos
),1,torneo
); while(equipo2[i]!=' ')
{
if(equipo2[i]==equipo.nombre[i]){
i++;
}else{
bandera=0;
}
}
if(bandera==1){
equipo.pts=pts2;
equipo.gf=gf2;
equipo.gc=gc2;
fwrite(&equipo
, sizeof(struct sequipos
),1, torneo
); }
else{
fread(&equipo
, sizeof(struct sequipos
),1,torneo
); }
}
return;
}
void mostrarposiciones(FILE *torneo)
{
int i=0;
equipo arreglo[],aux;
torneo
=fopen("c:\torneo.dat","rb");
fread(&equipo
, sizeof(struct sequipos
),1,torneo
); arreglo[i]= equipo;
i++;
fread(&equipo
, sizeof(struct sequipos
),1,torneo
); }
i--;
for(j=0;j<i-1;j++){
for(k=j+1;k<i;k++){
if(arreglo[j].pts<arreglo[k].pts){
aux=arreglo[j]
arreglo[j]=arreglo[k];
arreglo[k]=arreglo[j];
}
}
}
for(j=0;j<=i;j++){
printf("n t%s t%d t%d t%d t%d",arreglo
[j
].
nombre,arreglo
[j
].
gf,arreglo
[j
].
gc,arreglo
[j
].
pts) }
}