Реферат: Программирование на языке Object Pascal в среде Delphi

Министерство общего и профессионального образования

Череповецкий государственный университет

 

 

 

 

Институт математики, физики и информатики

Кафедра программного обеспечения ЭВМ. 

              Дисциплина  Программирование на ЯВУ

 

 

 

 

 

 

КУРСОВАЯ РАБОТА

 

 

Тема:Программирование на языке ObjectPascalв среде  Delphi

 

 

 

 

 

 

 

Выполнил студент:                                                  

     Группы:                                                      

                        Принял преподаватель:    

                                              Отметка о зачете:

 

 

 

 

 

 

 

 

 

 

 

 г Череповец. 2002/2003

Министерство общего и профессионального образования

Череповецкий государственный университет 

Институт математики, физики и информатики 

 

 

 

Задание:

 

Дан многочлен P(x)= anXn  + … + a1X+ a0X0  с целыми коэффициентами можно представить в виде списка. Создать программу, которая проверяет на равенство многочлены Pи Q, а так же строит сумму этих многочленов. 

 

Название курсовой работы:

 

 Лабораторная работа N8

 

План:

 

Блок схема                                                                                                                      3

Текст программы                                                                                                         5

Результаты работы                                                                                                   10

Описание программы                                                                                                11

Процедуры и функции из других модулей                                                              11

Литература                                                                                                                 11 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Блок-схема

 



/>

 

 

 

 

 

 

 

 

 

/> 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

/> 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Текст программы:

 

unit Unit1;

 

interface

 

uses

  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

  ComCtrls, Grids, StdCtrls;

 

type

  M = array[0..65535] of word;

  TForm1 = class(TForm)

    StringGrid1: TStringGrid;

    Edit1: TEdit;

    Edit2: TEdit;

    Button1: TButton;

    StringGrid2: TStringGrid;

    Label1: TLabel;

    Label2: TLabel;

    ComboBox1: TComboBox;

    Label3: TLabel;

    Label4: TLabel;

    Label5: TLabel;

    Button2: TButton;

    Button3: TButton;

    Label6: TLabel;

    Label7: TLabel;

    Label8: TLabel;

    Button4: TButton;

    Button5: TButton;

    RichEdit1: TRichEdit;

    RichEdit2: TRichEdit;

    RichEdit3: TRichEdit;

    procedure FormCreate(Sender: TObject);

    procedure Button1Click(Sender: TObject);

    procedure Button5Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Button4Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

  KofP,KofQ,KofS :M;

  ListItem: TListItem;

  L :TList;

  s,ss: string;

implementation

 

{$R *.DFM}

 

procedure TForm1.FormCreate(Sender: TObject);

var i :word;

begin

  ComboBox1.ItemIndex := 0;

  StringGrid1.Cells[0,0] :='Степень';

  StringGrid1.Cells[1,0] :='Коофициент';

  StringGrid2.Cells[0,0] :='Степень';

  StringGrid2.Cells[1,0] :='Коофициент';

  s  := '';

  ss := '';

  for i := 0 to 65535 do

  begin

    KofP[i] := 0;

    KofQ[i] := 0;

    KofS[i] := 0;

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

var e1,e2:integer;

C1,test,TCount,ENCount: word;

s1,s2: string;

begin

  s1 := Edit2.Text;

  s2 := Edit1.Text;

  If ComboBox1.ItemIndex = 0 then

  begin

    Val(s2, C1, e1);

    Val(s1, Test, e2);

    If (e1=0) and (e2=0)and(C1=StrToInt(s2))and(Test=StrToInt(s1)) then

    begin

      For TCount := 0 to StringGrid1.RowCount — 1 do

      begin

        If StringGrid1.Cells[0,TCount]=s2 then

        begin

          ENCount := TCount;

          StringGrid1.Cells[1,TCount] :=  S1;

          KofP[StrToInt(s2)] := StrToInt(s1);

        end;

      end;

      If ENCount = 0 then

      begin

        KofP[StrToInt(s2)] := StrToInt(s1);

        StringGrid1.Cols[0].Append(Edit1.Text);

        StringGrid1.Cols[1].Append(Edit2.Text);

        StringGrid1.RowCount := StringGrid1.RowCount  + 1;

      end;

    end

    else

    begin

      MessageDlg('Ошибка ввода данных! ',mtWarning,[mbOk],0);

      exit;

    end

  end

  else

  begin

    Val(s2, C1, e1);

    Val(s1, Test, e2);

    If (e1=0) and (e2=0)and(C1=StrToInt(s2))and(Test=StrToInt(s1)) then

    begin

      For TCount := 0 to StringGrid2.RowCount — 1 do

      begin

        If StringGrid2.Cells[0,TCount]=S2 then

        begin

          ENCount := TCount;

          StringGrid2.Cells[1,TCount] :=  S1;

          KofQ[StrToInt(s2)] := StrToInt(s1);

        end;

      end;

      If ENCount = 0 then

      begin

        KofQ[StrToInt(s2)] := StrToInt(s1);

        StringGrid2.Cols[0].Append(Edit1.Text);

        StringGrid2.Cols[1].Append(Edit2.Text);

        StringGrid2.RowCount := StringGrid2.RowCount  + 1;

      end;

    end

    else

    begin

      MessageDlg('Ошибка ввода данных! ',mtWarning,[mbOk],0);

      exit;

    end

  end

 

end;

 

procedure TForm1.Button5Click(Sender: TObject);

var I: word;

begin

  For i := 1 TO StringGrid1.RowCount -2 do

  StringGrid1.Rows[i].Clear;

  StringGrid1.RowCount := 2;

  For i := 1 TO StringGrid2.RowCount -2 do

  StringGrid2.Rows[i].Clear;

  StringGrid2.RowCount := 2;

  RichEdit1.Lines.Clear;

  RichEdit2.Lines.Clear;

  RichEdit3.Lines.Clear;

  for i := 0 to 65535 do

  begin

    KofP[i] := 0;

    KofQ[i] := 0;

    KofS[i] := 0;

  end;

end;

 

procedure TForm1.Button2Click(Sender: TObject);

Var i: word;

begin

  s := '';

  ss:= '';

  RichEdit1.Lines.Clear;

  RichEdit2.Lines.Clear;

  for i := 65535 downto 0 do

  begin

  If KofP[i] <> 0 then

  If Length(s) < 220 then

   S := S + IntToStr(KofP[i])+'X^'+IntToStr(i)+'+'

   else

   begin

     RichEdit1.Lines.Add(s);

     S := IntToStr(KofP[i])+'X^'+IntToStr(i)+'+';

   end;

  end;

  for i := 65535 downto 0 do

  begin

  If KofQ[i] <> 0 then

  If Length(ss) < 220 then

   SS := SS + IntToStr(KofQ[i])+'X^'+IntToStr(i)+'+'

   else

   begin

     RichEdit2.Lines.Add(ss);

     SS := IntToStr(KofQ[i])+'X^'+IntToStr(i)+'+';

   end;

  end;

   RichEdit1.Lines.Add(Copy(s,1,length(s)-1));

   RichEdit2.Lines.Add(Copy(ss,1,length(ss)-1));

   Button4.Enabled := True;

   Button3.Enabled := True;

end;

 

procedure TForm1.Button4Click(Sender: TObject);

var t: Byte;

i :word;

begin

  t := 0;

  for i := 65535 downto 0 do

  begin

    If KofP[i]<>KofQ[i] then t := 1

  end;

  If t= 0 then ShowMessage('Списки равны')

  elseShowMessage('Списки не равны');

end;

 

procedure TForm1.Button3Click(Sender: TObject);

Var i: Word;

begin

  s := '';

  RichEdit3.Lines.Clear;

  for i := 0 to 65535 do

  KofS[i]:= KofP[i]+KofQ[i];

  for i := 65535 downto 0 do

  begin

  If KofS[i] <> 0 then

  If Length(s) < 220 then

   S := S + IntToStr(KofS[i])+'X^'+IntToStr(i)+'+'

   else

   begin

     RichEdit1.Lines.Add(s);

     S := IntToStr(KofS[i])+'X^'+IntToStr(i)+'+';

   end;

  end;

  RichEdit3.Lines.Add(Copy(s,1,length(s)-1));

end;

 

end.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 






/>
/>


Результаты работы программы:






/>
/>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Описание программы:

 

Программа служит для построения на основе введенных коэффициентов 2-х списков и может выполнять так же :

·        Сравнение  этих спиков.

·        Построение многочлена суммы этих списков.

 

 

 

 

 

Описание процедур:

 

 

    procedure FormCreate(Sender: TObject)

Устанавливает начальные параметры при загрузке программы.

 

    procedure Button5Click(Sender: TObject)

Производит “очистку” программы.

 

    procedure Button2Click(Sender: TObject)

Создание списков.

 

    procedure Button4Click(Sender: TObject)

Проверка списков на равенство.

 

    procedure Button3Click(Sender: TObject) 

Составление суммы.

 

 

 

 

 

 

 

 

 

 

 

Литература : 

 

В.В. Фаронов. Delphi6. Учебный курс.

 

еще рефераты
Еще работы по программированию, базе данных