27.04.2010, 14:57
|
#8
|
Пользователь
Регистрация: 12.03.2010
Адрес: Беларусь
Сообщений: 54
Сказал(а) спасибо: 8
Поблагодарили 24 раз(а) в 17 сообщениях
|
оооо! Счяс найду код девушки моего друга, будете плеваться как гопники семечками!
Код:
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define m 5
FILE *ish, *result;
int n; //kolichestvo strok
char *namefile_ish = "h:\\ish.dat",
*namefile_result ="h:\\result.dat";
void MyCreate()
{int a[m];
if((ish=fopen(namefile_ish,"w"))==NULL)
{printf("Error\n"); return; }
else printf("File is opened\n");
cout<<"kolichestvo strok: "; cin>>n;
randomize();
for(int i=0; i<n; i++)
{cout<<endl;
for(int j=0; j<m; j++)
{a[j]=random(10);
printf("%5d", a[j]);
}
fwrite(a, sizeof(a), 1, ish);
}
fclose(ish);
cout<<"\nFile was created";
}
////////////////////////////////////////
void MyAppend(int prirost)
{int a[m], i; char ch;
if((ish=fopen(namefile_ish,"a"))==NULL)
{printf("Error\n"); return; }
else printf("File is opened\n");
do
{cout<<endl;
a[0]=random(10);
for(i=1; i<m; i++)
{a[i]=a[i-1]+prirost;
cout<<a[i]<<" ";
}
fwrite(a, sizeof(a), 1, ish);
n++;
cout<<"\n*--exit";
ch=getch();
} while(ch!='*');
fclose(ish);
}
/////////////////////////////////////////////////
void MyRead(char *name)
{FILE * arf;
int a[m];
if((arf=fopen(name,"r"))==NULL)
{printf("Error\n"); return; }
clrscr();
fread(a, sizeof(a), 1, arf);
while(!feof(arf))
{cout<<"\n";
for(int j=0; j<m; j++)
printf("%5d", a[j]);
fread(a, sizeof(a), 1, arf);
}
fclose(arf);
}
///////////////////////////////////////////////////
void MyFindMax()
{
int a[m], i, max_in_str, max_in_file ;
if((ish = fopen(namefile_ish,"r"))==NULL)
{printf("Error fopen Ish\n"); return; }
if((result=fopen(namefile_result,"w"))==NULL)
{printf("Error fopen Result\n"); return; }
fread(a, sizeof(a), 1, ish);
max_in_str = a[0];
max_in_file = a[0];
while(!feof(ish))
{
if((a[1]-a[0])>0) //возрастает?
{
{for(i=1; i<m; i++)
if(a[i]<=a[i-1]) break;
}
max_in_str = a[m-1];
}
else
{
if((a[1]-a[0])<0) //убывает?
{for(i=1; i<m; i++)
if(a[i]>=a[i-1]) break;
}
max_in_str = a[0];
}
if(i==m)
{
fwrite(a, sizeof(a), 1, result);
if (max_in_file < max_in_str)
max_in_file = max_in_str;
cout<<"maximum stroki = "; cout<<max_in_str; cout<< "\n";
}
fread(a, sizeof(a), 1, ish);
}
fclose(ish);
fclose(result);
printf("\nmaximum of matrica = "); cout<<max_in_file;
}
int main()
{
int flag;
while(1)
{
cout<<"\n1 -- CREATE"<<endl<<
"2 -- APPEND UP"<<endl<<
"3 -- APPEND Down"<<endl<<
"4 -- READ Ishodny File"<<endl<<
"5 -- Find Maximum"<<endl<<
"6 -- Read VOZRASTAYUSHIE I UBYVAYUSHIE STROKI"<<endl<<
"0 -- EXIT"<<endl;
cin>>flag; switch(flag)
{
case 1:MyCreate(); break;
case 2:MyAppend(1); break;
case 3:MyAppend(-1); break;
case 4:MyRead(namefile_ish); break;
case 5:MyFindMax(); break;
case 6:MyRead(namefile_result); break;
case 0: return 0;
}
}
}
|
|
|