
Решение:
Код:
// Задание № 6.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <math.h>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <io.h>
using namespace std;
FILE *Fz, *Ft;
struct TZap{
char FIO[30];
char birthd[15];
int num_gr;
int mas[4];
double s_b;
} Zap;
void Out(TZap z)
{
printf("\n %1s , \t%10s, \t%x, \t%x, \t%x,\t %x,\t %x,\t %x", z.FIO,z.birthd,z.num_gr,z.mas[0],z.mas[1],z.mas[2],z.mas[3],z.s_b);
fprintf(Ft,"\n %1s ,\t %10s, \t%x, \t%x,\t %x, \t%x,\t %x,\t %x", z.FIO,z.birthd,z.num_gr,z.mas[0],z.mas[1],z.mas[2],z.mas[3],z.s_b);
}
int _tmain(int argc, _TCHAR* argv[])
{
int size = sizeof(TZap);
char File_Zap[] = "zapisi.txt";
char File_Rez[] = "rezult.txt";
void Out(TZap);
int kod, D_f, i=0, j, kol;
long len;
double *srb,srr;
TZap st, *mas_Z;
Ft = fopen(File_Rez, "w");
while(true) {
puts("\n Create – 1\n Add – 2\n View – 3\n Perfect_Students – 4\n EXIT – 0");
scanf("%d", &kod);
switch(kod) {
case 1:
if ((Fz=fopen(File_Zap,"w"))==NULL) {
puts("\n Create ERROR!");
}
fclose(Fz);
printf("\n Create New File %s !\n",File_Zap);
break;
case 2:
Fz = fopen(File_Zap,"a");
printf("\n F.I.O. – ");
fflush(stdin);
gets(Zap.FIO);
printf(" BirthDay – ");
fflush(stdin);
gets(Zap.birthd);
printf(" Group – ");
scanf("%x" , &Zap.num_gr);
printf(" Physics – ");
fflush(stdin);
scanf("%x", &Zap.mas[0]);
printf(" Math – ");
fflush(stdin);
scanf("%x", &Zap.mas[1]);
printf(" Informatica – ");
fflush(stdin);
scanf("%x", &Zap.mas[2]);
printf(" Chemistry – ");
fflush(stdin);
scanf("%x", &Zap.mas[3]);
//srr=(double(Zap.mas[0]+Zap.mas[1]+Zap.mas[2]+Zap.mas[3])/double(4));
printf(" Sr ball – ");
fflush(stdin);
scanf("%x", &Zap.s_b);
fwrite(&Zap, size, 1, Fz);
fclose(Fz);
break;
case 3:
if ((Fz=fopen(File_Zap,"r"))==NULL) {
puts("\n Open ERROR!");
}
// Вывод на экран
printf("\n\-------FIO------Birthday--------Group--Physics--Math--Inform--Chem--SR_BAL");
// Запись такой же информации в текстовый файл Ft
fprintf(Ft,"\n\------FIO------Birthday--------Group--Physics--Math--Inform--Chem--SR_BAL");
while(1) {
if(!fread(&Zap,size,1,Fz)) break;
Out(Zap);
}
fclose(Fz);
break;
case 4:
Fz = fopen(File_Zap,"r");
D_f = fileno(Fz);
char fl[1];
len = filelength(D_f);
kol = len/size;
mas_Z = new TZap[kol];
// Считываем записи из файла в динамический массив
for (i=0; i < kol; i++)
fread((mas_Z+i), size, 1, Fz);
fclose(Fz);
printf(" VVedite Pervuu bukvu familii – ");
fflush(stdin);
gets(fl);
for (i=0; i<kol; i++)
{if (mas_Z[i].FIO[0]==fl[0] && ((mas_Z[i].mas[0]+mas_Z[i].mas[1]+mas_Z[i].mas[2]+mas_Z[i].mas[3])/4)==5)Out(mas_Z[i]);}
delete []mas_Z;
break;
case 0:
fclose(Ft);
return 0;
break;
}
}
return 0;
}
Скриншот: