- •Ознакомление с Интегрированной Средой Разработки (иср)
- •(I)Основное окно иср
- •Библиографический список
- •Лабораторная работа 1
- •Тестирование и использование приложения.
- •Контрольные вопросы
- •Тестирование и использование приложения.
- •Контрольные вопросы
- •Лабораторная работа 3
- •Задание
- •Проектирование приложения. Выбор, размещение и задание свойств компонентов. Коды классов, функций и обработчиков событий.
- •Тестирование и использование приложения.
- •Заголовочный файл
- •Файл реализации
- •Контрольные вопросы
- •Лабораторная работа 4
- •Введение
- •Алгоритмы шифрования и дешифрования
- •Проектирование приложения. Выбор, размещение и задание свойств компонентов. Коды классов, функций и обработчиков событий.
- •Тестирование и использование приложения.
- •Контрольные вопросы
- •Лабораторная работа 5
- •Введение
- •Алгоритмы
- •Проектирование приложения. Выбор, размещение и задание свойств компонентов. Коды классов, функций и обработчиков событий.
- •Тестирование и использование приложения.
- •Контрольные вопросы
- •Лабораторная работа 6
- •Введение
- •Проектирование приложения. Выбор, размещение и задание свойств компонентов. Коды классов, функций и обработчиков событий.
- •Тестирование и использование приложения.
- •Контрольные вопросы
- •Библиографический список
Тестирование и использование приложения.
Запустите приложение на выполнение, нажав быстрые кнопки Сохранить все и Запуск.
Составьте и выполните тесты, которые проверят правильность сообщений об ошибках.
Выполните тестирование, подобное представленному на рис.6.6.
Убедитесь в правильности сохранения очереди в файле.
Рис.6.1 – главная форма по окончании проектирования
Рис.6.2 – дерево компонентов Рис.6.3 – дерево классов
главной формы проекта
Рис.6.4 – форма «О программе» с деревом компонентов.
Рис.6.5 – форма «О разработчике» с деревом компонентов.
Рис.6.6 – главная форма с результатами тестирования
Заголовочный файл модуля LR_6 главной формы Form1.
//---------------------------------------------------------------------------
#ifndef LR_6H
#define LR_6H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Grids.hpp>
#include <ActnList.hpp>
#include <ComCtrls.hpp>
#include <ImgList.hpp>
#include <Menus.hpp>
#include <ToolWin.hpp>
#include <StdActns.hpp>
#include <Dialogs.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabeledEdit *LabeledEdit5;
TLabel *Label1;
TStringGrid *StringGrid1;
TImageList *ImageList1;
TActionList *ActionList1;
TGroupBox *GroupBox1;
TLabeledEdit *LabeledEdit1;
TLabeledEdit *LabeledEdit2;
TLabeledEdit *LabeledEdit3;
TLabeledEdit *LabeledEdit4;
TGroupBox *GroupBox2;
TLabeledEdit *LabeledEdit6;
TLabeledEdit *LabeledEdit7;
TLabeledEdit *LabeledEdit8;
TLabeledEdit *LabeledEdit9;
TAction *A_add;
TAction *A_del;
TAction *A_clr;
TAction *A_help;
TAction *A_wrt;
TMainMenu *MainMenu1;
TMenuItem *N1;
TMenuItem *N2;
TMenuItem *N3;
TMenuItem *N4;
TMenuItem *N5;
TMenuItem *N6;
TMenuItem *N7;
TMenuItem *N8;
TMenuItem *N9;
TMenuItem *N10;
TMenuItem *N11;
TToolBar *ToolBar1;
TToolButton *ToolButton1;
TToolButton *ToolButton2;
TToolButton *ToolButton3;
TToolButton *ToolButton4;
TToolButton *ToolButton5;
TToolButton *ToolButton6;
TToolButton *ToolButton7;
TOpenDialog *OpenDialog1;
TSaveDialog *SaveDialog1;
TAction *A_fsave;
TAction *A_fopen;
void __fastcall A_addExecute(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall A_delExecute(TObject *Sender);
void __fastcall A_clrExecute(TObject *Sender);
void __fastcall A_helpExecute(TObject *Sender);
void __fastcall A_wrtExecute(TObject *Sender);
void __fastcall N11Click(TObject *Sender);
void __fastcall A_fsaveExecute(TObject *Sender);
void __fastcall A_fopenExecute(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Файл реализации модуля LR_6 главной формы Form1.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "LR_6.h"
#include "f_6.h"
#include<string.h>
#include "LR_6_1.h"
#include "LR_6_2.h"
#include<stdio.h>
#include<fstream.h>
#include<ctype.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
queue q;
void __fastcall TForm1::A_addExecute(TObject *Sender)
{
LabeledEdit6->Text="";
LabeledEdit7->Text="";
LabeledEdit9->Text="";
LabeledEdit8->Text="";
if(LabeledEdit1->Text=="")
{MessageBox(NULL,"Введите Фамилия И.О.!","Ошибка",0);
LabeledEdit1->SetFocus();
return;
}
if(LabeledEdit2->Text=="")
{MessageBox(NULL,"Введите Устройство!","Ошибка",0);
LabeledEdit2->SetFocus();
return;
}
if(LabeledEdit3->Text==""||!isdigit(LabeledEdit3->Text[1]))
{MessageBox(NULL,"Введите Приоритет!","Ошибка",0);
LabeledEdit3->SetFocus();
return;
}
if(LabeledEdit4->Text=="")
{MessageBox(NULL,"Введите Описание работ!","Ошибка",0);
LabeledEdit4->SetFocus();
return;
}
LabeledEdit5->Text=IntToStr(q.get_size());
Node* pd;
pd=new Node;
pd->name = new char[50];
strcpy(pd->name,LabeledEdit1->Text.c_str());
pd->model = new char[50];
strcpy(pd->model,LabeledEdit2->Text.c_str());
pd->work = new char[50];
strcpy(pd->work,LabeledEdit4->Text.c_str());
pd->priority=StrToInt(LabeledEdit3->Text.c_str());
q.insert(q.get_size(),pd);
LabeledEdit5->Text=IntToStr(q.get_size());
LabeledEdit1->Clear();
LabeledEdit2->Clear();
LabeledEdit3->Clear();
LabeledEdit4->Clear();
LabeledEdit1->SetFocus();
StringGrid1->RowCount++;
int i=q.get_size()-1;
StringGrid1->Cells[0][i+1]=
(AnsiString)(q.get_mas_dat(i).get_dat()->name);
StringGrid1->Cells[1][i+1]=
(AnsiString)(q.get_mas_dat(i).get_dat()->model);
StringGrid1->Cells[2][i+1]=
(AnsiString)(q.get_mas_dat(i).get_dat()->work);
StringGrid1->Cells[3][i+1]=
IntToStr(q.get_mas_dat(i).get_dat()->priority);
delete[]pd->name;
delete[]pd->model;
delete[]pd->work;
delete pd;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
LabeledEdit5->Text="0";
StringGrid1->FixedRows=1;
StringGrid1->RowCount=1;
StringGrid1->FixedCols=0;
StringGrid1->ColCount=4;
StringGrid1->Cells[0][0]="Фамилия И.О.";
StringGrid1->Cells[1][0]="Устройство";
StringGrid1->Cells[2][0]="Описание работ";
StringGrid1->Cells[3][0]="Приоритет";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::A_delExecute(TObject *Sender)
{
LabeledEdit6->Clear();
LabeledEdit7->Clear();
LabeledEdit9->Clear();
LabeledEdit8->Clear();
if(!(q.get_size()))
{
MessageBox(NULL,"Очередь пуста!","",0);
return;
}
data d=q.del();
LabeledEdit5->Text=IntToStr(q.get_size());
LabeledEdit6->Text=(AnsiString)d.get_dat()->name;
LabeledEdit7->Text=(AnsiString)d.get_dat()->model;
LabeledEdit9->Text=(AnsiString)d.get_dat()->work;
LabeledEdit8->Text=IntToStr(d.get_dat()->priority);
int i=0;
while(i<q.get_size())
{
StringGrid1->Cells[0][i+1]=
(AnsiString)(q.get_mas_dat(i).get_dat()->name);
StringGrid1->Cells[1][i+1]=
(AnsiString)(q.get_mas_dat(i).get_dat()->model);
StringGrid1->Cells[2][i+1]=
(AnsiString)(q.get_mas_dat(i).get_dat()->work);
StringGrid1->Cells[3][i+1]=
IntToStr(q.get_mas_dat(i).get_dat()->priority);
i++;
}
StringGrid1->RowCount--;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::A_clrExecute(TObject *Sender)
{
if(!(q.get_size()))
{
MessageBox(NULL,"Очередь пуста!","",0);
return;
}
q.queue_clear();
StringGrid1->RowCount=1;
LabeledEdit1->Clear();
LabeledEdit2->Clear();
LabeledEdit3->Clear();
LabeledEdit4->Clear();
LabeledEdit5->Text=IntToStr(q.get_size());
LabeledEdit6->Clear();
LabeledEdit7->Clear();
LabeledEdit8->Clear();
LabeledEdit1->SetFocus();
if(!(q.get_size()))
{
MessageBox(NULL,"Очередь уничтожена!","",0);
return;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::A_helpExecute(TObject *Sender)
{
Form1->Enabled=false;
Form2->Show();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::A_wrtExecute(TObject *Sender)
{
Form1->Enabled=false;
Form3->Show();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N11Click(TObject *Sender)
{
if(q.get_size()>0)
q.queue_clear();
Close();
}
//---------------------------------------------------------------------------
AnsiString fn;
//---------------------------------------------------------------------------
void __fastcall TForm1::A_fsaveExecute(TObject *Sender)
{
if(SaveDialog1->Execute())
{
fn=SaveDialog1->FileName;
ofstream outfile(fn.c_str(),ios::out);
if(!outfile)
{
MessageBox(NULL,"Файл не удается создать!","Ошибка",0);
return;
}
int s=q.get_size();
outfile.write((char*)&s,sizeof(s));
for(int i=0; i<s; i++)
{
outfile.write((char*)q.get_mas_dat(i).get_dat()->name,50);
outfile.write((char*)q.get_mas_dat(i).get_dat()->model,50);
outfile.write((char*)q.get_mas_dat(i).get_dat()->work,50);
outfile.write((char*)&(q.get_mas_dat(i).get_dat()->priority),sizeof(int));
}
outfile.close();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::A_fopenExecute(TObject *Sender)
{
if(q.get_size()>0)
q.queue_clear();
StringGrid1->RowCount=1;
LabeledEdit5->Text="";
if(OpenDialog1->Execute())
{
fn=OpenDialog1->FileName;
ifstream infile(fn.c_str(),ios::in);
if(!infile)
{
MessageBox(NULL,"Файл не удается открыть!","Ошибка",0);
return;
}
int s;
infile.read((char*)&s,sizeof(s));
for(int i=0; i<s; i++)
{
Node*pd=new Node;
pd->name=new char[50];
pd->model=new char[50];
pd->work=new char[50];
infile.read((char*)pd->name,50);
infile.read((char*)pd->model,50);
infile.read((char*)pd->work,50);
infile.read((char*)&(pd->priority),sizeof(int));
q.insert(i,pd);
StringGrid1->RowCount++;
StringGrid1->Cells[0][i+1]=
(AnsiString)(q.get_mas_dat(i).get_dat()->name);
StringGrid1->Cells[1][i+1]=
(AnsiString)(q.get_mas_dat(i).get_dat()->model);
StringGrid1->Cells[2][i+1]=
(AnsiString)(q.get_mas_dat(i).get_dat()->work);
StringGrid1->Cells[3][i+1]=
IntToStr(q.get_mas_dat(i).get_dat()->priority);
delete[]pd->name;
delete[]pd->model;
delete[]pd->work;
delete pd;
}
q.set_size(s);
LabeledEdit5->Text=IntToStr(q.get_size());
if(!q.get_size())
{
MessageBox(NULL,"Очередь пуста!","",0);
return;
}
infile.close();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
if(q.get_size()>0)
q.queue_clear();
}
//---------------------------------------------------------------------------
Заголовочный файл модуля LR_6_1 формы Form2.
//---------------------------------------------------------------------------
#ifndef LR_6_1H
#define LR_6_1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
TMemo *Memo1;
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private: // User declarations
public: // User declarations
__fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif
Файл реализации модуля LR_6_1 формы Form2.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "LR_6_1.h"
#include "LR_6.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
Form1->Enabled=true;
}
//---------------------------------------------------------------------------
Заголовочный файл модуля LR_6_2 формы Form3.
//---------------------------------------------------------------------------
#ifndef LR_6_2H
#define LR_6_2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm3 : public TForm
{
__published: // IDE-managed Components
TMemo *Memo1;
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private: // User declarations
public: // User declarations
__fastcall TForm3(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm3 *Form3;
//---------------------------------------------------------------------------
#endif
Файл реализации модуля LR_6_2 формы Form3.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "LR_6_2.h"
#include "LR_6.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm3::FormClose(TObject *Sender, TCloseAction &Action)
{
Form1->Enabled=true;
}
//---------------------------------------------------------------------------