Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабы / С++Builder / Laba2 / Unit1

.cpp
Скачиваний:
13
Добавлен:
17.04.2013
Размер:
11.33 Кб
Скачать
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

char op=0;
bool comm=false;
long double A=0,B=0;

int compare(AnsiString S1,AnsiString S2)
{
String tmp1=S1.SubString(1,S1.Pos(" ")-1);
String tmp2=S2.SubString(1,S2.Pos(" ")-1);
if (tmp1>tmp2) return 1;
if (tmp1==tmp2) return 0;
if (tmp1<tmp2) return -1;
}

int sort(TStrings* Strngs, int mode, int direction)
{
switch (mode)
        {
        case 0:
        for (int i=0;i<=Strngs->Count-2;i++)
                {
                for (int j=Strngs->Count-1; j>=i+1;j--)
                        {
                        switch (direction)
                        {
                        case 0:
                        if (compare(Strngs->Strings[i],Strngs->Strings[j])>0)
                                {
                                AnsiString buf=Strngs->Strings[i];
                                Strngs->Strings[i]=Strngs->Strings[j];
                                Strngs->Strings[j]=buf;
                                };
                        break;
                        case 1:
                        if (compare(Strngs->Strings[i],Strngs->Strings[j])<0)
                                {
                                AnsiString buf=Strngs->Strings[i];
                                Strngs->Strings[i]=Strngs->Strings[j];
                                Strngs->Strings[j]=buf;
                                };
                        break;
                        };
                        };
                };
        break;
        case 1:
        for (int i=0;i<=Strngs->Count-2;i++)
                {
                for (int j=Strngs->Count-1; j>=i+1;j--)
                        {
                        switch (direction)
                        {
                        case 0:
                        if (Strngs->Strings[i]>Strngs->Strings[j])
                                {
                                AnsiString buf=Strngs->Strings[i];
                                Strngs->Strings[i]=Strngs->Strings[j];
                                Strngs->Strings[j]=buf;
                                };
                        break;
                        case 1:
                        if (Strngs->Strings[i]<Strngs->Strings[j])
                                {
                                AnsiString buf=Strngs->Strings[i];
                                Strngs->Strings[i]=Strngs->Strings[j];
                                Strngs->Strings[j]=buf;
                                };
                        break;
                        };
                        };
                };
        break;
        }
return 0;
}


//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
GlobalInt=10;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (OpenDialog1->Execute())
        {
        Memo1->Lines->LoadFromFile(OpenDialog1->FileName);
        sort(Memo1->Lines,RadioGroup1->ItemIndex,RadioGroup2->ItemIndex);
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
if (SaveDialog1->Execute())
{
Memo1->Lines->SaveToFile(SaveDialog1->FileName);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioGroup1Click(TObject *Sender)
{
sort(Memo1->Lines,RadioGroup1->ItemIndex,RadioGroup2->ItemIndex);
Beep(5000,50);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton13Click(TObject *Sender)
{
if (((TSpeedButton*) Sender)->Caption==",") {
 if (!comm) {Edit1->Text=Edit1->Text+",";comm=!comm;}
 return;}

if (Edit1->Text[1]=='0') if (((TSpeedButton*) Sender)->Caption==0) return;
if (Edit1->Text[1]!='0' || comm) Edit1->Text=Edit1->Text+((TSpeedButton*) Sender)->Caption; else Edit1->Text=((TSpeedButton*) Sender)->Caption;

}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton15Click(TObject *Sender)
{
Edit1->Text="0";
op=0;
comm=false;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::SpeedButton4Click(TObject *Sender)
{

if (op!=0) switch (op)
        {
        case '+':
        A=A+StrToFloat(Edit1->Text);
        Edit1->Text=FloatToStr(A);
        break;
        case '*':
        A=A*StrToFloat(Edit1->Text);
        Edit1->Text=FloatToStr(A);
        break;
        case '/':
        A=A/StrToFloat(Edit1->Text);
        Edit1->Text=FloatToStr(A);
        break;
        case '-':
        A=A-StrToFloat(Edit1->Text);
        Edit1->Text=FloatToStr(A);
        break;
        }
        else A=StrToFloat(Edit1->Text);
comm=false;
Edit1->Text="0";

if (((TSpeedButton*) Sender)->Caption=="+") op='+';
if (((TSpeedButton*) Sender)->Caption=="*") op='*';
if (((TSpeedButton*) Sender)->Caption=="/") op='/';
if (((TSpeedButton*) Sender)->Caption=="-") op='-';
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton17Click(TObject *Sender)
{
if (op!=0) switch (op)
        {
        case '+':
        A=A+StrToFloat(Edit1->Text);
        Edit1->Text=FloatToStr(A);
        break;
        case '*':
        A=A*StrToFloat(Edit1->Text);
        Edit1->Text=FloatToStr(A);
        break;
        case '/':
        A=A/StrToFloat(Edit1->Text);
        Edit1->Text=FloatToStr(A);
        break;
        case '-':
        A=A-StrToFloat(Edit1->Text);
        Edit1->Text=FloatToStr(A);
        break;
        }
op=0;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::RadioButton1Click(TObject *Sender)
{
switch (((TRadioButton*) Sender)->Caption[7])
        {
        case '1':
        ListBox1->Visible=true;
        ListBox2->Visible=false;
        ListBox3->Visible=false;
        break;
        case '2':
        ListBox1->Visible=false;
        ListBox2->Visible=true;
        ListBox3->Visible=false;
        break;
        case '3':
        ListBox1->Visible=false;
        ListBox2->Visible=false;
        ListBox3->Visible=true;
        break;
        }

}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
ListBox1->Items->LoadFromFile("Otdel1.txt");
ListBox2->Items->LoadFromFile("Otdel2.txt");
ListBox3->Items->LoadFromFile("Otdel3.txt");
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
TGridOptions oo;

if (ListBox1->Visible)
        {
        Form3->Edit1->Text=ListBox1->Items->Strings[ListBox1->ItemIndex];
        Form3->ShowModal();
        ListBox1->Items->Strings[ListBox1->ItemIndex]=Form3->Edit1->Text;
        }
if (ListBox2->Visible)
        {
        Form3->Edit1->Text=ListBox2->Items->Strings[ListBox2->ItemIndex];
        Form3->ShowModal();
        ListBox2->Items->Strings[ListBox2->ItemIndex]=Form3->Edit1->Text;
        }
if (ListBox3->Visible)
        {
        Form3->Edit1->Text=ListBox3->Items->Strings[ListBox3->ItemIndex];
        Form3->ShowModal();
        ListBox3->Items->Strings[ListBox3->ItemIndex]=Form3->Edit1->Text;
        }

}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
ListBox1->Items->SaveToFile("Otdel1.txt");
ListBox2->Items->SaveToFile("Otdel2.txt");
ListBox3->Items->SaveToFile("Otdel3.txt");
}
//---------------------------------------------------------------------------


void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
Form2->ListBox1->Items->Clear();
for (int i=0;i<ListBox1->Items->Count-1;i++)
        {
        if (ListBox1->Selected[i])
                Form2->ListBox1->Items->Add(ListBox1->Items->Strings[i]);
        }
for (int i=0;i<ListBox1->Items->Count-1;i++)
        {
        if (ListBox2->Selected[i])
                Form2->ListBox1->Items->Add(ListBox2->Items->Strings[i]);
        }
for (int i=0;i<ListBox1->Items->Count-1;i++)
        {
        if (ListBox3->Selected[i])
                Form2->ListBox1->Items->Add(ListBox3->Items->Strings[i]);
        }
Form2->ListBox1->Items->Add("");
double Sum=0;
for (int i=0;i<Form2->ListBox1->Items->Count-1;i++)
        {
        AnsiString SS=Form2->ListBox1->Items->Strings[i];
        SS.Delete(1,SS.AnsiPos("("));
        SS.Delete(SS.AnsiPos(")"),SS.Length()-SS.AnsiPos(")")+1);
        double S=StrToFloat(SS);
        Sum+=S;
        }
Form2->ListBox1->Items->Add("Итого: "+FloatToStr(Sum));
Form2->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
Button3->Width++;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)
{
((TButton*)Sender)->Caption="abc";
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button8Click(TObject *Sender)
{
Panel1->Color=clGreen;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button9Click(TObject *Sender)
{
Panel1->Color=clBlue;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button7Click(TObject *Sender)
{
Panel1->Color=clRed;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button10Click(TObject *Sender)
{
String s; //тип для работы со строками
s = Edit2 -> Text; // текстовое содержимое попадает в s
s = s + "*"; // добавляем звезду в хвост строки
Edit2 -> Text = s; // обновляем текстовое содержимое Edit2
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button11Click(TObject *Sender)
{
if (Memo2->Lines->Count>=StrToInt(Edit3->Text) && StrToInt(Edit3->Text)>0)
        Memo2->Lines->Strings[StrToInt(Edit3->Text)-1]=Edit4->Text;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button12Click(TObject *Sender)
{
if (OpenDialog1->Execute()) Memo2->Lines->LoadFromFile(OpenDialog1->FileName);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button13Click(TObject *Sender)
{
if (SaveDialog1->Execute()) Memo2->Lines->SaveToFile(SaveDialog1->FileName);
}
//---------------------------------------------------------------------------

Соседние файлы в папке Laba2