- •Объектно-ориентированной технологии программирования
- •5. Список используемой литературы…………………..……..…………....…..….. 36
- •6. Приложение. А………………….………..……….……………………..….....… 37 Введение
- •1.Теоретические основы ооп
- •2.Техническое задание.
- •2.1.Анализ предметной области.
- •2.1.1 Матрицы
- •2.1.2 Определители.
- •2.2.Проектирование программного продукта
- •2.2.1. Функциональные требования
- •2.2.2. Требования к интерфейсу
- •3.Рабочий проект
- •3.2. Укрупненный алгоритм
- •3.2.1.Классы
- •3.2.2.Модули
- •3.2.3.Схема алгоритма
- •3.2.4.Обработка исключений
- •3.2.Руководство пользователя
- •4. Заключение
- •5.Список использованной литературы.
- •6.Приложение а. Исходный текст программы.
4. Заключение
Данная программа является типичным примером реализации программ использованием объектно-ориентированной технологии программирования
созданных для Windows с помощью Borland C++ Builder.
Достоинством данной программы является ее простота в использовании в наиболее распространенной, на данный момент, операционной системе Windows и то, что при необходимости можно добавить нужные кнопки-функции.
Недостаток программы в том, что при наборе очень сложных функций одновременно программа выдает ошибку набора. Поэтому чтобы избежать этой ошибки необходимо соблюдать последовательность и правильность набора команд.
5.Список использованной литературы.
Бьерн Страуструп «Язык программирования C++» специальное издание. Москва, Санкт – Петербург,2002.
Г.Шилдт «Теория и практика Си++.» СПб.:BHV– Санкт-Петербург, 1996.
Н. Подбельский «Язык С++»; Питер, Санкт – Петербург 2004.
Валерий Лаптев «С++ Экспресс курс», БХВ – Санкт-Петербург, 2004.
А.Я. Лемих «С/С++ в примерах и задачах» Москва, 2004.
Кун С. «Матричные процессоры на СБИС». М. 1991
«Транспьютеры. Архитектура и ПО». Пер. с англ./ Под ред. Г. Харпа.- М.: Радио и связь, 1993.
«СуперЭВМ. Аппаратная и программная организация.»/ Под ред. С.Фернбаха. Пер. с англ. - М.: Радио и связь, 1991.
«Вычислительные комплексы, системы и сети» / А.М.Ларионов, С.А.Майоров, Г.И.Новиков: Учебник для вузов. Л:Энергоиздат. Ленингр.отд-ние, 1987.
«Фути К., Судзуки Н. Языки программирования и схемотехника» СБИС: Пер. с япон. М.: Мир, 1988.
Головкин Б.А. «Параллельные вычислительные системы». М.:Наука, 1980.
Н.Культин «Практика программирования на С++». «Питер», Санкт – Петербург 2003.
А.Л. Фридман «Язык программирования С++ » курс лекций; Интернет Университет Информационных технологий; Москва 2003
Т.А. Павловская «С/С++ Программирование на языке высокого уровня» учебник для вузов; Питер, Санкт – Петербург 2004.
http://www.parallel.ru
http://www.rusmath.ru
6.Приложение а. Исходный текст программы.
Project1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", Form1);
USEFORM("Unit3.cpp", AboutBox);
USEFORM("Unit4.cpp", AboutBox1);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->CreateForm(__classid(TAboutBox), &AboutBox);
Application->CreateForm(__classid(TAboutBox1), &AboutBox1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
Unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
#ifndef File1H
#define File1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "CSPIN.h"
#include <ExtCtrls.hpp>
#include <Grids.hpp>
#include "Unit2.h"
class TMatrix;
//---------------------------------------------------------------------------
class NSquare {};
class InsideError {};
class NRightSize {};
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TPanel *Panel1;
TStringGrid *StringGrid1;
TPanel *Panel2;
TStringGrid *StringGrid2;
TPanel *Panel3;
TStringGrid *StringGrid3;
TPanel *Panel11;
TButton *Button0;
TGroupBox *GroupBox12;
TEdit *Edit1;
TPanel *Panel13;
TButton *ButtonC;
TGroupBox *GroupBox14;
TButton *Button2;
TButton *Button3;
TLabel *Label3;
TPanel *Panel15;
TButton *Button7;
TButton *Button6;
TButton *Button5;
TPanel *Panel16;
TButton *Button17;
TButton *Button15;
TButton *Button16;
TButton *Button11;
TButton *Button12;
TEdit *Edit1_1;
TButton *Button1_1P;
TButton *Button1_1M;
TButton *Button1_2P;
TButton *Button1_2M;
TEdit *Edit1_2;
TButton *Button2_1P;
TButton *Button2_1M;
TEdit *Edit2_1;
TButton *Button2_2P;
TButton *Button2_2M;
TEdit *Edit2_2;
TButton *Button3_2;
TButton *Button3_1;
TLabel *Label3_1;
TLabel *Label3_2;
TButton *Button10;
TButton *Button18;
TLabel *Label1;
TLabel *Label2;
TButton *Button8;
TButton *Button1;
TLabel *Label4;
TLabel *Label5;
TLabel *Label6;
TLabel *Label7;
TLabel *Label8;
TLabel *Label9;
void __fastcall Button6Click(TObject *Sender);
void __fastcall Button5Click(TObject *Sender);
void __fastcall Button7Click(TObject *Sender);
void __fastcall Button3_1Click(TObject *Sender);
void __fastcall Button3_2Click(TObject *Sender);
void __fastcall ButtonCClick(TObject *Sender);
void __fastcall Button15Click(TObject *Sender);
void __fastcall Button1_1PClick(TObject *Sender);
void __fastcall Button1_1MClick(TObject *Sender);
void __fastcall Button1_2PClick(TObject *Sender);
void __fastcall Button1_2MClick(TObject *Sender);
void __fastcall Button2_1PClick(TObject *Sender);
void __fastcall Button2_1MClick(TObject *Sender);
void __fastcall Button2_2PClick(TObject *Sender);
void __fastcall Button2_2MClick(TObject *Sender);
void __fastcall StringGrid1Click(TObject *Sender);
void __fastcall StringGrid2Click(TObject *Sender);
void __fastcall Button16Click(TObject *Sender);
void __fastcall Button12Click(TObject *Sender);
void __fastcall Button11Click(TObject *Sender);
void __fastcall StringGrid1Exit(TObject *Sender);
void __fastcall StringGrid2Exit(TObject *Sender);
void __fastcall Button10Click(TObject *Sender);
void __fastcall Button17Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
void __fastcall Button8Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button0Click(TObject *Sender);
private:
// User declaration
TMatrix _Mat1,
_Mat2,
_Res,
_Mem;
int _Memory;
int _SG1_R,
_SG1_C,
_SG2_R,
_SG2_C;
int _Edit1Num;
int _SGFocusInt;
TStringGrid *_SGFocus;
TMatrix *_MatFocus;
public:
// User declarations
__fastcall TForm1(TComponent* Owner);
TForm1 :: ReadMemory();
TForm1 :: WriteMemory();
TForm1 :: ReadForm();
TForm1 :: ReadMatrix();
TForm1 :: WriteForm();
TForm1 :: WriteMatrix();
TForm1 :: StringRight(AnsiString *String);
TForm1 :: Print(int Index);
TForm1 :: SGRight(int SGNUM);
TForm1 :: ExceptCatch(int ErrCode);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
#endif
Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
#include "Unit4.h"
#include "File2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CSPIN"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
_Mat1.InitZero();
_Mat2.InitZero();
_SG1_R = 3;
_SG1_C = 3;
_SG2_R = 3;
_SG2_C = 3;
_SGFocus = StringGrid1;
_MatFocus = &_Mat1;
_Memory = 0;
_SGFocusInt = 1;
for (int i = 1; i <= SGMAX; i++)
{
StringGrid1->Cells[i][0] = IntToStr(i);
StringGrid2->Cells[i][0] = IntToStr(i);
StringGrid3->Cells[i][0] = IntToStr(i);
}
for (int i = 1; i <= SGMAX; i++)
{
StringGrid1->Cells[0][i] = IntToStr(i);
StringGrid2->Cells[0][i] = IntToStr(i);
StringGrid3->Cells[0][i] = IntToStr(i);
}
for (int i = 1; i < SGMAX ; i++)
for (int j = 1; j < SGMAX; j++)
{
StringGrid1->Cells[j][i] = "0";
StringGrid2->Cells[j][i] = "0";
StringGrid3->Cells[j][i] = "0";
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
try
{
ReadForm();
_Res.MSumm(_Mat1, _Mat2);
WriteForm();
}
catch (int ExceptCode)
{
ExceptCatch(ExceptCode);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
try
{
ReadForm();
_Res.MMult(_Mat1, _Mat2);
WriteForm();
}
catch (int ErrCode)
{
ExceptCatch(ErrCode);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button7Click(TObject *Sender)
{
try
{
ReadForm();
_Res.MDiff(_Mat1, _Mat2);
WriteForm();
}
catch (int ErrCode)
{
ExceptCatch(ErrCode);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3_1Click(TObject *Sender)
{
StringGrid1->RowCount = StringGrid3->RowCount;
StringGrid1->ColCount = StringGrid3->ColCount;
Edit1_1->Text = IntToStr(_SG1_R = StringGrid1->RowCount - 1);
Edit1_2->Text = IntToStr(_SG1_C = StringGrid1->ColCount - 1);
_Mat1 = _Res;
Print(1);
}
............................................
И т.д.
File1.cpp
#include "Unit1.h"
#include "Unit2.h"
#include "Unit4.h"
//---------------------------------------------------------------------------
TForm1::ReadForm()
{
SGRight(1);
SGRight(2);
_Mat1.InitNewMatrix1(_SG1_R, _SG1_C);
for (int i = 0; i < _SG1_R; i++)
for (int j = 0; j < _SG1_C; j++)
_Mat1.InitElem(i, j, StrToInt(StringGrid1->Cells[j + 1][i + 1]));
_Mat2.InitNewMatrix1(_SG2_R, _SG2_C);
for (int i = 0; i < _SG2_R; i++)
for (int j = 0; j < _SG2_C; j++)
_Mat2.InitElem(i, j, StrToInt(StringGrid2->Cells[j + 1][i + 1]));
}
//---------------------------------------------------------------------------
TForm1::WriteForm()
{
StringGrid3->RowCount = _Res._NNUM1 + 1;
StringGrid3->ColCount = _Res._NNUM2 + 1;
Label3_1->Caption = IntToStr(_Res._NNUM1);
Label3_2->Caption = IntToStr(_Res._NNUM2);
for (int i = 0; i < _Res._NNUM1; i++)
for (int j = 0; j < _Res._NNUM2; j++)
StringGrid3->Cells[j+1][i+1] = IntToStr(_Res.GetElem(i, j));
}
//---------------------------------------------------------------------------
TForm1 :: Print(int Index)
{
if (Index == 1)
{
for (int i = 0; i < _Mat1._NNUM1; i++)
for (int j = 0; j < _Mat1._NNUM2; j++)
StringGrid1->Cells[j+1][i+1] = IntToStr(_Mat1.GetElem(i, j));
}
if (Index == 2)
{
for (int i = 0; i < _Mat2._NNUM1; i++)
for (int j = 0; j < _Mat2._NNUM2; j++)
StringGrid2->Cells[j+1][i+1] = IntToStr(_Mat2.GetElem(i, j));
}
}
//---------------------------------------------------------------------------
TForm1 :: ReadMatrix()
{
SGRight(_SGFocusInt);
int N1 = _SGFocus->RowCount - 1;
int N2 = _SGFocus->ColCount - 1;
_MatFocus->InitNewMatrix1(N1, N2);
for (int i = 0; i < N1; i++)
for (int j = 0; j < N2; j++)
_MatFocus->InitElem(i, j, StrToInt(_SGFocus->Cells[j + 1][i + 1]));
}
//---------------------------------------------------------------------------
TForm1 :: WriteMatrix()
{
for (int i = 0; i < _MatFocus->_NNUM1; i++)
for (int j = 0; j < _MatFocus->_NNUM2; j++)
_SGFocus->Cells[j + 1][i + 1] = IntToStr(_MatFocus->GetElem(i, j));
}
//---------------------------------------------------------------------------
TForm1 :: ReadMemory()
{
SGRight(_SGFocusInt);
int N1 = _SGFocus->RowCount - 1;
int N2 = _SGFocus->ColCount - 1;
_Mem.InitNewMatrix1(N1, N2);
for (int i = 0; i < N1; i++)
for (int j = 0; j < N2; j++)
_Mem.InitElem(i, j, StrToInt(_SGFocus->Cells[j + 1][i + 1]));
}
//---------------------------------------------------------------------------
TForm1 :: WriteMemory()
{
_SGFocus->RowCount = _Mem._NNUM1 + 1;
_SGFocus->ColCount = _Mem._NNUM2 + 1;
for (int i = 0; i < _MatFocus->_NNUM1; i++)
for (int j = 0; j < _MatFocus->_NNUM2; j++)
_SGFocus->Cells[j + 1][i + 1] = IntToStr(_Mem.GetElem(i, j));
}
//---------------------------------------------------------------------------
TForm1 :: ExceptCatch(int ErrCode)
{
switch (ErrCode)
{
case 1:
{
AboutBox1->Label1->Caption = "WRONG SIZE";
AboutBox1->Label2->Caption = "The matrix must be square";
}
break;
case 2:
{
AboutBox1->Label1->Caption = "WRONG SIZE";
AboutBox1->Label2->Caption = "Both matrixes must have same size";
}
break;
case 3:
{
AboutBox1->Label1->Caption = "WRONG DATA";
AboutBox1->Label2->Caption = "The matrix must have only integers";
}
break;
case 4:
{
AboutBox1->Label1->Caption = "WRONG DATA";
AboutBox1->Label2->Caption = "The edit area must have an integer";
}
break;
case 5:
{
AboutBox1->Label1->Caption = "WRONG SIZE";
AboutBox1->Label2->Caption = "Bad size of second matrix";
}
break;
case 10:
{
AboutBox1->Label1->Caption = "INSIDE ERROR";
AboutBox1->Label2->Caption = "Bad index";
}
break;
default:
{
AboutBox1->Label1->Caption = "NEW ERROR";
AboutBox1->Label2->Caption = "";
}
break;
}
AboutBox1->ShowModal();
}
//---------------------------------------------------------------------------
TForm1 :: SGRight(int SGNUM)
{
TStringGrid *SG;
AnsiString buf;
if (SGNUM == 1) SG = StringGrid1;
if (SGNUM == 2) SG = StringGrid2;
for (int i = 1; i < SG->RowCount; i++)
for (int j = 1; j < SG->RowCount; j++)
{
if (SG->Cells[i][j] == "")
{
SG->Cells[i][j] = "0";
throw 3;
}
for (int k = 1; k < SG->Cells[i][j].Length(); k++)
{
if (((SG->Cells[i][j])[k] > 57) || ((SG->Cells[i][j])[k] < 48))
if ((SG->Cells[i][j])[k] != 45)
{
SG->Cells[i][j] = "0";
throw 3;
}
}
}
}
//---------------------------------------------------------------------------
Unit2.h
//---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
//*****************************************************************************
//******************************* CLASS TMATRIX *******************************
//*****************************************************************************
class TMatrix
{
private:
//----------------- ??????????
int **_mat;
public:
unsigned char _NNUM1, _NNUM2;
//----------------- Constructors
TMatrix();
TMatrix(int);
//----------------- Metods
//----------- Init operations
void InitRandom();
void InitZero();
void InitE();
//----------- One element operations
void InitElem(int, int, int);
int GetElem(int, int);
//----------- Matrix operations
void MScalMult(int);
void MSumm(TMatrix &, TMatrix &);
void MDiff(TMatrix &, TMatrix &);
void MMult(TMatrix &, TMatrix &);
void MNegative();
void MTrans();
void MMod();
void MMin();
//----------- Size operations
void DeleteOldMatrix();
void InitNewMatrix1();
void InitNewMatrix1(int, int);
};
//---------------------------------------------------------------------------
#endif
Unit2.cpp
//---------------------------------------------------------------------------
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.h"
//*****************************************************
//********************* Constructors ******************
//*****************************************************
TMatrix :: TMatrix(void)
{
_NNUM1 = 3;
_NNUM2 = 3;
_mat = new int *[_NNUM1];
for (int i = 0; i < _NNUM1; i++)
_mat[i] = new int[_NNUM2];
for (int i = 0; i < _NNUM1; i++)
for (int j = 0; j < _NNUM2; j++)
_mat[i][j] = 0;
}
//*****************************************************************************
TMatrix :: TMatrix(int InitNum)
{
_NNUM1 = 3;
_NNUM2 = 3;
_mat = new int *[_NNUM1];
for (int i = 0; i < _NNUM1; i++)
_mat[i] = new int[_NNUM2];
for (int i = 0; i < _NNUM1; i++)
for (int j = 0; j < _NNUM2; j++)
_mat[i][j] = InitNum;
}
//***************************************************************************
//***************************** CLASS FUNCTIONS
//***************************************************************************
//***************************** INITNEWMATRIX
void TMatrix :: InitNewMatrix1(int m, int n)
{
_NNUM1 = m;
_NNUM2 = n;
_mat = new int *[_NNUM1];
for (int i = 0; i < _NNUM1; i++)
_mat[i] = new int[_NNUM2];
for (int i = 0; i < _NNUM1; i++)
for (int j = 0; j < _NNUM2; j++)
_mat[i][j] = rand()%100-50;
}
//***************************** DELETEOLDMATRIX
void TMatrix :: DeleteOldMatrix()
{
for (int i = 0; i < _NNUM1; i++)
delete _mat[i];
_NNUM1 = 0;
_NNUM2 = 0;
}
//***************************** INITRANDOM
void TMatrix :: InitRandom()
{
for (int i = 0; i < _NNUM1; i++)
for (int j = 0; j < _NNUM2; j++)
_mat[i][j] = rand()%100-50;
}
//***************************** INITE
void TMatrix :: InitE()
{
if (_NNUM1 != _NNUM2)
throw 1;
for (int i = 0; i < _NNUM1; i++)
for (int j = 0; j < _NNUM2; j++)
if (i == j)
_mat[i][j] = 1;
else
_mat[i][j] = 0;
}
//***************************** MSCALMULT
void TMatrix :: MScalMult(int Scal)
{
for (int i = 0; i < _NNUM1; i++)
for (int j = 0; j < _NNUM2; j++)
_mat[i][j] *= Scal;
}
//***************************** MSUMM
void TMatrix :: MSumm(TMatrix & A, TMatrix & B)
{
if ((A._NNUM1 != B._NNUM1) || (A._NNUM2 != B._NNUM2))
throw 2;
InitNewMatrix1(A._NNUM1, A._NNUM2);
for (int i = 0; i < _NNUM1; i++)
for (int j = 0; j < _NNUM2; j++)
_mat[i][j] = A._mat[i][j] + B._mat[i][j];
}
//***************************** MDIFF
void TMatrix :: MDiff(TMatrix & A, TMatrix & B)
{
if ((A._NNUM1 != B._NNUM1) || (A._NNUM2 != B._NNUM2))
throw 2;
InitNewMatrix1(A._NNUM1, A._NNUM2);
for (int i = 0; i < _NNUM1; i++)
for (int j = 0; j < _NNUM2; j++)
_mat[i][j] = A._mat[i][j] - B._mat[i][j];
}
//***************************** MMULT
void TMatrix :: MMult(TMatrix & A, TMatrix & B)
{
if (A._NNUM2 != B._NNUM1)
throw 5;
InitNewMatrix1(A._NNUM1, B._NNUM2);
for (int i = 0; i < _NNUM1; i++)
for (int j = 0; j < _NNUM2; j++)
{
_mat[i][j] = 0;
for (int k = 0; k < A._NNUM2; k++)
_mat[i][j] += A._mat[i][k] * B._mat[k][j];
}
}
//***************************** MTRANS
void TMatrix :: MTrans()
{
if (_NNUM1 != _NNUM2)
throw 1;
int buf;
for (int i = 0; i < _NNUM1; i++)
for (int j = 0; j < i; j++)
{
buf = _mat[i][j];
_mat[i][j] = _mat[j][i];
_mat[j][i] = buf;
}
}
//***************************** MNEGATIVE
void TMatrix :: MNegative()
{
for (int i = 0; i < _NNUM1; i++)
for (int j = 0; j < _NNUM2; j++)
_mat[i][j] = -_mat[i][j];
}
//---------------------------------------------------------------------------
#pragma package(smart_init)
File2.h
//*****************************************************
//************************ GLOBALS ********************
//*****************************************************
const int SGMAX = 11;
const int SGMIN = 1;