rendered paste body#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<fstream.h>
struct komanda
{char name[30];
char fio[30];
int nomer;
int vozr;
int rost;
int ves;};
struct sport
{char strana[30];
struct komanda komand;};
struct sport igrok;
char c1[30],c2[30],c3[100];
int t1;
fstream fil;
void vvod(int m)
{ cout<<"\nvvedite dannue o "<<(m+1)<<" igroke:\n\n";
cout<<"strana: "; gets(c1);
strcpy(igrok.strana,c1);
cout<<"komanda: "; gets(c2);
strcpy(igrok.komand.name,c2);
cout<<"fio: "; gets(c3);
strcpy(igrok.komand.fio,c3);
cout<<"nomer: "; cin>>igrok.komand.nomer;
cout<<"vozrast: "; cin>>igrok.komand.vozr;
cout<<"rost: "; cin>>igrok.komand.rost;
cout<<"ves: "; cin>>igrok.komand.ves;
// ZAPIS v file polei 1 structuri
fil<<igrok.strana<<" "<<igrok.komand.name<<" "<<igrok.komand.fio<<" "<<igrok.komand.nomer<<" "<<igrok.komand.vozr<<" "<<igrok.komand.rost<<" "<<igrok.komand.ves<<endl;}
main()
{int i,m,j=-1,d, r1,r2,r3, pos[20], z;
float min1, max, min2, vo[20], ro[20], ve[20];
char key;
while (key<'6')
{clrscr(); cout<<"\n\n\n\n\n\n";
cout<<"\t\t\t1 - SOZDANIE faila\n\n";
cout<<"\t\t\t2 - CHTENIE faila\n\n";
cout<<"\t\t\t3 - DOBAVLENIE zapisey v fail\n\n";
cout<<"\t\t\t4 - FORMIROVANIE komand\n\n";
cout<<"\t\t\t5 - INFORMACIA o komandah\n\n";
cout<<"\t\t\t6 - VIHOD\n\n";
cin>>key;
if (key=='1')
{clrscr(); m=0; //m-kol-vo zapisei
//sozdanie novogo faila s rezimami dla dobavlenia
fil.open("igro.dat",ios::trunc|ios::app);
if (!fil) {cout<<"file not open"; return 1;}
//vvod dannix (1 structuri) i zapis ee v file
vvod(m);
fil.close(); }
if (key=='2')
{ clrscr();
cout<<"------------------------------------------------------------------------------\n";
printf("|%11s | %11s | %11s | %7s | %7s | %5s | %5s | \n", "strana","komanda","fio","nomer","vozrast","rost","ves");
cout<<"------------------------------------------------------------------------------\n";
//otkritie file dla chtenia
fil.open("igro.dat",ios::out|ios::in);
//po kol-vy zapisei proshitat file
for(i=0;i<=m;i++)
{
//opredelenie tekushei posizii v file
z=fil.tellp();
//perexod na tekushuu posiziu
fil.seekp(z);
//viravnivanie
cout<<"|"; cout.setf(ios::right);
// SHTENIE iz file polei 1 structuri
fil>>igrok.strana; cout.width(11); cout<<igrok.strana; cout<<" |";
fil>>igrok.komand.name; cout.width(12); cout<<igrok.komand.name; cout<<" |";
fil>>igrok.komand.fio; cout.width(12); cout<<igrok.komand.fio; cout<<" |";
fil>>igrok.komand.nomer; cout.width(8); cout<<igrok.komand.nomer; cout<<" |";
fil>>igrok.komand.vozr; cout.width(8); cout<<igrok.komand.vozr; cout<<" |";
fil>>igrok.komand.rost; cout.width(6); cout<<igrok.komand.rost; cout<<" |";
fil>>igrok.komand.ves; cout.width(6); cout<<igrok.komand.ves; cout<<" |";
cout<<endl; cout.unsetf(ios::right);}
cout<<"------------------------------------------------------------------------------\n";
getch(); fil.close(); }
if (key=='3')
{clrscr();
//dobablenie zapisei v suchestvuushii file v konec
//kol-vo zapisei uvelishivaetsa na 1
m++;
//otkritie file dla dobavlenia
fil.open("igro.dat",ios::app);
vvod(m); fil.close(); }
if (key=='4')
{clrscr(); j++; vo[j]=0; ro[j]=0; ve[j]=0; d=0; char k[30], s[30];
cout<<"vvedite nazvanie komandi: "; gets(k);
cout<<"vvedite stranu komandi: "; gets(s);
//otkritie file dla shtenia/zapisi
fil.open("igro.dat",ios::out|ios::in);
for(i=0;i<=m;i++) //v zikle po kol-vy zapisei proshitat file
{
z=fil.tellp();
fil.seekp(z);
// SHTENIE iz file polei 1 structuri
fil>>igrok.strana>>igrok.komand.name>>igrok.komand.fio>>igrok.komand.nomer>>igrok.komand.vozr>>igrok.komand.rost>>igrok.komand.ves;
//sravnenie prochitannoi zapisi s vvedennoi
if ((strcmp(igrok.komand.name,k)==0)&&(strcmp(igrok.strana,s)==0))//esli oni ravni
{ d++; pos[j]=z;
vo[j]+=igrok.komand.vozr;
ro[j]+=igrok.komand.rost;
ve[j]+=igrok.komand.ves; } }
cout<<"v komande "<<k<<" strani "<<s<<" "<<d<<" igroka";
if(d!=0) { vo[j]/=d; ro[j]/=d; ve[j]/=d;}
getch();fil.close();}
if (key=='5') //poisk samoi molodoi, rosloi i legkoi komandi
{clrscr(); min1=vo[0]; max=ro[0]; min2=ve[0]; r1=0; r2=0; r3=0;
for(int x=1;x<=j;x++)
{if (min1>vo[x]) {min1=vo[x]; r1=x;}
if (max<ro[x]) {max=ro[x]; r2=x;}
if (min2>ve[x]) {min2=ve[x]; r3=x;}}
//otkritie file dla shtenia/zapisi
fil.open("igro.dat",ios::out|ios::in);
//ustanovka ukazatela v file na posiziu
fil.seekp(pos[r1]);
// SHTENIE iz file polei 1 structuri
fil>>igrok.strana>>igrok.komand.name;
cout<<"samaya molodaya komanda "<<igrok.komand.name<<"\n\tstrani "<<igrok.strana<<"\n\tsredniy vozrast "<<min1<<endl;
fil.seekp(pos[r2]); fil>>igrok.strana>>igrok.komand.name;
cout<<"samaya roslaya komanda "<<igrok.komand.name<<"\n\tstrani "<<igrok.strana<<"\n\tsredniy rost "<<max<<endl;
fil.seekp(pos[r3]); fil>>igrok.strana>>igrok.komand.name;
cout<<"samaya legkaya komanda "<<igrok.komand.name<<"\n\tstrani "<<igrok.strana<<"\n\tsredniy ves "<<min2<<endl; getch(); fil.close();}
if (key=='6') {clrscr(); exit(0);} }}