Este es el cpp de carga:
Código
cpp de proceso:
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
using namespace std;
struct registro{
int legajo, altura, peso;
};
int main()
{
FILE *p = fopen("registros2.dat", "ab");
if(p == NULL)
{
cout << "Error al abrir el archivo.";
exit(1);
}
else
{
registro alumnos[10];
for(int i = 0; i < 10; i++)
{
cout << "Legajo alumno "<< i+1 <<": ";
cin >> alumnos[i].legajo;
cout << "Altura: ";
cin >> alumnos[i].altura;
cout << "Peso: ";
cin >> alumnos[i].peso;
fwrite(&alumnos[i], sizeof(registro), 1, p);
}
fclose(p);
}
system("pause");
return 0;
}
Código
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
struct registro{
int legajo, altura, peso;
};registro alumnos[10];
void peso_mayor_menor(FILE *p)
{
int aux=0, aux1=0, aux2=0, res=0;
while(feof(p)==0)
{
fread(&alumnos, sizeof(registro), 1, p);
for (int i = 0; i < 9; i++)
{
for (int j = i + 1; j < 10; j++)
{
if (alumnos[i].peso > alumnos[j].peso)
{
aux = alumnos[i].peso;
alumnos[i].peso = alumnos[j].peso;
alumnos[j].peso = aux;
aux1 = alumnos[i].legajo;
alumnos[i].legajo = alumnos[j].legajo;
alumnos[j].legajo = aux1;
aux2 = alumnos[i].altura;
alumnos[i].altura = alumnos[j].altura;
alumnos[j].altura = aux2;
}
}
}
}
for(int i = 0; i < 10; i++)
{
cout << "Legajo " << ": " << alumnos[i].legajo << endl;
cout << "Peso " << ": " << alumnos[i].peso << endl;
cout << "Altura " << ": " << alumnos[i].altura << endl << endl;
}
long tam = 0 * sizeof(registro);
res = fseek (p, tam, SEEK_CUR);
if (res == 0)
{
fread (&alumnos, sizeof (registro), 1, p);
cout << "ALUMNO DE MENOR PESO" << endl;
cout << "Legajo: " << alumnos[tam].legajo << endl;
cout << "Peso: " << alumnos[tam].peso << endl << endl;
}
rewind(p);
long tam1 = 0 * sizeof(registro);
int res1 = fseek (p, tam1, SEEK_CUR);
if(res==0)
{
fread (&alumnos, sizeof (registro), 1, p);
cout << "ALUMNO DE MAYOR PESO" << endl;
cout << "Legajo: " << alumnos[tam1].legajo << endl;
cout << "Peso: " << alumnos[tam1].peso << endl << endl;
}
}
//void altura_mayor_menor(FILE *p)
//{
//}
int main()
{
FILE *p = fopen("registros2.dat", "rb");
if(p == NULL)
{
cout << "Error al abrir el archivo.";
exit(1);
}
else
{
peso_mayor_menor(p);
//altura_mayor_menor(p);
}
system("pause");
fclose(p);
return 0;
}


 
  




 Autor
 Autor
		


 En línea
									En línea
								



