№1 КОНТРОЛЬНАЯ РАБОТА по дисциплине «Структуры и алгоритмы обработки данных»

Задание 1

1.  Организовать структуру для хранения целых, вещественных или символьных данных  на языке высокого уровня.

2.  Проверить корректность ввода, хранения и вывода данных.

Структура: Товар-Код, Название, Цена, Производитель, СрокГодности;

saod

Type

data = record

tovar_kod :string[50] ;

nazvanie  : string[50];

cena   : Real;

proizvoditel:string[50];

srok_Godnost:string[50];

end;

var

Form1: TForm1;

d:Array[1..50] of data;

x:Integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click (Sender: TObject);

begin

x:=x+1;

Label7.Caption:=IntToStr (x);

d[x].tovar_kod:=(Edit1.Text);

d[x].nazvanie:=(Edit2.Text);

d[x].cena:=StrToFloat (Edit3.Text);

d[x].proizvoditel:=(Edit4.Text);

d[x].srok_Godnost:=(Edit5.Text);

Edit1.Clear;

Edit2.Clear;

Edit3.Clear;

Edit4.Clear;

Edit5.Clear;

end;

procedure TForm1.Button2Click (Sender: TObject);

var i:integer;

begin

for i := 1 to x do

begin

ListBox1.Items.Add ((d[i].tovar_kod));

ListBox1.Items.Add ((d[i].nazvanie));

ListBox1.Items.Add (FloatToStr (d[i].cena));

ListBox1.Items.Add ((d[i].proizvoditel));

ListBox1.Items.Add ((d[i].srok_Godnost));

ListBox1.Items.Add ('');

ListBox1.Items.SaveToFile ('bd.txt');

end;

end;

procedure TForm1.Edit1KeyPress (Sender: TObject; var Key: Char);

const

AllowedChars: string = '0123456789';

var

i: Integer;

Ok: Boolean;

begin

i  := 0;

Ok := False;

{ If you erase next line, user won't be able to type backspace }

if Key = #8 then Ok := True;

repeat

i := i + 1;

if Key = AllowedChars[i] then Ok := True;

until (Ok) or (i = Length (AllowedChars));

if not Ok then Key := #0;

end;

procedure TForm1.FormCreate (Sender: TObject);

begin

x:=0;

end;

procedure TForm1.Edit2KeyPress (Sender: TObject; var Key: Char);

const

AllowedChars: string = 'abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбю';

var

i: Integer;

Ok: Boolean;

begin

i  := 0;

Ok := False;

{ If you erase next line, user won't be able to type backspace }

if Key = #8 then Ok := True;

repeat

i := i + 1;

if Key = AllowedChars[i] then Ok := True;

until (Ok) or (i = Length (AllowedChars));

if not Ok then Key := #0;

end;

procedure TForm1.Edit3KeyPress (Sender: TObject; var Key: Char);

const

AllowedChars: string = '0123456789';

var

i: Integer;

Ok: Boolean;

begin

i  := 0;

Ok := False;

{ If you erase next line, user won't be able to type backspace }

if Key = #8 then Ok := True;

repeat

i := i + 1;

if Key = AllowedChars[i] then Ok := True;

until (Ok) or (i = Length (AllowedChars));

if not Ok then Key := #0;

end;

procedure TForm1.Edit4KeyPress (Sender: TObject; var Key: Char);

const

AllowedChars: string = 'abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбю0123456789';

var

i: Integer;

Ok: Boolean;

begin

i  := 0;

Ok := False;

{ If you erase next line, user won't be able to type backspace }

if Key = #8 then Ok := True;

repeat

i := i + 1;

if Key = AllowedChars[i] then Ok := True;

until (Ok) or (i = Length (AllowedChars));

if not Ok then Key := #0;

end;

procedure TForm1.Edit5KeyPress (Sender: TObject; var Key: Char);

const

AllowedChars: string = '0123456789';

var

i: Integer;

Ok: Boolean;

begin

i  := 0;

Ok := False;

{ If you erase next line, user won't be able to type backspace }

if Key = #8 then Ok := True;

repeat

i := i + 1;

if Key = AllowedChars[i] then Ok := True;

until (Ok) or (i = Length (AllowedChars));

if not Ok then Key := #0;

end;

end.

About admin

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Подтвердите, что Вы не бот — выберите самый большой кружок: