#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <iomanip.h>
#include <fstream.h>

struct musei
{
char name[20];
char tipe[20];
char adrs[30];
float price;
char time[80];
} a[10];

char*sh[]=
{
"                      ใงฅจ                        ",
"ีออออออออออัอออออออออออัอออออออัออออออัอออออออออออธ",
"ณ  งข ญจฅ ณ ชแฏฎงจๆจ๏ณ คเฅแ ณ ฅญ  ณเฅฌ๏      ณ",
"ฦออออออออออุอออออออออออุอออออออุออออออุอออออออออออต",
"ิออออออออออฯอออออออออออฯอออออออฯออออออฯอออออออออออพ"
};

ifstream fin;
ofstream fout;

float max, min;

void filtr (char* stroka)
{
char sourse[250];
int xk=strlen(stroka)-1;
int xn=0;
while(stroka[xn]==' ') xn++;
while(stroka[xk]==' ') xk--;
for(int i=xn, j=0; i<=xk; i++, j++) sourse[j]=stroka[i];
sourse[j]='\0';
strcpy(stroka, sourse);
}

void shapka()
{
for(int i=0;i<4;i++) fout<<sh[i]<<endl;
}

int number (char* filename)
{
int n=0;
char t[255];
fin.open(filename);
if(!fin){cout<<"Fail to read file data";exit(1);}
while(fin.peek()!=EOF)
{fin.getline(t,255); n++;}
fin.close();
return n;
}

char buf[2];

void vvod (musei a[], int n, float& max, float& min, char* filename)
{
int k=0, l=0;
fin.open(filename);
if(!fin){cout<<"Fail to read file data";exit(1);}
cout<<n<<endl;
for(int i=0; i<n; i++)
{
fin.getline(a[i].name,19);
filtr(a[i].name);  cout<<endl<< a[i].name ;

fin.getline(a[i].tipe,14);
filtr(a[i].tipe); cout<< a[i].tipe;

fin.getline(a[i].adrs,15);
filtr(a[i].adrs); cout<< a[i].adrs;

fin>>a[i].price;  cout<<a[i].price;

fin.getline(a[i].time,80);
filtr(a[i].time);cout<<a[i].time;

if(k==0) {max=a[i].price; k++;}
if(l==0) {min=a[i].price; l++;}

if(a[i].price<min) min=a[i].price;
if(a[i].price>max) max=a[i].price;
}
fin.close();
}

void vivod (musei a[], int n)
{
for(int i=0; i<n; i++)
fout<<'ณ'<<setw(10)<<a[i].name<<'ณ'<<setw(11)<<a[i].tipe<<'ณ'<<setw(7)<<a[i].adrs<<
'ณ'<<setw(6)<<a[i].price<<'ณ'<<setw(11)<<a[i].time<<'ณ'<<endl;
fout<<sh[4]<<endl;
fout<<"\n\n\nMin price: "<<min<<"\nMax price: "<<max;
}

void poisk (musei *p, int n)
{
char d[20];
fin.open("poisk.dat");
if(!fin){cout<<"Fail";exit(1);}
fout<<"\n\n Search name\n";
while(!fin.eof())
{
fin.getline(d,20);
if(!strcmp(d,""))
{
fout<<"\n No data for search";
continue;
}
for(int i=0; i<n; i++)
if(strcmp(p[i].name,d)==0)
{fout<<"\nณ"<<setw(10)<<p[i].name<<'ณ'<<setw(11)<<p[i].tipe<<'ณ'
<<setw(7)<<p[i].adrs<<'ณ'<<setw(6)<<p[i].price<<'ณ'<<setw(11)
<<p[i].time<<'ณ'; goto m;
}
fout<<"\n name"<<d<<"not found";
m:;
}
fin.close();
}

void main()
{ clrscr();
char filen[15];
cout<<"enter file name - ";
cin.getline(filen,15);
cout<<filen;
fout.open("res.cpp");
if(!fout){cout<<"fail";exit(1);}
int n=number(filen); cout<<n<<'\n';
vvod(a,n,max,min,filen);
shapka();
vivod(a,n);
poisk(a,n);
}