Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
2 отчёт по практике ( 2 курс ).docx
Скачиваний:
5
Добавлен:
31.10.2018
Размер:
189.84 Кб
Скачать

3.3.Калькулятор – Visual Basic

Private Sub delit_Click()

If txt2.Text <> 0 Then otvet.Caption = CStr(CInt(txt1.Text) / CInt(txt2.Text)) Else MsgBox ("на ноль делить нельзя!")

End Sub

Private Sub minus_Click()

otvet.Caption = CStr(CInt(txt1.Text) - CInt(txt2.Text))

End Sub

Private Sub mnoj_Click()

otvet.Caption = CStr(CInt(txt1.Text) * CInt(txt2.Text))

End Sub

Private Sub plus_Click()

otvet.Caption = CStr(CInt(txt1.Text) + CInt(txt2.Text))

End Sub

3.4.Редактор – Visual Basic

Form1(Form1.frm)

Private Sub Close_Click()

On Error Resume Next

Open Form3.Text1 For Input As #1

Y = Input(LOF(1), #1)

Close #1

If Text1 = Y Then

Text1 = ""

Exit Sub

ElseIf (MsgBox("Сохранить изменения в документе?", vbQuestion Or vbYesNo, "Подтверждение")) = vbNo Then

Text1 = ""

Exit Sub

ElseIf Form3.Text1 = "" Then

Form2.Enabled = False

Form4.Visible = True

Else

Open Form3.Text1 For Output As #1

Print #1, Text1

Close #1

Text1 = ""

Exit Sub

End If

End Sub

Private Sub Exit_Click()

On Error Resume Next

Open Form3.Text1 For Input As #1

S = Input(LOF(1), #1)

Close #1

If Text1 = S Then

End

ElseIf (MsgBox("Сохранить изменения в документе?", vbQuestion Or vbYesNo, "Подтверждение")) = vbNo Then

End

ElseIf Form3.Text1 = "" Then

Form2.Enabled = False

Form4.Visible = True

Else

Open Form3.Text1 For Output As #1

Print #1, Text1

Close #1

End

End If

End Sub

Private Sub Form_Unload(Cancel As Integer)

On Error Resume Next

Open Form3.Text1 For Input As #1

Q = Input(LOF(1), #1)

Close #1

If Text1 = Q Then

End

ElseIf (MsgBox("Сохранить изменения в документе?", vbQuestion Or vbYesNo, "Подтверждение")) = vbNo Then

End

ElseIf Form3.Text1 = "" Then

Form2.Enabled = False

Form4.Visible = True

Else

Open Form3.Text1 For Output As #1

Print #1, Text1

Close #1

End

End If

End Sub

Private Sub Information_Click()

On Error Resume Next

Form2.Enabled = False

Form5.Visible = True

End Sub

Private Sub New_Click()

On Error Resume Next

Dim A

A = CurDir

RetVal = Shell(A + "\Редактор.exe ", 1)

End Sub

Private Sub Open_Click()

On Error Resume Next

If Text1 = "" Then

Form3.Text1 = ""

Form3.Visible = True

Form2.Enabled = False

Else

MsgBox "Для продолжения работы закройте созданный или открытый файл!", vbInformation, "RSV"

Exit Sub

End If

End Sub

Private Sub Print_Click()

On Error Resume Next

Dim objprinter As Printer

If Printer.DeviceName = "Microsoft Fax" Then

MsgBox "В системе не обнаружено принтера!", vbCritical, "RSV"

Exit Sub

ElseIf Printer.DeviceName = "Microsoft Office Document Image Writer" Then

MsgBox "В системе не обнаружено принтера!", vbCritical, "RSV"

Exit Sub

Else

Printer.Font.Name = "times new roman"

Printer.Font.Size = 14

Printer.Font.Underline = False

Printer.Print Text1

Printer.EndDoc

End If

End Sub

Private Sub Programm_Click()

On Error Resume Next

Form2.Enabled = False

Form6.Visible = True

End Sub

Private Sub Save_Click()

On Error Resume Next

If Form3.Text1 = "" Then

Form2.Enabled = False

Form4.Visible = True

Else

Open Form3.Text1 For Output As #1

Print #1, Text1

Close 1#

End If

End Sub

Private Sub ShowSave_Click()

On Error Resume Next

Form2.Enabled = False

Form4.Visible = True

End Sub

Form2(Form2.frm)

Private Sub Command1_Click()

On Error Resume Next

Form2.Enabled = True

Form3.Visible = False

Open Text1 For Input As #1

Form2.Text1 = Input$(LOF(1), #1)

Close #1

End Sub

Private Sub Dir1_Change()

On Error Resume Next

File1.Path = Dir1.Path

End Sub

Private Sub Dir1_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then

Dir1.Path = Dir1.List(Dir1.ListIndex)

End If

End Sub

Private Sub Drive1_Change()

On Error Resume Next

Dir1.Path = Drive1

End Sub

Private Sub File1_Click()

If Right(File1.Path, 1) = "\" Then

Text1 = File1.Path & File1.FileName

Else

Text1 = File1.Path & "\" & File1.FileName

End If

End Sub

Private Sub Form_Unload(Cancel As Integer)

Form2.Enabled = True

End Sub

Form3(Form3.frm)

Private Sub Command1_Click()

On Error Resume Next

If Text1 = "" Then

MsgBox "Введите имя файла!", vbCritical, "RSV"

Exit Sub

Else

End If

If Text2 = "" Then

MsgBox "Введите тип файла!", vbCritical, "RSV"

Exit Sub

Else

End If

If Text2 = "exe" Then

MsgBox "Введен не поддерживаемый тип файлов!", vbCritical, "RSV"

Exit Sub

ElseIf Text2 = "com" Then

MsgBox "Введен не поддерживаемый тип файлов!", vbCritical, "RSV"

Exit Sub

ElseIf Text2 = "bat" Then

MsgBox "Введен не поддерживаемый тип файлов!", vbCritical, "RSV"

Exit Sub

Else

End If

Dim R

If Right(Dir1.Path, 1) = "\" Then

D = Dir1 & Text1 & "." & Text2

Else

D = Dir1 & "\" & Text1 & "." & Text2

End If

R = Dir(D)

If R = "" Then

Open D For Output As #1

Print #1, Form2.Text1

Close 1#

Form3.Text1 = D

Form3.Command1 = True

Form2.Enabled = True

Form4.Visible = False

Exit Sub

Else

MsgBox "Такой файл уже существует.", vbCritical, "RSV"

End If

If (MsgBox("Перезаписать его?", vbqestion Or vbYesNo, "Подтверждение")) = vbYes Then

Open D For Output As #1

Print #1, Form2.Text1

Close 1#

Form3.Text1 = D

Form3.Command1 = True

Form2.Enabled = True

Form4.Visible = False

Else

Exit Sub

End If

End Sub

Private Sub Dir1_Change()

On Error Resume Next

File1.Path = Dir1.Path

End Sub

Private Sub Dir1_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then

Dir1.Path = Dir1.List(Dir1.ListIndex)

End If

End Sub

Private Sub Drive1_Change()

On Error Resume Next

Dir1.Path = Drive1

End Sub

Private Sub Form_Unload(Cancel As Integer)

Form2.Enabled = True

End Sub

Form4(Form4.frm)

Private Sub Form_Load()

On Error Resume Next

Dim A

A = CurDir

Open A + "\Help.rsv" For Input As #1

Text1 = Input$(LOF(1), #1)

Close #1

End Sub

Private Sub Form_Unload(Cancel As Integer)

Form2.Enabled = True

Form5.Visible = False

End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)

KeyCode = 0

End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

KeyAscii = 0

End Sub

Form5(Form5.frm)

Private Sub Form_Load()

On Error Resume Next

Dim A

A = CurDir

Open A + "\Information.rsv" For Input As #1

Label1 = Input$(LOF(1), #1)

Close #1

End Sub

Private Sub Form_Unload(Cancel As Integer)

Form2.Enabled = True

Form6.Visible = False

End Su

3.5.Редактор – C++ Builder 6

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

#include <vcl.h>

#pragma hdrstop

#include "Unit1.h"

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

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

TTextAttributes*wcg;

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

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

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

void __fastcall TForm1::Button1Click(TObject *Sender)

{

RichEdit1->Clear(); //Очищаем от текста

OpenDialog1->Execute(); //Ищем нужный файл

if (OpenDialog1->FileName=="") { //Если имя файла пустое то нечего не происходит

}

else //а если имя есть то запускаем следующию конструкцию:

{

RichEdit1->Lines->LoadFromFile(OpenDialog1->FileName);

Form1->Caption="Файл: " + OpenDialog1->FileName;

}

}

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

void __fastcall TForm1::Button2Click(TObject *Sender)

{

RichEdit1->Clear(); //Очищаем от текста

OpenDialog1->FileName="new.txt"; //Присваеваем новому файлу имя

Form1->Caption="Файл: " + OpenDialog1->FileName; //Пишем что у нас открыт новый файл

}

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

void __fastcall TForm1::Button3Click(TObject *Sender)

{

RichEdit1->Lines->SaveToFile(OpenDialog1->FileName);

}

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

void __fastcall TForm1::Button4Click(TObject *Sender)

{

SaveDialog1->Execute() ;

if (SaveDialog1->FileName==""){ //Если имя пустое то нечего

}

else //Если имя указано - то сохраняем:

{

RichEdit1->Lines->SaveToFile(SaveDialog1->FileName);

}

}

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

void __fastcall TForm1::Button5Click(TObject *Sender)

{

AnsiString FileName=OpenDialog1->FileName; //Объявляем имя удаляемого файла и присваеваем ему имя открытого фала

if (DeleteFile(FileName)) Form1->Caption="Файл удалён "; // программа успешно удалена, выводиться сообщение.

RichEdit1->Clear(); //Очищаем Memo

}

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

void __fastcall TForm1::Button6Click(TObject *Sender)

{

if (FontDialog1->Execute() ) //Окно выбора шрифта

{

wcg=RichEdit1->SelAttributes; //Принимаем атрибуты на RichEdit

wcg->Assign(FontDialog1->Font);

RichEdit1->SelAttributes=wcg; //Атрибуты входять в силу

}

}

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

void __fastcall TForm1::Button7Click(TObject *Sender)

{

if (ColorDialog1->Execute() ) //Окно выбора цвета

{

wcg=RichEdit1->SelAttributes; //Принимаем цвет

wcg->Color=ColorDialog1->Color;

RichEdit1->SelAttributes=wcg; //Красим текст

}

}

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

void __fastcall TForm1::Button8Click(TObject *Sender)

{

if (PrintDialog1->Execute() )

{

for (int i=1;i<=PrintDialog1->Copies;i++)

{

RichEdit1->Print("");

}

}

}

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

void __fastcall TForm1::FormCreate(TObject *Sender)

{

Form1->Caption="World Games Developers" ;

}

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

void __fastcall TForm1::N3Click(TObject *Sender)

{

RichEdit1->Clear(); //Очищаем от текста

OpenDialog1->FileName="new.txt"; //Присваеваем новому файлу имя

Form1->Caption="Файл: " + OpenDialog1->FileName; //Пишем что у нас открыт новый файл

}

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

void __fastcall TForm1::N4Click(TObject *Sender)

{

RichEdit1->Clear(); //Очищаем от текста

OpenDialog1->Execute(); //Ищем нужный файл

if (OpenDialog1->FileName=="") { //Если имя файла пустое то нечего не происходит

}

else //а если имя есть то запускаем следующию конструкцию:

{

RichEdit1->Lines->LoadFromFile(OpenDialog1->FileName);

Form1->Caption="Файл: " + OpenDialog1->FileName;

}

}

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

void __fastcall TForm1::N5Click(TObject *Sender)

{

RichEdit1->Lines->SaveToFile(OpenDialog1->FileName);

}

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

void __fastcall TForm1::N6Click(TObject *Sender)

{

SaveDialog1->Execute() ;

if (SaveDialog1->FileName==""){ //Если имя пустое то нечего

}

else //Если имя указано - то сохраняем:

{

RichEdit1->Lines->SaveToFile(SaveDialog1->FileName);

}

}

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

void __fastcall TForm1::N8Click(TObject *Sender)

{

AnsiString FileName=OpenDialog1->FileName; //Объявляем имя удаляемого файла и присваеваем ему имя открытого фала

if (DeleteFile(FileName)) Form1->Caption="Файл удалён "; // программа успешно удалена, выводиться сообщение.

RichEdit1->Clear(); //Очищаем Memo

}

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

void __fastcall TForm1::N7Click(TObject *Sender)

{

if (PrintDialog1->Execute() )

{

for (int i=1;i<=PrintDialog1->Copies;i++)

{

RichEdit1->Print("");

}

}

}

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

void __fastcall TForm1::N9Click(TObject *Sender)

{

Close();

}

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

void __fastcall TForm1::N10Click(TObject *Sender)

{

if (FontDialog1->Execute() ) //Окно выбора шрифта

{

wcg=RichEdit1->SelAttributes; //Принимаем атрибуты на RichEdit

wcg->Assign(FontDialog1->Font);

RichEdit1->SelAttributes=wcg; //Атрибуты входять в силу

}

}

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

void __fastcall TForm1::N11Click(TObject *Sender)

{

if (ColorDialog1->Execute() ) //Окно выбора цвета

{

wcg=RichEdit1->SelAttributes; //Принимаем цвет

wcg->Color=ColorDialog1->Color;

RichEdit1->SelAttributes=wcg; //Красим текст

}

}

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

#include <vcl.h>

#pragma hdrstop

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

USEFORM("Unit1.cpp", Form1);

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

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)

{

try

{

Application->Initialize();

Application->CreateForm(__classid(TForm1), &Form1);

Application->Run();

}

catch (Exception &exception)

{

Application->ShowException(&exception);

}

catch (...)

{

try

{

throw Exception("");

}

catch (Exception &exception)

{

Application->ShowException(&exception);

}

}

return 0;

}

3.6. Калькулятор C++ Builder 6

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

#include <vcl.h>

#pragma hdrstop

#include "Unit1.h"

#include "Calc.h"

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

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

CCalc Calc;

CSuperCalc SuperCalc;

float operand_1, operand_2;

char znak;

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

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

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

void __fastcall TForm1::Button7Click(TObject *Sender)

{

Edit1->Text=Edit1->Text+'1';

}

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

void __fastcall TForm1::Button10Click(TObject *Sender)

{

Edit1->Text=Edit1->Text+'0';

}

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

void __fastcall TForm1::Button8Click(TObject *Sender)

{

Edit1->Text=Edit1->Text+'2';

}

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

void __fastcall TForm1::Button9Click(TObject *Sender)

{

Edit1->Text=Edit1->Text+'3';

}

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

void __fastcall TForm1::Button4Click(TObject *Sender)

{

Edit1->Text=Edit1->Text+'4';

}

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

void __fastcall TForm1::Button5Click(TObject *Sender)

{

Edit1->Text=Edit1->Text+'5';

}

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

void __fastcall TForm1::Button6Click(TObject *Sender)

{

Edit1->Text=Edit1->Text+'6';

}

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

void __fastcall TForm1::Button1Click(TObject *Sender)

{

Edit1->Text=Edit1->Text+'7';

}

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

void __fastcall TForm1::Button2Click(TObject *Sender)

{

Edit1->Text=Edit1->Text+'8';

}

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

void __fastcall TForm1::Button3Click(TObject *Sender)

{

Edit1->Text=Edit1->Text+'9';

}

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

void __fastcall TForm1::Button11Click(TObject *Sender)

{

Edit1->Text=Edit1->Text+',';

}

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

void __fastcall TForm1::Button15Click(TObject *Sender)

{

operand_1=StrToFloat(Edit1->Text);

Edit1->Clear();

znak='+';

}

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

void __fastcall TForm1::Button17Click(TObject *Sender)

{

float result;

operand_2=StrToFloat(Edit1->Text);

if (znak=='+')

result=SuperCalc.Add(operand_1,operand_2);

if (znak=='-')

result=SuperCalc.Vid(operand_1,operand_2);

if (znak=='*')

result=SuperCalc.Mul(operand_1,operand_2);

if (znak=='/')

result=SuperCalc.Dil(operand_1,operand_2);

if (znak=='+/-')

result=SuperCalc.PlusMinus(operand_1);

Edit1->Text=FloatToStr(result);

}

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

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)

{

Calc.~CCalc();

}

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

void __fastcall TForm1::Button14Click(TObject *Sender)

{

operand_1=StrToFloat(Edit1->Text);

Edit1->Clear();

znak='-';

}

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

void __fastcall TForm1::Button13Click(TObject *Sender)

{

operand_1=StrToFloat(Edit1->Text);

Edit1->Clear();

znak='*';

}

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

void __fastcall TForm1::Button12Click(TObject *Sender)

{

operand_1=StrToFloat(Edit1->Text);

Edit1->Clear();

znak='/';

}

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

void __fastcall TForm1::Button19Click(TObject *Sender)

{

operand_1=StrToFloat(Edit1->Text);

Edit1->Clear();

float result=SuperCalc.Sqrt(operand_1);

Edit1->Text=FloatToStr(result);

}

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

void __fastcall TForm1::Button16Click(TObject *Sender)

{

operand_1=0;

operand_2=0;

Edit1->Clear();

}

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

void __fastcall TForm1::Button20Click(TObject *Sender)

{

operand_1=StrToFloat(Edit1->Text);

operand_1*=-1;

Edit1->Text=FloatToStrF(operand_1,2,1,0);

}

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

void __fastcall TForm1::Button18Click(TObject *Sender)

{

operand_1=StrToFloat(Edit1->Text);

Edit1->Clear();

float result=SuperCalc.Sqr(operand_1);

Edit1->Text=FloatToStr(result);

}

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

void __fastcall TForm1::Button21Click(TObject *Sender)

{

operand_1=StrToFloat(Edit1->Text);

Edit1->Clear();

float result=SuperCalc.Sqrw(operand_1);

Edit1->Text=FloatToStr(result);

}

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

#include <vcl.h>

#pragma hdrstop

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

USEFORM("Unit1.cpp", Form1);

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

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)

{

try

{

Application->Initialize();

Application->CreateForm(__classid(TForm1), &Form1);

Application->Run();

}

catch (Exception &exception)

{

Application->ShowException(&exception);

}

catch (...)

{

try

{

throw Exception("");

}

catch (Exception &exception)

{

Application->ShowException(&exception);

}

}

return 0;

}

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

#include <vcl.h>

#pragma hdrstop

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

USEFORM("Unit1.cpp", Form1);

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

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)

{

try

{

Application->Initialize();

Application->CreateForm(__classid(TForm1), &Form1);

Application->Run();

}

catch (Exception &exception)

{

Application->ShowException(&exception);

}

catch (...)

{

try

{

throw Exception("");

}

catch (Exception &exception)

{

Application->ShowException(&exception);

}

}

return 0;

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]