Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C++ Builder > Написать, "что" используется в проекте.


Автор: MIG 8.6.2006, 12:43
 smile  smile 


Пожалуйста, помогите разобраться, где здесь объекты, используются ли конструкторы (если да, то какие и где?), какие шаблоны, классы использовались здесь. Используется ли здесь рекурсия (если да, то покажите, где?). Тыкните меня носом в это, я очень прошу! Что такое рекурсия?

 //---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Main.h"
#include "CV.cpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
VectorM <double> *A,*B,*C;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}

//---------------------------------------------------------------------------
//Ввод A и B по умолчанию из файлов
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(A)delete A;
if(B)delete B;
A=new VectorM<double>("inputA");
B=new VectorM<double>("inputB");
ChStr->Position=A->GetSize();
strok->Text=IntToStr(ChStr->Position);
V1->RowCount=ChStr->Position;
V2->RowCount=ChStr->Position;
V3->RowCount=ChStr->Position;
for(int i=0; i<ChStr->Position; i++)
  {
  V1->Cells[0][i]=FloatToStr(A->operator [](i));
  V2->Cells[0][i]=FloatToStr(B->operator [](i));
  }
}

//---------------------------------------------------------------------------
//Выход из программы
void __fastcall TForm1::Button5Click(TObject *Sender)
{
if(A) delete A;
if(B) delete B;
if© delete C;
exit(0);
}
//---------------------------------------------------------------------------
//При создании формы обнулить векторы
void __fastcall TForm1::FormActivate(TObject *Sender)
{
A=B=C=NULL;
}
//---------------------------------------------------------------------------
//Очистка векторов
void __fastcall TForm1::Button4Click(TObject *Sender)
{
for(int i=0; i<ChStr->Position; i++)
  {
  V1->Cells[0][i]="";
  V2->Cells[0][i]="";
  V3->Cells[0][i]="";
  }
if(A) delete A;
if(B) delete B;
if© delete C;
A=B=C=NULL;
}
//---------------------------------------------------------------------------
//Сохранение векторов по умолчанию
void __fastcall TForm1::Button6Click(TObject *Sender)
{
for(int i=0; i<ChStr->Position; i++)
  {
  if(V1->Cells[0][i]=="")V1->Cells[0][i]=FloatToStr(0);
  if(V2->Cells[0][i]=="")V2->Cells[0][i]=FloatToStr(0);
  V3->Cells[0][i]="";
  }
ofstream outA("inputA", ios_base::out);
ofstream outB("inputB", ios_base::out);
outA<<ChStr->Position<<endl;
outB<<ChStr->Position<<endl;
for(int i=0; i<ChStr->Position; i++)
  {
  outA<<StrToFloat(V1->Cells[0][i])<<endl;
  outB<<StrToFloat(V2->Cells[0][i])<<endl;
  }
outA.close();
outB.close();
}
//---------------------------------------------------------------------------
//Ввод из окна вектора А
//Сложение векторов
void __fastcall TForm1::Button8Click(TObject *Sender)
{
for(int i=0; i<ChStr->Position; i++)
  {
  if(V1->Cells[0][i]=="")V1->Cells[0][i]=FloatToStr(0);
  if(V2->Cells[0][i]=="")V2->Cells[0][i]=FloatToStr(0);
  if(V3->Cells[0][i]=="")V3->Cells[0][i]=FloatToStr(0);
  }
V3->RowCount=ChStr->Position;
if(A)delete A;
if(B)delete B;
if©delete C;
ofstream outA("tempA", ios_base::out);
ofstream outB("tempB", ios_base::out);
outA<<ChStr->Position<<endl;
outB<<ChStr->Position<<endl;
for(int i=0; i<ChStr->Position; i++)
  {
  outA<<StrToFloat(V1->Cells[0][i])<<endl;
  outB<<StrToFloat(V2->Cells[0][i])<<endl;
  }
A=new VectorM<double>("tempA");
B=new VectorM<double>("tempB");
outA.close();
outB.close();
remove("tempA");
remove("tempB");
C=new VectorM<double>(*A);
C->operator +(*B);
for(int i=0; i<ChStr->Position; i++)
  V3->Cells[0][i]=FloatToStr(C->operator [](i));
}
//---------------------------------------------------------------------------
//Разность векторов
void __fastcall TForm1::Button11Click(TObject *Sender)
{
for(int i=0; i<ChStr->Position; i++)
  {
  if(V1->Cells[0][i]=="")V1->Cells[0][i]=FloatToStr(0);
  if(V2->Cells[0][i]=="")V2->Cells[0][i]=FloatToStr(0);
  if(V3->Cells[0][i]=="")V3->Cells[0][i]=FloatToStr(0);
  }
V3->RowCount=ChStr->Position;
if(A)delete A;
if(B)delete B;
if©delete C;
ofstream outA("tempA", ios_base::out);
ofstream outB("tempB", ios_base::out);
outA<<ChStr->Position<<endl;
outB<<ChStr->Position<<endl;
for(int i=0; i<ChStr->Position; i++)
  {
  outA<<StrToFloat(V1->Cells[0][i])<<endl;
  outB<<StrToFloat(V2->Cells[0][i])<<endl;
  }
A=new VectorM<double>("tempA");
B=new VectorM<double>("tempB");
outA.close();
outB.close();
remove("tempA");
remove("tempB");
C=new VectorM<double>(*A);
C->operator -(*B);
for(int i=0; i<ChStr->Position; i++)
  V3->Cells[0][i]=FloatToStr(C->operator [](i));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button12Click(TObject *Sender)
{
for(int i=0; i<ChStr->Position; i++)
  if(V1->Cells[0][i]=="")V1->Cells[0][i]=FloatToStr(0);
if(A)delete A;
ofstream outA("tempA", ios_base::out);
outA<<ChStr->Position<<endl;
for(int i=0; i<ChStr->Position; i++)
  outA<<StrToFloat(V1->Cells[0][i])<<endl;
outA.close();
A=new VectorM<double>("tempA");
remove("tempA");
double cv[100];
int n=A->Vich(cv);
V3->RowCount=n;
for(int i=0; i<n; i++)
  V3->Cells[0][i]=FloatToStr(cv[i]);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
OpenDialog1->Execute();
if (OpenDialog1->FileName!="" && FileExists(OpenDialog1->FileName))
  {
  if(A)delete A;
  A=new VectorM<double>(OpenDialog1->FileName.c_str());
  ChStr->Position=A->GetSize();
  strok->Text=IntToStr(ChStr->Position);
  V1->RowCount=ChStr->Position;
  V2->RowCount=ChStr->Position;
  V3->RowCount=ChStr->Position;
  for(int i=0; i<ChStr->Position; i++)
    {
    V1->Cells[0][i]=FloatToStr(A->operator [](i));
    }
  }
}
//---------------------------------------------------------------------------
//Копирование А в В
void __fastcall TForm1::Button14Click(TObject *Sender)
{
for(int i=0; i<ChStr->Position; i++)
  {
  V2->Cells[0][i]=V1->Cells[0][i];
  }
}
//---------------------------------------------------------------------------
//Открытие из файла ветора В
void __fastcall TForm1::Button16Click(TObject *Sender)
{
OpenDialog1->Execute();
if (OpenDialog1->FileName!="" && FileExists(OpenDialog1->FileName))
  {
  if(B)delete B;
  B=new VectorM<double>(OpenDialog1->FileName.c_str());
  ChStr->Position=B->GetSize();
  strok->Text=IntToStr(ChStr->Position);
  V1->RowCount=ChStr->Position;
  V2->RowCount=ChStr->Position;
  V3->RowCount=ChStr->Position;
  for(int i=0; i<ChStr->Position; i++)
    {
    V2->Cells[0][i]=FloatToStr(B->operator [](i));
    }
  }
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button7Click(TObject *Sender)
{
SaveDialog1->Execute();
if (SaveDialog1->FileName!="")
{
for(int i=0; i<ChStr->Position; i++)
  {
  if(V1->Cells[0][i]=="")V1->Cells[0][i]=FloatToStr(0);
  if(V2->Cells[0][i]=="")V2->Cells[0][i]=FloatToStr(0);
  V3->Cells[0][i]="";
  }
ofstream outA(SaveDialog1->FileName.c_str(), ios_base::out);
outA<<ChStr->Position<<endl;
for(int i=0; i<ChStr->Position; i++)
  outA<<StrToFloat(V1->Cells[0][i])<<endl;
outA.close();
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button17Click(TObject *Sender)
{
SaveDialog1->Execute();
if (SaveDialog1->FileName!="")
{
for(int i=0; i<ChStr->Position; i++)
  {
  if(V1->Cells[0][i]=="")V1->Cells[0][i]=FloatToStr(0);
  if(V2->Cells[0][i]=="")V2->Cells[0][i]=FloatToStr(0);
  V3->Cells[0][i]="";
  }
ofstream outB(SaveDialog1->FileName.c_str(), ios_base::out);
outB<<ChStr->Position<<endl;
for(int i=0; i<ChStr->Position; i++)
  outB<<StrToFloat(V2->Cells[0][i])<<endl;
outB.close();
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ChStrClick(TObject *Sender, TUDBtnType Button)
{
if(ChStr->Position<1) {ChStr->Position=1;return;}
if(ChStr->Position>13) {ChStr->Position=13;return;}
strok->Text=IntToStr(ChStr->Position);
V1->RowCount=ChStr->Position;
V2->RowCount=ChStr->Position;
V3->RowCount=ChStr->Position;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button9Click(TObject *Sender)
{
for(int i=0; i<ChStr->Position; i++)
  {
  if(V1->Cells[0][i]=="")V1->Cells[0][i]=FloatToStr(0);
  if(V2->Cells[0][i]=="")V2->Cells[0][i]=FloatToStr(0);
  if(V3->Cells[0][i]=="")V3->Cells[0][i]=FloatToStr(0);
  }
V3->RowCount=ChStr->Position;
if(A)delete A;
if(B)delete B;
if©delete C;
ofstream outA("tempA", ios_base::out);
ofstream outB("tempB", ios_base::out);
outA<<ChStr->Position<<endl;
outB<<ChStr->Position<<endl;
for(int i=0; i<ChStr->Position; i++)
  {
  outA<<StrToFloat(V1->Cells[0][i])<<endl;
  outB<<StrToFloat(V2->Cells[0][i])<<endl;
  }
A=new VectorM<double>("tempA");
B=new VectorM<double>("tempB");
outA.close();
outB.close();
remove("tempA");
remove("tempB");
C=new VectorM<double>(*A);
C->operator *(*B);
for(int i=0; i<ChStr->Position; i++)
  V3->Cells[0][i]=FloatToStr(C->operator [](i));
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button10Click(TObject *Sender)
{
for(int i=0; i<ChStr->Position; i++)
  {
  if(V1->Cells[0][i]=="")V1->Cells[0][i]=FloatToStr(0);
  if(V2->Cells[0][i]=="")V2->Cells[0][i]=FloatToStr(0);
  if(V3->Cells[0][i]=="")V3->Cells[0][i]=FloatToStr(0);
  }
V3->RowCount=ChStr->Position;
if(A)delete A;
if(B)delete B;
if©delete C;
ofstream outA("tempA", ios_base::out);
ofstream outB("tempB", ios_base::out);
outA<<ChStr->Position<<endl;
outB<<ChStr->Position<<endl;
for(int i=0; i<ChStr->Position; i++)
  {
  outA<<StrToFloat(V1->Cells[0][i])<<endl;
  outB<<StrToFloat(V2->Cells[0][i])<<endl;
  }
A=new VectorM<double>("tempA");
B=new VectorM<double>("tempB");
outA.close();
outB.close();
remove("tempA");
remove("tempB");
C=new VectorM<double>(*A);
C->operator /(*B);
for(int i=0; i<ChStr->Position; i++)
  V3->Cells[0][i]=FloatToStr(C->operator [](i));
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button13Click(TObject *Sender)
{
for(int i=0; i<ChStr->Position; i++)
  if(V2->Cells[0][i]=="")V2->Cells[0][i]=FloatToStr(0);
if(B)delete B;
ofstream outB("tempB", ios_base::out);
outB<<ChStr->Position<<endl;
for(int i=0; i<ChStr->Position; i++)
  outB<<StrToFloat(V2->Cells[0][i])<<endl;
B=new VectorM<double>("tempB");
outB.close();
remove("tempB");
double cv[100];
int n=B->Vich(cv);
V3->RowCount=n;
for(int i=0; i<n; i++)
  V3->Cells[0][i]=FloatToStr(cv[i]);
}
//---------------------------------------------------------------------------
 

Автор: _hunter 8.6.2006, 13:19
ты книгу какую-нить по сям читать не пробовал? говорят помогает...
объекты там -- A, B, C, Form1 (точнее это указатели нан них) и 
конструктор -- TForm1::TForm1()
шаблон VectorM <double>
рекурсии при беглом просмотре не заметил 

Автор: MIG 8.6.2006, 17:40
А такой вопросик, а что за шаблон используется? Как он называется по-русски?
А в каких командах эти объекты заданы? Т.е. кде их в программе показать?

Один остался до защиты этой программы, книга мало чем поможет за это время! ))) 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)