Конструирование программ и языки программирования

Автор работы: Пользователь скрыл имя, 26 Февраля 2012 в 21:45, курсовая работа

Краткое описание

С++ был создан в начале 80-х Бьерном Страуструпом. Страуструп имел перед собой две цели: (1) оставить С++ совместимым с обычным С и (2) расширить С конструкциями объектно-ориентированного программирования (ООП), основанными на понятии класса в Simula 67.
Конечная цель создания С++ - предоставить профессиональному программисту язык, который можно использовать при создании объектно-ориентированного программного обеспечения, не жертвуя эффективностью или переносимостью С.

Содержание работы

Введение 3
1. Техническое задание 6
2. Рабочий проект 7
2.1.Общие сведения (среда функционирования (ОС), способ загрузки,
способ инсталляции, требования к ПО, требования к ТО) 7
2.2. Алгоритм программы 8
2.2.1.Классы 8
2.2.2.Диаграмма классов 13
2.2.3.Модули 14
2.2.4.Схема алгоритма 15
2.2.5.Диаграмма последовательности 16
2.2.6.Обработка исключений 17
2.3.Руководство пользователя 18
Заключение……………………………..……………………………………….........23
Список используемой литературы…………………..……..…………....…..…….. 24

Содержимое работы - 1 файл

Пояснительная записка.doc

— 628.00 Кб (Скачать файл)

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

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++)

Информация о работе Конструирование программ и языки программирования