О.О.П / ООП Лабораторные работы / Лабораторная работа №6 / Лабораторка оформление
.docЛабораторна робота № 6
Тема: Обробка двомірних динамічних масивів.
Мета: вивчити поняття «покажчик», правила створення і прийоми обробки динамічних масивів на прикладі двомірного масиву.
|
Свойство |
Описание |
Name |
Имя компонента. Используется в программе для доступа к компоненту и его свойствам |
|
ColCount |
Количество колонок таблицы |
|
RowCount |
Количество строк таблицы |
|
DefaultColWidth |
Ширина колонок таблицы |
|
DefaultRowHeight |
Высота строк таблицы |
|
FixedCols |
Количество зафиксированных слева колонок таблицы. Зафиксированные колонки выделяются цветом и при горизонтальной прокрутке таблицы остаются на месте |
|
FixedRows |
Количество зафиксированных сверху строк таблицы. Зафиксированные строки выделяются цветом и при вертикальной прокрутке таблицы остаются на месте |
|
Cells |
Соответствующий таблице двумерный массив. Ячейке таблицы, находящейся на пересечении столбца с номером col и строки с номером row, соответствует элемент cells [col] [row] |
|
GridLineWidth |
Ширина линий, ограничивающих ячейки таблицы |
|
Left |
Расстояние от левой границы поля таблицы до левой границы формы |
|
Top |
Расстояние от верхней границы поля таблицы до верхней границы формы |
Властивості Align, Constraints, Cursor, Enabled, Font, Height, Hint, ShowHint, Left, ParentColor, ParentFont, ParentShowHint, Name, PopupMenu, Top, Transparent, Visible, Width і деякі інші є загальними для багатьох компонентов.тся загальними для багатьох компонентів .
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int n=3;
double a[20][20];
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Edit1 ->Text=IntToStr(n);
StringGrid1 ->ColCount = n+1; StringGrid1 ->RowCount = n+1;
// Введення в лівий верхній елемент таблиці назви масивів
StringGrid1 ->Cells[0][0] = "Матриця A";
for(int i=1; i<=n;i++){
StringGrid1 ->Cells[0][i]="i="+IntToStr(i);
StringGrid1 ->Cells[i][0]="j="+IntToStr(i);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
int i;
n=StrToInt(Edit1 ->Text);
StringGrid1 ->ColCount = n+1; StringGrid1 ->RowCount = n+1;
for(i=1; i<=n;i++){
StringGrid1 ->Cells[0][i]="i="+IntToStr(i);
StringGrid1 ->Cells[i][0]="j="+IntToStr(i);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double s;
int max=0, i, j;
for(i=0; i<n;i++) for(j=0; j<n;j++)
a[i][j]=StrToFloat(StringGrid1 ->Cells[i+1][j+1]);
max=a[1][n-1];
for (i = 0; i < n; i++){
for (j=n - i; j < n; j++)
{
if(max<a[i][j]) max=a[i][j];
Label3->Caption=IntToStr(max);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
delete []a;
ShowMessage("Память освобождена");
Close();
}
//---------------------------------------------------------------------------
Прогр. Код идз
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
int n = 3;
double **a, *b;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Edit1 ->Text=IntToStr(n);
StringGrid1 ->ColCount = n+1; StringGrid1 ->RowCount = n+1;
StringGrid2 ->RowCount = n+1; StringGrid3 ->RowCount = n+1;
// Введення в лівий верхній елемент таблиці назви масивів
StringGrid1 ->Cells[0][0] = "Матрица A";
StringGrid2 ->Cells[0][0] = "Массив B";
StringGrid3 ->Cells[0][0] = "Массив C";
for(int i=1; i<=n;i++){
StringGrid1 ->Cells[0][i]="i="+IntToStr(i);
StringGrid1 ->Cells[i][0]="j="+IntToStr(i);
}
Randomize ();
for(int i=1; i<n+1;i++)
{
for(int j=1; j<n+1;j++)
StringGrid1 ->Cells[i][j] = IntToStr(random(21) - 10);
}
Randomize ();
for(int j=1; j<n+1;j++)
StringGrid2 ->Cells[0][j] = IntToStr(random(21) - 10);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
int i;
n=StrToInt(Edit1 ->Text);
StringGrid1 ->ColCount = n+1; StringGrid1 ->RowCount = n+1;
StringGrid2 ->RowCount = n+1; StringGrid3 ->RowCount = n+1;
for(i=1; i<=n;i++){
StringGrid1 ->Cells[0][i]="i="+IntToStr(i);
StringGrid1 ->Cells[i][0]="j="+IntToStr(i);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double s;
int i, j;
a = new double*[n]; // Захоплення пам'яті під покажчики
for(i=0; i<n;i++) a[i] = new double[n]; // Захоплення пам'яті під елементи
b = new double[n];
// Заповнення масивів А і В елементами з таблиць StringGrid1 і StringGrid2
for(i=0; i<n;i++){
for(j=0; j<n;j++) a[i][j]=StrToFloat(StringGrid1 ->Cells[j+1][i+1]);
b[i]=StrToFloat(StringGrid2 ->Cells[0][i+1]);
}
// Множення рядка матриці А на вектор В і виведення результату s в StringGrid3
for(i=0; i<n;i++){
for(s=0, j=0; j<n;j++) s += a[i][j]*b[j];
StringGrid3 ->Cells[0][i+1] = FloatToStrF(s, ffFixed, 8,2);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
delete []a;
delete []b;
ShowMessage("Память очищена!");
Close();
}
//---------------------------------------------------------------------------