Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Задание С++ 07_10_08_.doc
Скачиваний:
25
Добавлен:
11.03.2016
Размер:
1.15 Mб
Скачать

Приложение 3

Файл exeptions.h

#pragma once

void ExeptionLetters(char* str);

void ExeptionInt(char* str);

void ExeptionFloat(char* str);

void ExeptionRange(double d,double min,double max);

void ExeptionFopen(char* str);

void ExeptionFound();

void ExeptionEmpty();

void ExeptionInvalidValue(char* str);

Файл exeptions.cpp

#include "stdafx.h"

#include "exeptions.h"

using namespace System;

using namespace System::Windows::Forms;

void ExeptionLetters(char* str)

{String^ s=gcnew String(str);

s=String::Concat("\nString\t",s,"\t must include inglish letters\n");

MessageBox::Show(s,"ExeptionLetters ");

return;

}

void ExeptionInt(char* str)

{String^ s=gcnew String(str);

s=String::Concat("\nString\t",s,"\t must include letters of digits\n");

MessageBox::Show(s,"ExeptionInt ");}

void ExeptionFloat(char* str){}

void ExeptionRange(double d,double min,double max)

{String^ s1=d.ToString();

String^ s2=min.ToString();

String^ s3=max.ToString();

s1=String::Concat("\n Value\t",s1,"\t must be latter then ",s2,"and must be greater then",s3);

MessageBox::Show(s1,"ExeptionRange");}

void ExeptionFopen(char* str)

{String^ s=gcnew String(str);

s=String::Concat("\nFile\t",s,"\t open error\n");

MessageBox::Show(s,"ExeptionFopen");}

void ExeptionInvalidValue(char* str)

{String^ s=gcnew String(str);

s=String::Concat("\nValue\t",s,"\t Invalid \n");

MessageBox::Show(s,"Invalid Value");}

void ExeptionFound()

{MessageBox::Show("Просмотр закончен. Искомый элемент не найден"

,"Поиск");}

void ExeptionEmpty()

{MessageBox::Show("Поля ввода не должны быть пустыми"

,"Input");}

Файл validator.h

#pragma once

#include "exeptions.h"

int IsLetters(char* s);

int IsInt(char* s);

int IsFloat(char* s);

int InRangeValue(double d,double min,double max);

Файл validator.cpp

#include "stdafx.h"

#include "validator.h"

int IsLetters(char* s)

{if(s==0)return 0;

for(;*s!='\0' && toupper(*s)>='A' && toupper(*s)<='Z' ;s++)

;

if (*s!='\0') {ExeptionLetters(s); return 0;}

return 1;}

int IsInt(char* s)

{if(s==0)return 0;

for(;*s!='\0' && *s>='0' && *s<='9' ;s++)

;

if (*s!='\0') {ExeptionInt(s); return 0;}

return 1;}

int IsFloat(char* s){if(s==0)return 0;

return 1;}

int InRangeValue(double d,double min,double max)

{if(d<min|| d>max)

{ExeptionRange(d,min,max); return 0;}

return 1;}

Файл win.h

int ToChar(char* out,wchar_t* in);

Файл win.cpp

#include "StdAfx.h"

#using <mscorlib.dll>

#include <windows.h>

int ToChar(char* out,wchar_t* in)

{return WideCharToMultiByte(CP_ACP, 0, in, 1,out , 1, NULL, NULL);

}

Файл MyConvert.h

#pragma once

using namespace System;

using namespace System::Windows::Forms;

class MyConvert

{

public:

static int copyto(char** ss,char buf[] );

static int copyto(int* i,char buf[]);

static int copyto(double* d,char buf[]);

static int copyto(char* s, int i);

static int copyto(char* s,double d );

static int copyto(char* buf,String^ S,int count=0);

static int copyto(char** str,String^ S);

static int copyto(String^ &S,char* buf );

static int copyto(char* m[],cli::array<String ^ >^ s,int count,int first_s=0,int first_m=0);

static int copyto(cli::array<String ^ >^ m,char* s[],int count,int first_s=0,int first_m=0);

static int copyto(cli::array<TextBox^>^ m,char* s[],int count,int first_s=0,int first_m=0);

static int copyto(char* m[],cli::array<TextBox^>^ s,int count,int first_s=0,int first_m=0);

static int copyto(cli::array<TextBox^>^ m,cli::array<String ^ >^s,int count,int first_s=0,int first_m=0);

static int copyto(cli::array<String ^ >^m, cli::array<TextBox^>^ s, int count,int first_s=0,int first_m=0);

MyConvert(void);

public:

~MyConvert(void);

};

Файл MyConvert.cpp

#include "StdAfx.h"

#include "MyConvert.h"

#include "validator.h"

#include "win.h"

int MyConvert::copyto(char** s,char buf[] )

{ //if(buf==0)return 0;

delete [](*s);

*s=new char[strlen(buf)+1];

strcpy(*s,buf);

return 1;}

int MyConvert::copyto(int* i,char buf[])

{if(IsInt(buf))

*i=atoi(buf)

;

else return 0;

return 1;}

int MyConvert::copyto(double* i,char buf[])

{return 1;}

int MyConvert::copyto(char* s, int i)

{return itoa(i,s,10) ? 1 : 0 ; }

int MyConvert::copyto(char* s,double d )

{return gcvt(d,10,s) ? 1 : 0 ; }

//#include "win.h"

int MyConvert::copyto(char* buf,System::String^ S,int count)

{int i, state;

for(i=0;i<S->Length;i++){

if(count && i>count) break;

wchar_t t=S->default[i];

state=ToChar(&buf[i],&t);

//state=WideCharToMultiByte(CP_ACP, 0, &t, 1, &buf[i], 1, NULL, NULL);

}

buf[i]='\0';

return state;}

int MyConvert::copyto(char** str,System::String^ S)

{ delete [](*str);

*str=new char [S->Length+1];

return MyConvert::copyto(*str,S);

}

int MyConvert::copyto(System::String^ &S,char* buf )

{S=gcnew System::String(buf); return 1;}

int MyConvert::copyto(char* m[],cli::array<String ^ >^ s,int count,int first_s,int first_m)

{ //if(s==0)return 0;

while(count-->0)

{ copyto(&m[first_m],s[first_s]);

++first_m;

++first_s;}

return 1;

}

int MyConvert::copyto(cli::array<String ^ >^ m,char* s[],int count,int first_s,int first_m)

{ if(s==0)return 0;

while(count-->0)

{//copyto(m[first_m],s[first_s]);

m[first_m]=gcnew System::String(s[first_s]);

++first_m;

++first_s;}

return 1;

}

int MyConvert::copyto(cli::array<TextBox^>^ m,char* s[],int count,int first_s,int first_m)

{if(s==0)return 0;

while(count-->0)

{m[first_m]->Text=gcnew String(s[first_s]);

++first_m;

++first_s;

}

return 1;

}

int MyConvert::copyto(char* m[],cli::array<TextBox^>^ s,int count,int first_s,int first_m)

{//if(s==0)return 0;

while(count-->0)

{ copyto(&m[first_m],s[first_s]->Text);

++first_m;

++first_s;

}

return 1;

}

int MyConvert::copyto(cli::array<TextBox^>^ m,cli::array<String ^ >^s,int count,int first_s,int first_m)

{ //if(s==0)return 0;

while(count-->0)

{m[first_m]->Text=s[first_s];

++first_m;

++first_s;

}

return 1;

}

int MyConvert::copyto(cli::array<String ^ >^m, cli::array<TextBox^>^ s, int count,int first_s,int first_m)

{ //if(s==0)return 0;

while(count-->0){m[first_m]=s[first_s]->Text;

++first_m;

++first_s;

}

return 1;

}

MyConvert::MyConvert(void)

{

}

MyConvert::~MyConvert(void)

{

}

Файл Obj.h

#pragma once

class MyString;

class Obj{

public:

virtual ~Obj(){}

virtual MyString* ToMyString()=0;

virtual Obj* copy()=0;

virtual void dispose ()=0;

virtual int equal(const Obj&)=0;

virtual int cmp(const Obj&)=0;

};

Файл io.h

#pragma once

#include "Obj.h"

#include "MyConvert.h"

typedef FILE* File;

int eof( File fp);

int eof();

void clear(File fp);

void clear();

int input(File fp,char* s);

int input(File fp,char* s,int lim);

int input(File fp,char** s);

int input(File fp,int* i);

int input(File fp,double* i);

int input(char* s,int* i);

int input(char* s,double* i);

int input(char* s);

int input(char** s);

int input(int* i);

int input(double* d);

int output(char* s);

int output(File fp,char* s);

int output(File fp,int i);

int output(char* s,int i);

int output(char* s,double d);

using namespace System;

using namespace System::Windows::Forms;

int input(TextBox^ t,char* s,int count);

int input(TextBox^ t,char** s);

int input(TextBox^ t,int *i);

class InOut :public Obj{

public:

virtual int input(File fp)=0;

virtual int input()=0;

virtual int output(File f)=0;

virtual int output()=0;

virtual int input (char* m[], int first=0)=0 ;

virtual int output (char* m[], int first=0)=0;

int input (cli::array<TextBox^>^ m, int count, int first=0);

int output (cli::array<TextBox^>^ m, int count, int first=0);

int output(ListView^ lis, int count);

};

Файл io.cpp

#include "stdafx.h"

#include "io.h"

#include "MyConvert.h"

#define MAX 256

char buf[MAX];

using namespace std;

int eof(FILE* fp){return feof(fp);}

int eof(){return feof(stdin); }

void clear(FILE* fp){rewind(fp);}

void clear(){rewind(stdin); }

int input(File fp,char* s)

{int state=fscanf(fp,"%s",s);

return state && state!=EOF;

}

int input(FILE* fp,char** s)

{ return input(fp,buf) && MyConvert::copyto(s,buf); }

int output(FILE* fp,char* s)

{return fprintf(fp,"%s\n",s);}

int output(File fp,int i)

{return fprintf(fp,"%d\n",i);}

int output(char* s,int i)

{return sprintf(s,"%d",i);}

int output(char* s,double d)

{return sprintf(s,"%f",d);}

int input(FILE* fp,int* i)

{return input( fp,buf) && MyConvert::copyto(i,buf);}

int input(FILE* fp,double* i)

{return 1;}

int input(char* s) {return input(stdin,s);}

int input(char** s) {return input(stdin,s);}

int input(int* i) {return input(stdin,i);}

int input(double* d){return input(stdin,d);}

int output(char* s) {return output(stdout,s);}

int input(FILE* fp,char* s,int lim)

{ int c;

while((c=getc(fp)) !=EOF && isspace(c))

;

if(c==EOF) return 0;

*s++=c;--lim;

while(--lim>0 && (c=getc(fp)) !=EOF && !isspace(c))

*s++=c;

*s='\0';

return (c== EOF||lim==0)? 0 :1;

}

using namespace System;

using namespace System::Windows::Forms;

int input(TextBox^ t,char* s,int count)

{return MyConvert::copyto(s,t->Text,count);

}

int input(TextBox^ t,char** s)

{ return input( t,buf,MAX) && MyConvert::copyto(s,buf); }

int input(TextBox^ t,int *i)

{return input( t,buf,MAX) && MyConvert::copyto(i,buf);}

class Buff{

char** ms;

int count;

public:

char**get(){return ms;}

Buff(int _count,int max)

{ ms=new char*[count=_count];

for(int i=0;i<count;i++)

ms[i]=new char[max];

}

~Buff()

{for(int i=0;i<count;i++)

delete [] ms[i];

delete []ms;

}

};

int InOut::input (cli::array<TextBox^>^ m, int count, int first)

{Buff b(count,MAX);

MyConvert::copyto(b.get(),m,count,first,0);

return input(b.get());

}

int InOut::output (cli::array<TextBox^>^ m, int count, int first)

{Buff b(count,MAX);

int state= output(b.get());

MyConvert::copyto(m,b.get(),count,0,first);

return state;

}

int InOut::output(ListView^list, int count)

{Buff b(count,MAX);

int state=output(b.get());

cli::array<String ^ >^m=gcnew cli::array< System::String^ >(count);

//String* m[]=new String*[count];

MyConvert::copyto(m,b.get(),count);

list->Items->Add(gcnew ListViewItem(m));

return state;

}

Файл MyString.h

#pragma once

#include "io.h"

class MyString: public InOut

{char* s;

int len;

public:

MyString(void);

MyString (char* s);

MyString (const MyString& );

void assign (const MyString& t);

~MyString(void);

void dispose ();

MyString* copy();

int length(){return len;}

int length()const

{return len;}

char* ToPchar();

int ToInt();

double ToDouble();

String^ ToString();

MyString* ToMyString();

int equal(const MyString& t);

int cmp(const MyString& t);

int equal(const Obj& t);

int cmp(const Obj& t);

int input (char* m[], int first=0) ;

int output(char* m[], int first=0);

int input(File fp) ;

int input() ;

int output(File f);

int output();

int input(TextBox^ t);

};

Файл MyString.cpp

#include "StdAfx.h"

#include "MyString.h"

#include "MyConvert.h"

MyString::MyString(void)

{s=0; len=0;}

MyString::~MyString(void)

{dispose() ;

}

void MyString::dispose()

{delete [] s;}

MyString::MyString (char* ss)

{if(ss==0){s=0; len=0;return ;}

s=new char[(len=strlen(ss))+1];

strcpy(s,ss);

}

MyString::MyString(const MyString& t)

{s=new char[(len=t.len)+1];

strcpy(s,t.s);

}

void MyString::assign (const MyString& t)

{if(this==&t)return;

char*ss=new char[(len=t.len)+1];

strcpy(ss,t.s);

delete [] s;

s=ss;

}

MyString* MyString::copy()

{return new MyString(*this);}

char* MyString::ToPchar()

{if(s==0)return 0;

char* ss=new char[len+1];

strcpy(ss,s);

return ss;}

MyString* MyString::ToMyString(){return new MyString(*this);}

int MyString::ToInt()

{int i;

MyConvert::copyto(&i,s);

return i;}

double MyString::ToDouble()

{double d;

MyConvert::copyto( &d,s);

return d;}

String^ MyString::ToString()

{return gcnew String(s);}

int MyString::equal(const MyString& ss)

{return strcmp(s,ss.s)==0;}

int MyString::cmp(const MyString& ss)

{return strcmp(s,ss.s);}

int MyString::equal(const Obj& t)

{return equal((const MyString&)t);}

int MyString:: cmp(const Obj& t)

{return cmp((const MyString&)t);}

int MyString::input(File f)

{ if(::input(f,&s))

return len=strlen(s);

return 0;}

int MyString::input()

{ if(::input(&s))

return len=strlen(s);

return 0;}

int MyString::input(TextBox^ t)

{if(::input(t,&s))

return len=strlen(s);

return 0;}

int MyString::output(File f )

{return ::output(f,s);}

int MyString::output()

{return ::output(s);}

int MyString::input (char* m[], int first)

{char*ss=new char[(len=strlen(m[first]))+1];

strcpy(ss,m[first]);

delete [] s;

s=ss;

return len;}

int MyString::output(char* m[], int first)

{delete [] m[first];

m[first]=new char[len+1];

strcpy(m[first],s);

return len;}

Файл MyDate.h

#pragma once

#include "io.h"

#include "MyString.h"

class MyDate:public InOut

{ int day,month,year;

static int daytab[2][13];

static char* MonthName[13];

static char* DayNames[8];

public:

MyDate(void);

int get_day(){return day;}

int get_month(){return month;}

int get_year(){return year;}

int get_day()const

{return day;}

int get_month()const

{return month;}

int get_year()const

{return year;}

public:

~MyDate(void);

MyDate(int d,int m,int y);

MyDate (char* s);

MyDate (const MyDate& );

void assign (const MyDate& t);

void dispose ();

MyDate* copy();

int validate();

static int vis(int y)

{ return ((!(y%4))&&(y%100)||(!(y%400))); }

char* ToPchar();

String^ ToString();

MyString* ToMyString(){return new MyString(ToPchar());}

int equal(const MyDate& t);

int cmp(const MyDate& t);

int equal(const Obj& t);

int cmp(const Obj& t);

int input (char* m[], int first=0) ;

int output(char* m[], int first=0);

int input(File fp) ;

int input() ;

int output(File f);

int output();

int input(TextBox^ t1, TextBox^ t2, TextBox^ t3) ;

};

Файл MyDate.cpp

#include "StdAfx.h"

#include "MyDate.h"

#include "exeptions.h"

#include "MyConvert.h"

int MyDate::daytab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};

char* MyDate::MonthName[13]={"Wrong month","January","February","March","April","May","June","July","August","September","October","November","December"};

char* MyDate::DayNames[8]={"Wrong day","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

MyDate::MyDate(void)

{day=month=year=0;

}

MyDate::~MyDate(void)

{ }

MyDate::MyDate(int d,int m,int y)

{

day=d;

month=m;

year=y;

if(!validate()) ExeptionInvalidValue("MyDate");

}

int MyDate::validate()

{

return (year>0&&month>0&&month<=12&&day>0&&day<=daytab[vis(year)][month]);

}

MyDate::MyDate (char* s){}

MyDate::MyDate (const MyDate& d)

{day=d.day;

month=d.month;

year=d.year;}

void MyDate::assign (const MyDate& d)

{day=d.day;

month=d.month;

year=d.year;}

void MyDate::dispose (){}

MyDate* MyDate::copy()

{return new MyDate();}

char* MyDate::ToPchar()

{char s[256],buf[256],*s1;

s[0]='\0';

itoa(day,buf,10); strcat(s,buf); strcat(s,".");

itoa(month,buf,10); strcat(s,buf); strcat(s,".");

itoa(year,buf,10); strcat(s,buf);

s1=new char[strlen(s)+1];

strcpy(s1,s);

return s1;}

String^ MyDate::ToString()

{return gcnew String(ToPchar());}

int MyDate::equal(const MyDate& d)

{return day==d.day && month==d.month && year==d.year;}

int MyDate::cmp(const MyDate& d)

{if(year!=d.year)return year-d.year;

else if(month!=d.month)return month-d.month;

else return day-d.day;

}

int MyDate::equal(const Obj& t)

{return equal((const MyDate&)t);}

int MyDate::cmp(const Obj& t)

{return cmp((const MyDate&)t);}

int MyDate::input (char* m[], int first)

{MyConvert::copyto(&day,m[first++]);

MyConvert::copyto(&month,m[first++]);

MyConvert::copyto(&year,m[first++]);

return 3;}

int MyDate::output(char* m[], int first)

{MyConvert::copyto(m[first++],day);

MyConvert::copyto(m[first++],month);

MyConvert::copyto(m[first++],year);

return 3;}

int MyDate::input(File fp)

{int state=1;

state*=::input(fp,&day); if(eof( fp)) return 0;

state*=::input(fp,&month); if(eof( fp)) return 0;

state*=::input(fp,&year); if(eof( fp)) return 0;

return state;}

int MyDate::input()

{int state=1;

::output( "day");

state*=::input(&day); if(eof( )) return 0;

::output("month");

state*=::input(&month); if(eof( )) return 0;

::output("year");

state*=::input(&year); if(eof( )) return 0;

return state;}

int MyDate::output(File f)

{return fprintf(f,"%d\t%d\t%d\n",

day,month,year);

}

int MyDate::output()

{return output(stdin);}

int MyDate::input(TextBox^ t1, TextBox^ t2, TextBox^ t3)

{int state=1;

state*=::input(t1,&day) ;

state*=::input(t2,&month) ;

state*=::input(t3,&year ) ;

return state;}

Файл compare.h

#pragma once

#include "Obj.h"

struct ParamSort {

char* FieldName[3];

int DirectCond[3];

ParamSort()

{for(int i=0;i<3;i++)

{FieldName[i]=0;DirectCond[i]=0;}

}

};

struct InRange {

Obj* Min,*Max;

char*s;

InRange(Obj* m1, Obj* m2,char* s0): Min(m1),Max(m2), s(s0){}

};

Файл Record.h

#pragma once

#include "compare.h"

#include "io.h"

class Record : public InOut

{public:

virtual int CmpField(const Obj& obj,char*s)=0;

virtual int CountFields()=0;

//virtual char** NamesFields()=0;

int InRangeValue(InRange* param);

static int CmpParamSort( Obj* a, Obj* b,ParamSort* p);

public:

Record(void);

public:

~Record(void);};

class Compare{

public:

virtual int cmp( Obj* a, Obj* b)=0;

};

class Compare1: public Compare {

ParamSort* param;

public: int cmp( Obj* a, Obj* b)

{return Record::CmpParamSort(a,b,param);}

Compare1(ParamSort* p):param(p){}

};

class Predicat{

public:

virtual bool fun( Obj* item)=0;

};

class Predicat1: public Predicat{

InRange* param;

public: bool fun( Obj* item){return ((Record*)item)->InRangeValue(param);}

Predicat1 (InRange* p):param(p){}

};

Файл Record.cpp

#include "StdAfx.h"

#include "Record.h"

int Record::InRangeValue(InRange* param)

{return CmpField((Obj&)(*(param->Min)),param->s)>=0 && CmpField((Obj&)(*(param->Max)),param->s)<=0 ;}

int Record::CmpParamSort( Obj* aa, Obj* bb,ParamSort* p)

{ Record* a= (Record*)aa;

Record* b= (Record*)bb;

if(a->CmpField(*b,p->FieldName[0])!=0)

if(p->DirectCond[0]==1) return a->CmpField(*b,p->FieldName[0])>0;

else return a->CmpField(*b,p->FieldName[0])<0;

else if(a->CmpField(*b,p->FieldName[1])!=0)

if(p->DirectCond[1]==1) return a->CmpField(*b,p->FieldName[1])>0;

else return a->CmpField(*b,p->FieldName[1])<0;

else if(a->CmpField(*b,p->FieldName[2])!=0)

if(p->DirectCond[2]==1) return a->CmpField(*b,p->FieldName[2])>0;

else return a->CmpField(*b,p->FieldName[2])<0;

}

Record::Record(void)

{

}

Record::~Record(void)

{

}

Файл Book.h

#pragma once

#include "io.h"

#include "Record.h"

#include "MyString.h"

#include "MyDate.h"

class Book:public Record

{

MyString autor;

MyString title;

int number;

int price;

public:

Book(); //выделяет память под класс Record

//и инициализирует ее значениями по умолчанию

Book(char*a,char*t,int n,int p);

Book(const Book&);

~Book();

MyString* ToMyString(){return new MyString("Book");}

Book* copy(); //coздает копию структуры Record в динамической памяти

void dispose (); // Освобождает выделенную память под структур Record

int validate(); // проверяет корректность данных

int equal(const Book&); // функция, проверяющая равенство значений полей записей

//Используется при поиске

int cmp(const Book&); // функция, сравнивающая записи Используется при сортировки

friend int CmpField(Book* a,Book* b,char*s);

int CmpField(const Obj& obj,char*s);

int CountFields() {return 4;}

int equal(const Obj&);

int cmp(const Obj&);

int finput(File f);

int input(File fp) ;

int input() ;

int output(File f);

int output();

int input (char* m[], int first=0) ;

int output(char* m[], int first=0);

};

Файл Book.cpp

#include "StdAfx.h"

#include "Book.h"

#include "MyConvert.h"

#include ".\validator.h"

Book::Book() // инициализирует значениями по умолчанию

{ number=0;

price=0;

}

Book::Book(char*a,char*t,int n,int p):autor(a),title(t)

{

number=n;

price=p;

}

Book::Book(const Book& t) //coздает копию структуры Book в динамической памяти

{autor.assign(t.autor);

title.assign(t.title);

number=t. number;

price=t.price;

}

Book* Book:: copy()

{return new Book(*this);}

void Book::dispose () // Освобождает выделенную память

{}

Book::~Book()

{ dispose(); }

int Book::equal( const Book& r)

{ return

((r.autor.length()!=0)? autor.equal(r.autor) :1)&&

((r.title.length()!=0)? title.equal(r.title) :1)&&

((r.price !=0)? r.price == price :1) &&

((r.number !=0)? r.number== number :1)

;

}

int Book::cmp(const Book& t) // функция, сравнивающая записи

{int cond;

MyString s1(t.autor);

MyString s2(t.autor);

if(s1.length()!=0&& (cond=autor.cmp(t.autor)))return cond;

else if(s2.length()!=0&& (cond=title.cmp(t.title)))return cond;

else return number-t.number;

}

int Book::equal(const Obj& t)

{return equal((const Book&) t);}

int Book::cmp(const Obj& t)

{return cmp((const Book&) t);}

int CmpField(Book* a,Book* b,char*s)

{if (!strcmp(s,"autor")) return a->autor.cmp(b->autor);

else if(!strcmp(s,"title")) return a->title.cmp(b->title);

else if (!strcmp(s,"price")) return a->price-b->price;

else if (!strcmp(s,"number")) return a->number-b->number;

}

int Book::CmpField(const Obj& obj,char*s)

{return ::CmpField(this,(Book*)&obj,s);}

int Book::finput(File f)

{

int state=autor.input(f);

state&=title.input(f);

return state;

}

int Book::validate( )// проверяет корректность данных

{ int a,b;

char* s1=autor.ToPchar();

char* s2=title.ToPchar();

a=IsLetters(s1);

if(!a)

return 0;

b=IsLetters(s2);

if(!b)

return 0;

return 1 ;}

int Book::input(File fp )

{int state=1;

state*=autor.input(fp); if(eof( fp)) return 0;

state*=title.input(fp); if(eof( fp)) return 0;

state*=::input(fp,&number); if(eof( fp)) return 0;

state*=::input(fp,&price); if(eof( fp)) return 0;

state*=validate();

return (state==0)? 0: 4;}

int Book::input()

{int state=1;

::output("autor");

state*=autor.input(); if(eof( )) return 0;

::output( "title");

state*=title.input(); if(eof( )) return 0;

::output( "number");

state*=::input(&number); if(eof( )) return 0;

::output( "price");

state*=validate();

return (state==0)? 0: 4;}

int Book::output(File f)

{

autor.output(f);

title.output(f);

::output(f,number);

::output(f,price);

return 4;

}

int Book::output()

{return output(stdout);}

int Book::input (char* m[], int first)

{int state=1;

state*=autor.input(m,first++) ;

state*=title.input(m,first++) ;

state*=MyConvert::copyto(&number,m[first++]);

state*=MyConvert::copyto(&price,m[first++]);

state*=validate() ;

return (state==0)? 0: 4;}

int Book::output(char* m[], int first)

{m[first++]=autor.ToPchar();

m[first++]=title.ToPchar();

::output(m[first++],number);

::output(m[first++],price);

return 4;

}

Файл Record.h

#pragma once

#include "io.h"

#include "Record.h"

#include "MyString.h"

#include "MyDate.h"

class Reader:public Record

{

MyString name;

MyString address;

int number;

int telephon;

public:

Reader(); //выделяет память под класс Reader

//и инициализирует ее значениями по умолчанию

Reader(char*n,char*a,int nn,int t);

Reader(const Reader&);

~Reader();

MyString* ToMyString(){return new MyString("Reader");}

Reader* copy(); //coздает копию структуры Reader в динамической памяти

void dispose (); // Освобождает выделенную память под структур Reader

int validate(); // проверяет корректность данных

int equal(const Reader&); // функция, проверяющая равенство значений полей записей

//Используется при поиске

int cmp(const Reader&); // функция, сравнивающая записи Используется при сортировки

friend int CmpField(Reader* a,Reader* b,char*s);

int CmpField(const Obj& obj,char*s);

int CountFields(){return 4;}

int equal(const Obj&);

int cmp(const Obj&);

int finput(File f);

int input(File fp) ;

int input() ;

int output(File f);

int output();

int input (char* m[], int first=0) ;

int output(char* m[], int first=0);

};

Файл Record.cpp

#include "StdAfx.h"

#include "Reader.h"

#include "MyConvert.h"

#include ".\validator.h"

Reader::Reader() // инициализирует значениями по умолчанию

{ number=0;

telephon=0;

}

Reader::Reader(char*n,char*a,int nn,int t):name(n),address(a)

{number=nn;

telephon=t;

}

Reader::Reader(const Reader& t) //coздает копию структуры Reader в динамической памяти

{name.assign(t.name);

address.assign(t.address);

number=t. number;

telephon=t.telephon;

}

Reader* Reader:: copy()

{return new Reader(*this);}

void Reader::dispose () // Освобождает выделенную память

{}

Reader::~Reader()

{ dispose(); }

int Reader::equal( const Reader& r)

{ return

((r.name.length()!=0)? name.equal(r.name) :1)&&

((r.address.length()!=0)? address.equal(r.address) :1)&&

((r.telephon !=0)? r.telephon == telephon :1) &&

((r.number !=0)? r.number== number :1)

;

}

int Reader::cmp(const Reader& t) // функция, сравнивающая записи

{int cond;

MyString s1(t.name);

MyString s2(t.name);

if(s1.length()!=0&& (cond=name.cmp(t.name)))return cond;

else if(s2.length()!=0&& (cond=address.cmp(t.address)))return cond;

else return number-t.number;

}

int Reader::equal(const Obj& t)

{return equal((const Reader&) t);}

int Reader::cmp(const Obj& t)

{return cmp((const Reader&) t);}

int CmpField(Reader* a,Reader* b,char*s)

{if (!strcmp(s,"name")) return a->name.cmp(b->name);

else if(!strcmp(s,"address")) return a->address.cmp(b->address);

else if (!strcmp(s,"telephon")) return a->telephon-b->telephon;

else if (!strcmp(s,"number")) return a->number-b->number;

}

int Reader::CmpField(const Obj& obj,char*s)

{return ::CmpField(this,(Reader*)&obj,s);}

int Reader::finput(File f)

{

int state=name.input(f);

state&=address.input(f);

return state;

}

int Reader::validate( )// проверяет корректность данных

{ int a,b;

a=IsLetters( name.ToPchar());

b= IsLetters( address.ToPchar());

return a && b ;}

int Reader::input(File fp )

{int state=1;

state*=name.input(fp); if(eof( fp)) return 0;

state*=address.input(fp); if(eof( fp)) return 0;

state*=::input(fp,&number); if(eof( fp)) return 0;

state*=::input(fp,&telephon); if(eof( fp)) return 0;

state*=validate();

return (state==0)? 0: 4;}

int Reader::input()

{int state=1;

::output("name");

state*=name.input(); if(eof( )) return 0;

::output( "address");

state*=address.input(); if(eof( )) return 0;

::output( "number");

state*=::input(&number); if(eof( )) return 0;

::output( "telephon");

state*=validate();

return (state==0)? 0: 4;}

int Reader::output(File f)

{

name.output(f);

address.output(f);

::output(f,number);

::output(f,telephon);

return 4;

}

int Reader::output()

{return output(stdout);}

int Reader::input (char* m[], int first)

{int state=1;

state*=name.input(m,first++) ;

state*=address.input(m,first++) ;

state*=MyConvert::copyto(&number,m[first++]);

state*=MyConvert::copyto(&telephon,m[first++]);

state*=validate() ;

return (state==0)? 0: 4;}

int Reader::output(char* m[], int first)

{m[first++]=name.ToPchar();

m[first++]=address.ToPchar();

::output(m[first++],number);

::output(m[first++],telephon);

return 4;

}

Файл Library.h

#pragma once

#include "io.h"

#include "Record.h"

#include "MyString.h"

#include "MyDate.h"

#include "Reader.h"

#include "Book.h"

class Library:public Record

{ Book* b;

Reader* r;

MyString bibl;

MyDate d;

public:

Library(); //выделяет память под класс Library

//и инициализирует ее значениями по умолчанию

Library(char*a,int d,int m,int y,Reader* r=0,Book* b=0);

Library(const Library&);

~Library();

MyString* ToMyString(){return new MyString("Library");}

Library* copy(); //coздает копию структуры Library в динамической памяти

void dispose (); // Освобождает выделенную память под структур Library

int validate(); // проверяет корректность данных

int equal(const Library&); // функция, проверяющая равенство значений полей записей

//Используется при поиске

int cmp(const Library&); // функция, сравнивающая записи Используется при сортировки

friend int CmpField(Library* a,Library* b,char*s);

int CmpField(const Obj& obj,char*s);

int CountFields(){return 4;}

int equal(const Obj&);

int cmp(const Obj&);

int finput(File f);

int input(File fp) ;

int input() ;

int output(File f);

int output();

int input (char* m[], int first=0) ;

int output(char* m[], int first=0);

};

Файл Library.cpp

#include "StdAfx.h"

#include "Library.h"

#include "MyConvert.h"

#include ".\validator.h"

Library::Library() // инициализирует значениями по умолчанию

{r=0;b=0;

}

Library::Library(char*a,int d0,int m,int y,Reader* pr,Book* pb):bibl(a),d(d0,m,y)

{ r=pr; b=pb;

}

Library::Library(const Library& t) :bibl(t.bibl),d(t.d),r(t.r),b(t.b)

//coздает копию структуры Library в динамической памяти

{//bibl.assign(t.bibl);

//d.assign(t.d);

}

Library* Library:: copy()

{return new Library(*this);}

void Library::dispose () // Освобождает выделенную память

{}

Library::~Library()

{ dispose(); }

int Library::equal( const Library& l)

{ return

((l.b!=0)? b->equal(*l.b) :1)&&

((l.r!=0)? r->equal(*l.r) :1)&&

((l.bibl.length()!=0)? bibl.equal(l.bibl) :1)&&

(((l.d.get_day() !=0) && (l.d.get_month() !=0) && (l.d.get_year() !=0))?

d.equal(l.d):1);

}

int Library::cmp(const Library& t) // функция, сравнивающая записи

{int cond;

MyString s(t.bibl);

if ((t.b)&& (cond=b->cmp(*t.b))) return cond;

else if((t.r)&& (cond=r->cmp(*t.r))) return cond;

else if(s.length()!=0&& (cond=bibl.cmp(t.bibl)))return cond;

else if( (cond=d.cmp(t.d)))return cond;

}

int Library::equal(const Obj& t)

{return equal((const Library&) t);}

int Library::cmp(const Obj& t)

{return cmp((const Library&) t);}

int CmpField(Library* l1,Library* l2,char*s)

{if (!strcmp(s,"book")) return l1->b->cmp(*l2->b);

else if (!strcmp(s,"reader")) return l1->r->cmp(*l2->r);

else if (!strcmp(s,"bibl")) return l1->bibl.cmp(l2->bibl);

else if(!strcmp(s,"date")) return l1->d.cmp(l2->d);

}

int Library::CmpField(const Obj& obj,char*s)

{return ::CmpField(this,(Library*)&obj,s);}

int Library::finput(File f)

{

int state=b->input(f);

state&=r->input(f);

state&=bibl.input(f);

state&=d.input(f);

return state;

}

int Library::validate( )// проверяет корректность данных

{ int a,c,r0,b0;

b0=b->validate();

r0=r->validate();

a=IsLetters( bibl.ToPchar());

c=d.validate();

return b0 &&r0&& a && c;}

int Library::input(File fp )

{int state=1;

b=new Book;

r=new Reader;

state*=b->input(fp); if(eof( fp)) return 0;

state*=r->input(fp); if(eof( fp)) return 0;

state*=bibl.input(fp); if(eof( fp)) return 0;

state*=d.input(fp); if(eof( fp)) return 0;

state*=validate();

return state;}

int Library::input()

{

int state=1;

b=new Book;

r=new Reader;

state*=b->input(); if(eof( )) return 0;

state*=r->input(); if(eof( )) return 0;

::output("bibl");

state*=bibl.input(); if(eof( )) return 0;

::output( "data");

state*=d.input(); if(eof( )) return 0;

state*=validate();

return state;}

int Library::output(File f)

{

int state=1;

state&=b->output(f);

state&=r->output(f);

state&=bibl.output(f);

state&=d.output(f);

return state;

}

int Library::output()

{return output(stdout);}

int Library::input (char* m[], int first)

{int state=1,f=first;

b=new Book;

r=new Reader;

state*=b->input(m,first) ;

first+=b->CountFields();

state*=r->input(m,first) ;

first+=r->CountFields();

state*=bibl.input(m,first++) ;

state*=d.input(m,first);

first+=3;

state*=validate() ; ;

return (state==0)? 0: first-f ;}

int Library::output(char* m[], int first)

{int f=first;

Book* bb;

Reader* rr;

if(b==0)

{bb=new Book;

first+=bb->output(m,first);

delete bb;}

else first+=b->output(m,first);

if(r==0)

{rr=new Reader;

first+=rr->output(m,first);

delete rr;}

else first+=r->output(m,first);

m[first++]=bibl.ToPchar();

first+=d.output(m,first);

return first-f;

}

Файл item.h

#pragma once

#include "Obj.h"

typedef Obj* T;

typedef T* Iterator;

Файл algo.h

//алгоритмы

#pragma once

#include "item.h"

#include "Record.h"

Iterator find( const Iterator& first,const Iterator& last,const T& item);

Iterator find(const Iterator& first,const Iterator& last,Predicat &pred);

int replace(const Iterator& first,const Iterator& last,const T&Old,const T&New);

void sort(const Iterator& first,const Iterator& last,Compare &Comp );

Файл algo.h

#pragma once

#include "stdafx.h"

#include "algo.h"

Iterator find( const Iterator& first,const Iterator& last,const T& item)

{Iterator i;

for(i=first;i<last;i++)

if( (*i)->equal(*item)) return i;

return last;

}

Iterator find(const Iterator& first,const Iterator& last,Predicat &pred)

{Iterator i;

for(i=first;i<last;i++)

if(pred.fun(*i)) return i;

return last;

}

int replace(const Iterator& first,const Iterator& last,const T&Old,const T&New)

{Iterator i;int count=0;

for(i=first;i<last;i++)

if( (*i)->equal(*Old))

{ (*i)->dispose();

*i=New->copy();

count++;}

return count;

}

void sort(const Iterator& first,const Iterator& last,Compare &Comp )

{

Iterator i;

Iterator j;

T tmp;int k=0;

for(i=first;i<last;i++,k++)

{

for(j=first+1;j<last-k;j++)

if (Comp.cmp(*(j-1),*j))

{tmp=*(j-1);*(j-1)=*j;*j=tmp;}

}

}

Файл vec.h

#pragma once

#include "item.h"

class vec

{ T* start;

T* finish;

public:

vec(void){start=new T[100];finish=start+100;}

vec(int sz){start=new T[sz];finish=start+sz;}

~vec(void){delete [] start;}

void resize(int n)

{T* _start;

T* _finish;

_start=_finish=new T[ finish-start+n];

T* i;

for( i=start;i<=finish;i++)

*_finish++=*i;

delete [] start;

start=_start; finish=_finish;

}

T* begin(void){return start;}

T* end(void){return finish;}

int get_size(void){return finish-start;}

T& get_item(int i){return *(begin()+i);}

};

Файл Tabl.h

#pragma once

#include "item.h"

#include "io.h"

#include "Record.h"

#include "vec.h"

class Tabl{

vec v;

Iterator cur;

T buf;

public:

Tabl( int sz=100,T buffer=0);

~Tabl( );

void resize(int n);

void clear();

void dispose ();

Iterator begin();

Iterator end() ;

int length();

T get_item(int i);

Iterator insert(const T& item);

Iterator erase(Iterator pos);

int remove(const T& item);

void output();

int input();

int input(File f);

void output(File f);

void foutput(char* FileName);

int finput(char* FileName);

Tabl* Query(Predicat& pred);

int remove(Predicat &pred);

void output(ListView^list,int count);

};

Файл Tabl.cpp

#include "stdafx.h"

#include "validator.h"

#include "Tabl.h"

#include "MyConvert.h"

T* Tabl::begin(){return v.begin();}

T* Tabl::end() {return cur;}

T Tabl::get_item(int i){return v.get_item(i);}

int Tabl::length(){return cur-begin();}

Tabl::Tabl( int sz,T buffer):v(sz)

{buf=buffer;

cur=begin();

}

void Tabl::clear( )

{T* i;

for( i=begin();i<cur;i++)

{(*i)->dispose();

delete (*i);}

cur=begin();

}

void Tabl::dispose ()

{clear();

delete buf;}

Tabl::~Tabl( ){dispose ();}

T* Tabl::insert(const T& item)

{if(length()>v.get_size())

{ int len= length(); v.resize(2*len); cur=begin()+len;}

*cur++=item->copy();

return cur;

}

T* Tabl::erase(T* pos)

{ T* i;

(*pos)->dispose();

delete (*pos);

for( i=pos;i<cur;i++)

*i=*(i+1);

cur--;

return pos;}

int Tabl::remove(const T& item)

{T* i;

T* j=begin(); int n=0;

for( i=begin();i<cur;i++)

if(! (*i)->equal(*item))

*j++=*i;

else { (*i)->dispose();

delete (*i);

n++;}

cur=j;

return n;

}

void Tabl::output()

{T* i;

for(i=begin();i!=end();i++)

((InOut*) (*i))->output();}

int Tabl::input()

{while(!eof( ) )

if(((InOut*)buf)->input ())

insert((T)buf);

return length();

}

int Tabl::input(File f)

{

while(!eof( f ) )

if(((InOut*)buf)->input (f))

insert((T)buf);

return length();

}

void Tabl::output(File f)

{T* i;

for(i=begin();i!=end();i++)

((InOut*) (*i))->output(f);

}

void Tabl::foutput(char* FileName)

{File f;

if ((f=fopen(FileName,"w"))==0)

{ ExeptionFopen(FileName); return ;}

output(f);

fclose(f);

}

int Tabl::finput(char* FileName)

{int count; File f;

if( (f =fopen(FileName,"r"))==0)

{ ExeptionFopen(FileName); return 0;}

count=input(f);

fclose(f);

return count;

}

Tabl* Tabl::Query(Predicat& pred)

{Tabl* rez=new Tabl(v.get_size());

T* i;

for( i= begin();i<end();i++)

if(pred.fun(*i))

rez->insert(*i);

return rez;

}

int Tabl::remove(Predicat &pred)

{T* i;

T* j=begin(); int n=0;

for( i=begin();i<cur;i++)

if(!(pred.fun(*i)))

*j++=*i;

else { (*i)->dispose();

delete i;

n++;}

cur=j;

return n;

}

void Tabl::output(ListView^list,int count)

{list->Items->Clear();

for(T* i=begin();i<end();i++)

((InOut*)(*i))->output(list,count);

}

Файл Sort.h

#pragma once

#include "MyConvert.h"

#include "compare.h"

using namespace System;

using namespace System::ComponentModel;

using namespace System::Collections;

using namespace System::Windows::Forms;

using namespace System::Data;

using namespace System::Drawing;

namespace Book_Lib_List_View_2005 {

public ref class Sort : public System::Windows::Forms::Form

{

public:

Sort(void)

{

InitializeComponent();

//

//TODO: Add the constructor code here

//

}

protected:

/// <summary>

/// Clean up any resources being used.

/// </summary>

~Sort()

{

if (components)

{

delete components;

}

}

public:

struct ParamSort *p;

char** Filds;

int count;

void getParam(ParamSort *pp,char** Filds0,int count0)

{p=pp; Filds=Filds0;count=count0;}

private: System::Void Sort_Load(System::Object^ sender, System::EventArgs^ e) {

for(int i=0;i<count;i++)

{comboBox1->Items->Add(gcnew String(Filds[i]));

comboBox2->Items->Add(gcnew String(Filds[i]));

comboBox3->Items->Add(gcnew String(Filds[i]));

}

comboBox1->SelectedIndex=0;

comboBox2->SelectedIndex=0;

comboBox3->SelectedIndex=0;

radioButton1->Checked=true;

radioButton4->Checked=true;

radioButton6->Checked=true;

}

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

String^s;

s=Convert::ToString(comboBox1->SelectedItem);

MyConvert::copyto(& p->FieldName[0],s);

s=Convert::ToString(comboBox2->SelectedItem);

MyConvert::copyto(& p->FieldName[1],s);

s=Convert::ToString(comboBox3->SelectedItem);

MyConvert::copyto(& p->FieldName[2],s);

p->DirectCond[0]=(radioButton1->Checked)?1:0;

p->DirectCond[1]=(radioButton4->Checked)?1:0;

p->DirectCond[2]=(radioButton6->Checked)?1:0;

this->Close();

}

};

}

Файл FQuery2.h

#pragma once

struct Range{

int MinValue,MaxValue;

};

namespace Book_Lib_List_View_2005 {

public ref class FQuery2 : public System::Windows::Forms::Form

{

public:

FQuery2(void)

{

InitializeComponent();

}

protected:

/// <summary>

/// Clean up any resources being used.

/// </summary>

~FQuery2()

{

if (components)

{

delete components;

}

}

struct Range*p;

public: void getParam(Range*pp)

{p=pp;}

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

p->MinValue=Convert::ToInt32(textBox1->Text);

p->MaxValue=Convert::ToInt32( textBox2->Text);

this->Close();

}

};

}

Файл Form2.h

#pragma once

#include "stdafx.h"

#include "exeptions.h"

#include "Tabl.h"

#include "FQuery2.h"

#include "Sort.h"

#include "algo.h"

#include "Book.h"

namespace Book_Lib_List_View_2005 {

InOut* _Bcurrent,*_Bfound;

Iterator Bfound;

char* BFileName;

using namespace System;

public ref class Form2 : public System::Windows::Forms::Form

{

public:

Form2(void)

{

InitializeComponent();

}

protected:

/// <summary>

/// Clean up any resources being used.

/// </summary>

~Form2()

{

if (components)

{

delete components;

}

}

public:

public:Tabl* t;

// TextBox* m[];

cli::array<TextBox^>^ m;

int Count;

private: int _foundNext, flag, SelectIndex;

Book* b;

private: System::Void Add_Click(System::Object^ sender, System::EventArgs^ e) {

if(!_Bcurrent->input( m,Count)) {ExeptionEmpty();return;}

t->insert(_Bcurrent);

t->output(listView1,Count);

}

private: System::Void Delete_Click(System::Object^ sender, System::EventArgs^ e) {

_Bcurrent->input( m,Count);

int i=t->remove(_Bcurrent);

if(i)

{_Bcurrent->output( m,Count);t->output(listView1,Count);}

}

private: System::Void Find_Click(System::Object^ sender, System::EventArgs^ e) {

_Bfound->input( m,Count);

Bfound=find(t->begin(),t->end(),_Bfound);

if( Bfound!=t->end())

((InOut*) (*Bfound))->output( m,Count);

else { ExeptionFound(); }

}

private: System::Void Find_Next_Click(System::Object^ sender, System::EventArgs^ e) {

if(Bfound==t->end()) return;

Bfound=find(++Bfound,t->end(),_Bfound);

if( Bfound!=t->end())

((InOut*) (*Bfound))->output( m,Count);

else { ExeptionFound(); }

}

private: System::Void Replace_Click(System::Object^ sender, System::EventArgs^ e) {

if(flag==0)

{ if(!_Bfound->input( m,Count)){ExeptionEmpty();return;}

flag=1;

MessageBox::Show("Введите данные для замены и нажмите кнопку Заменить еще раз","Поиск");

return;}

if(!_Bcurrent->input( m,Count)){ExeptionEmpty();return;}

{flag=0;

replace(t->begin(),t->end(),_Bfound,_Bcurrent);

t->output(listView1,Count);

}

}

private: System::Void Clear_Click(System::Object^ sender, System::EventArgs^ e) {

_Bcurrent->dispose();

_Bcurrent=new Book;

_Bcurrent->output( m,Count);

}

private: System::Void Form2_Load(System::Object^ sender, System::EventArgs^ e) {

Book*tmp =new Book;

Count=tmp->CountFields();

_Bcurrent=tmp;

_Bfound=new Book;

t=new Tabl(100,_Bfound);

BFileName=0;

_foundNext=-1;flag=0;

m=gcnew cli::array<TextBox^>(Count);

// m=new TextBox*[Count];

m[0]=textBox5;m[1]=textBox6;m[2]=textBox7; m[3]=textBox8 ;

}

private: System::Void listView1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {

int ind=listView1->SelectedIndices->Count-1;

if(ind!=-1)

{ int i=listView1->SelectedIndices[ind];

T s=t->get_item(i);

((InOut*) s)->output( m,Count);}

}

private: System::Void Query2_Click(System::Object^ sender, System::EventArgs^ e) {

Range p;

FQuery2^ form= gcnew FQuery2;

form->getParam(&p);

form->ShowDialog();

Book _min(0,0,0,p.MinValue);

Book _max(0,0,0,p.MaxValue);

InRange r(&_min,&_max,"price");

Predicat1 pred(&r);

Tabl*q= t->Query(pred);

q->output(listView1,Count);

}

private: System::Void Sort_Click(System::Object^ sender, System::EventArgs^ e) {

struct ParamSort p;

char* Filds[]={"autor","title","price","number"};

Sort ^form= gcnew Sort;

form->getParam(&p, Filds,4);

form->ShowDialog();

Compare1 Comp(&p);

sort(t->begin(),t->end(),Comp);

t->output(listView1,Count);

}

private: System::Void Create_Click(System::Object^ sender, System::EventArgs^ e) {

t->clear();

listView1->Items->Clear();

this->Text="Без имени";

}

private: System::Void Open_Click(System::Object^ sender, System::EventArgs^ e) {

OpenFileDialog^ fd = gcnew OpenFileDialog();

fd->Title = "Open" ;

fd->Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;

if( fd->ShowDialog() == ::DialogResult::OK)

{ this->Text=fd->FileName;

MyConvert::copyto(&BFileName,fd->FileName);

t->clear();

t->finput(BFileName);

t->output(listView1,Count);

}

}

private: System::Void MyClose_Click(System::Object^ sender, System::EventArgs^ e) {

t->clear();

listView1->Items->Clear();

this->Text="";

}

private: System::Void Save_Click(System::Object^ sender, System::EventArgs^ e) {

t->foutput(BFileName);

}

private: System::Void Save_As_Click(System::Object^ sender, System::EventArgs^ e) {

SaveFileDialog^ fd = gcnew SaveFileDialog();

fd->Title = "SaveAs" ;

fd->Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;

if( fd->ShowDialog() == ::DialogResult::OK)

{this->Text=fd->FileName;

MyConvert::copyto(&BFileName,fd->FileName);

t->foutput(BFileName);

}

}

private: System::Void Exit_Click(System::Object^ sender, System::EventArgs^ e) {

this->Close();

}

private: System::Void Form2_Deactivate(System::Object^ sender, System::EventArgs^ e) {

}

public: void get_obj(Book**pb)

{b=*pb;}

private: System::Void Form2_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e) {

((InOut*)b)->input( m,b->CountFields()); }

};

}

Файл Form3.h

#pragma once

#include "stdafx.h"

#include "exeptions.h"

#include "Tabl.h"

#include "FQuery2.h"

#include "Sort.h"

#include "algo.h"

#include "Reader.h"

namespace Book_Lib_List_View_2005 {

InOut* _Rcurrent,*_Rfound;

Iterator Rfound;

char* RFileName;

public ref class Form3 : public System::Windows::Forms::Form

{

public:

Form3(void)

{ InitializeComponent();

}

protected:

~Form3()

{

if (components)

{

delete components;

}

}

public:

public:Tabl* t;

// TextBox* m[];

cli::array<TextBox^>^ m;

int Count;

private: int _foundNext, flag, SelectIndex;

Reader* r;

private: System::Void Add_Click(System::Object^ sender, System::EventArgs^ e) {

if(!_Rcurrent->input( m,Count)) {ExeptionEmpty();return;}

t->insert(_Rcurrent);

t->output(listView1,Count);

}

private: System::Void Delete_Click(System::Object^ sender, System::EventArgs^ e) {

_Rcurrent->input( m,Count);

int i=t->remove(_Rcurrent);

if(i)

{_Rcurrent->output( m,Count);t->output(listView1,Count);}

}

private: System::Void Find_Click(System::Object^ sender, System::EventArgs^ e) {

_Rfound->input( m,Count);

Rfound=find(t->begin(),t->end(),_Rfound);

if( Rfound!=t->end())

((InOut*) (*Rfound))->output( m,Count);

else { ExeptionFound(); }

}

private: System::Void Find_Next_Click(System::Object^ sender, System::EventArgs^ e) {

if(Rfound==t->end()) return;

Rfound=find(++Rfound,t->end(),_Rfound);

if( Rfound!=t->end())

((InOut*) (*Rfound))->output( m,Count);

else { ExeptionFound(); }

}

private: System::Void Replace_Click(System::Object^ sender, System::EventArgs^ e) {

if(flag==0)

{ if(!_Rfound->input( m,Count)){ExeptionEmpty();return;}

flag=1;

MessageBox::Show("Введите данные для замены и нажмите кнопку Заменить еще раз","Поиск");

return;}

if(!_Rcurrent->input( m,Count)){ExeptionEmpty();return;}

{flag=0;

replace(t->begin(),t->end(),_Rfound,_Rcurrent);

t->output(listView1,Count);

}

}

private: System::Void Clear_Click(System::Object^ sender, System::EventArgs^ e) {

_Rcurrent->dispose();

_Rcurrent=new Reader;

_Rcurrent->output( m,Count);

}

private: System::Void Form2_Load(System::Object^ sender, System::EventArgs^ e) {

Reader* tmp=new Reader;

Count=tmp->CountFields();

_Rcurrent=tmp;

_Rfound=new Reader;

t=new Tabl(100,_Rfound);

RFileName=0;

_foundNext=-1;flag=0;

m=gcnew cli::array<TextBox^>(Count);

// m=new TextBox*[Count];

m[0]=textBox5;m[1]=textBox6;m[2]=textBox7; m[3]=textBox8 ;

}

private: System::Void listView1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {

int ind=listView1->SelectedIndices->Count-1;

if(ind!=-1)

{ int i=listView1->SelectedIndices[ind];

T s=t->get_item(i);

((InOut*) s)->output( m,Count);}

}

private: System::Void Query2_Click(System::Object^ sender, System::EventArgs^ e) {

Range p;

FQuery2^ form= gcnew FQuery2;

form->getParam(&p);

form->ShowDialog();

Reader _min(0,0,p.MinValue,0);

Reader _max(0,0,p.MaxValue,0);

InRange r(&_min,&_max,"number");

Predicat1 pred(&r);

Tabl*q= t->Query(pred);

q->output(listView1,Count);

}

private: System::Void Sort_Click(System::Object^ sender, System::EventArgs^ e) {

struct ParamSort p;

char* Filds[]={"autor","title","price","number"};

Sort ^form= gcnew Sort;

form->getParam(&p, Filds,4);

form->ShowDialog();

Compare1 Comp(&p);

sort(t->begin(),t->end(),Comp);

t->output(listView1,Count);

}

private: System::Void Create_Click(System::Object^ sender, System::EventArgs^ e) {

t->clear();

listView1->Items->Clear();

this->Text="Без имени";

}

private: System::Void Open_Click(System::Object^ sender, System::EventArgs^ e) {

OpenFileDialog^ fd = gcnew OpenFileDialog();

fd->Title = "Open" ;

fd->Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;

if( fd->ShowDialog() == ::DialogResult::OK)

{ this->Text=fd->FileName;

MyConvert::copyto(&RFileName,fd->FileName);

t->clear();

t->finput(RFileName);

t->output(listView1,Count);

}

}

private: System::Void MyClose_Click(System::Object^ sender, System::EventArgs^ e) {

t->clear();

listView1->Items->Clear();

this->Text="";

}

private: System::Void Save_Click(System::Object^ sender, System::EventArgs^ e) {

t->foutput(RFileName);

}

private: System::Void Save_As_Click(System::Object^ sender, System::EventArgs^ e) {

SaveFileDialog^ fd = gcnew SaveFileDialog();

fd->Title = "SaveAs" ;

fd->Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;

if( fd->ShowDialog() == ::DialogResult::OK)

{this->Text=fd->FileName;

MyConvert::copyto(&RFileName,fd->FileName);

t->foutput(RFileName);

}

}

private: System::Void Exit_Click(System::Object^ sender, System::EventArgs^ e) {

this->Close();

}

private: System::Void Form2_Deactivate(System::Object^ sender, System::EventArgs^ e) {

}

public: void get_obj(Reader**pb)

{r=*pb;}

private: System::Void Form3_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e) {

((InOut*)r)->input( m,r->CountFields());}

//

};

}

Файл Form1.h

#pragma once

#include "stdafx.h"

#include "exeptions.h"

#include "Tabl.h"

#include "Form2.h"

#include "Form3.h"

#include "FQuery2.h"

#include "Sort.h"

#include "algo.h"

#include "Library.h"

namespace Book_Lib_List_View_2005 {

InOut* _current,*_found;

Iterator found;

char* FileName;

public ref class Form1 : public System::Windows::Forms::Form

{

public:

Form1(void)

{

InitializeComponent();

}

protected:

~Form1()

{ if (components)

{ delete components;

}

}

public:

public:Tabl* t;

// TextBox* m[];

cli::array<TextBox^>^ m;

int Count;

private: int _foundNext, flag, SelectIndex;

Reader* rr; Book* bb;

private: System::Void Add_Click(System::Object^ sender, System::EventArgs^ e) {

char buf[256];

MyConvert::copyto(buf,m[8]->Text,255);

int d, mm,y;

d= Convert::ToInt32(m[9]->Text);

mm=Convert::ToInt32(m[10]->Text);

y= Convert::ToInt32(m[11]->Text);

Library lib(buf, d,mm, y,rr,bb);

t->insert(&lib);

t->output(listView1,Count);

}

private: System::Void Delete_Click(System::Object^ sender, System::EventArgs^ e) {

_current->input( m,Count);

int i=t->remove(_current);

if(i)

{_current->output( m,Count);t->output(listView1,Count);}

}

private: System::Void Find_Click(System::Object^ sender, System::EventArgs^ e) {

_found->input( m,Count);

found=find(t->begin(),t->end(),_found);

if( found!=t->end())

((InOut*) (*found))->output( m,Count);

else { ExeptionFound(); }

}

private: System::Void Find_Next_Click(System::Object^ sender, System::EventArgs^ e) {

if(found==t->end()) return;

found=find(++found,t->end(),_found);

if( found!=t->end())

((InOut*) (*found))->output( m,Count);

else { ExeptionFound(); }

}

private: System::Void Replace_Click(System::Object^ sender, System::EventArgs^ e) {

if(flag==0)

{ if(!_found->input( m,Count)){ExeptionEmpty();return;}

flag=1;

MessageBox::Show("Введите данные для замены и нажмите кнопку Заменить еще раз","Поиск");

return;}

if(!_current->input( m,Count)){ExeptionEmpty();return;}

{flag=0;

replace(t->begin(),t->end(),_found,_current);

t->output(listView1,Count);

}

}

private: System::Void Clear_Click(System::Object^ sender, System::EventArgs^ e) {

_current->dispose();

_current=new Library;

_current->output( m,Count);

}

private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {

Count=12;

_current=new Library;

_found=new Library;

t=new Tabl(100,_found);

FileName=0;

_foundNext=-1;flag=0;

m=gcnew cli::array<TextBox^>(Count);

// m=new TextBox*[Count];

m[0]=textBox5;m[1]=textBox6;m[2]=textBox7; m[3]=textBox8 ;

m[4]=textBox1;m[5]= textBox2; m[6]=textBox3;m[7]=textBox4;

m[8]=textBox9;m[9]=textBox10; m[10]=textBox11 ; m[11]=textBox12 ;

}

private: System::Void listView1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {

int ind=listView1->SelectedIndices->Count-1;

if(ind!=-1)

{ int i=listView1->SelectedIndices[ind];

T s=t->get_item(i);

((InOut*) s)->output( m,Count);}

}

private: System::Void Query2_Click(System::Object^ sender, System::EventArgs^ e) {

/* Range p;

FQuery2^ form= gcnew FQuery2;

form->getParam(&p);

form->ShowDialog();

Book _min(0,0,p.MinValue,0);

Book _max(0,0,p.MaxValue,0);

InRange r(&_min,&_max,"day");

Predicat1 pred(&r);

Tabl*q= t->Query(pred);

q->output(listView1,Count);

*/ }

private: System::Void Sort_Click(System::Object^ sender, System::EventArgs^ e) {

struct ParamSort p;

char* Filds[]={"bibl","date"};

Sort ^form= gcnew Sort;

form->getParam(&p, Filds,4);

form->ShowDialog();

Compare1 Comp(&p);

sort(t->begin(),t->end(),Comp);

t->output(listView1,Count);

}

private: System::Void Create_Click(System::Object^ sender, System::EventArgs^ e) {

t->clear();

listView1->Items->Clear();

this->Text="Без имени";

}

private: System::Void Open_Click(System::Object^ sender, System::EventArgs^ e) {

OpenFileDialog^ fd = gcnew OpenFileDialog();

fd->Title = "Open" ;

fd->Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;

if( fd->ShowDialog() == ::DialogResult::OK)

{ this->Text=fd->FileName;

MyConvert::copyto(&FileName,fd->FileName);

t->clear();

t->finput(FileName);

t->output(listView1,Count);

}

}

private: System::Void MyClose_Click(System::Object^ sender, System::EventArgs^ e) {

t->clear();

listView1->Items->Clear();

this->Text="";

}

private: System::Void Save_Click(System::Object^ sender, System::EventArgs^ e) {

t->foutput(FileName);

}

private: System::Void Save_As_Click(System::Object^ sender, System::EventArgs^ e) {

SaveFileDialog^ fd = gcnew SaveFileDialog();

fd->Title = "SaveAs" ;

fd->Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;

if( fd->ShowDialog() == ::DialogResult::OK)

{this->Text=fd->FileName;

MyConvert::copyto(&FileName,fd->FileName);

t->foutput(FileName);

}

}

private: System::Void Exit_Click(System::Object^ sender, System::EventArgs^ e) {

this->Close();

}

private: System::Void button7_Click(System::Object^ sender, System::EventArgs^ e) {

Form2^ f2=gcnew Form2;

Book*b=new Book;

f2->get_obj(&b);

f2->ShowDialog();

((InOut*) b)->output( m,b->CountFields());

bb=b;

}

private: System::Void button8_Click(System::Object^ sender, System::EventArgs^ e) {

Form3^ f3=gcnew Form3;

Reader*r=new Reader; Book b;

f3->get_obj(&r);

f3->ShowDialog();

((InOut*) r)->output( m,r->CountFields(),b.CountFields());

rr=r;

}

};

}

литература

1. Страуструп Б. Язык пpогpаммиpования С++. Часть первая. - Киев: ДиаСофт, 1993. 264 с.

2. Страуструп Б. Язык пpогpаммиpования С++. Часть вторая. - Киев: ДиаСофт, 1993. 296 с.

3. Эллис М. , Страуструп Б. Справочное руководство по языку программированию С++. -М: Изд. Мир, 1992

4.. С++ язык пpогpаммиpования. - М: И. В. К. -СОФТ, 1991

5. Иpэ П. Обьектно -оpиентиpованное пpогpаммиpование с использованием С++. -Киев:НИПФ ДиаСофт Лтд. , 1995. 480 с.

6. Касаткин А. И. , Вальвачев А. Н. От Turbo C к Borland C++. -Минск:Вышейшая школа, 1992 7. Нефоpмальное введение в С++ и Turbo VISION. -Петеpбуpг:Галеpея Петpополь, 1992

7. Абрамов С.А., Гнездилова Г.Г., Капустина Е.Н., Семон М.И. / Задачи по программированию. - М.:, Наука, 1998

Сборник заданий по программированию на языке С++