From 35d49d8c8e887769019b045ebe68bca2139b9040 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Thu, 20 Dec 2018 14:23:29 +0100 Subject: [PATCH] Praxisaufgabe --- lib/linkedlist.pas | 2 + praxistest/lib/utils.pas | 105 +++++++++++++++++++++++++++++++++++ praxistest/persons/Name1.prs | Bin 0 -> 24 bytes praxistest/persons/Name2.prs | Bin 0 -> 24 bytes praxistest/persons/Name3.prs | Bin 0 -> 24 bytes praxistest/persons/Name4.prs | Bin 0 -> 24 bytes praxistest/programm1.pas | 38 +++++++++++++ praxistest/programm2.pas | 41 ++++++++++++++ 8 files changed, 186 insertions(+) create mode 100644 praxistest/lib/utils.pas create mode 100644 praxistest/persons/Name1.prs create mode 100644 praxistest/persons/Name2.prs create mode 100644 praxistest/persons/Name3.prs create mode 100644 praxistest/persons/Name4.prs create mode 100644 praxistest/programm1.pas create mode 100644 praxistest/programm2.pas diff --git a/lib/linkedlist.pas b/lib/linkedlist.pas index b5efe43..283fad6 100644 --- a/lib/linkedlist.pas +++ b/lib/linkedlist.pas @@ -1,5 +1,7 @@ unit linkedlist; +{ TODO: Change from interface and record to class. } + interface type link = ^node; diff --git a/praxistest/lib/utils.pas b/praxistest/lib/utils.pas new file mode 100644 index 0000000..b2d9cbf --- /dev/null +++ b/praxistest/lib/utils.pas @@ -0,0 +1,105 @@ +{ Julius Riegel, 20.12.18 } + +unit utils; + +interface +uses + crt, + Graph; +type + person = record + pname : String[10]; + psurname : String[10]; + number: Integer; + end; + +function int_to_str(i: Integer): String; +procedure write_file(fname: String; data: person); +function read_file(fname: String): person; +procedure drawrectnums(nums: Array of Integer; size: Integer); +procedure init_graphics; +procedure graphictext(x, y, size: Integer; text: String); + +implementation + +function int_to_str(i: Integer): String; +begin + Str(i, int_to_str); +end; + +procedure write_file(fname: String; data: person); +var + outfile: File of person; + +begin + Assign(outfile, fname); + Rewrite(outfile); + Write(outfile, data); + Close(outfile); +end; + +function read_file(fname: String): person; +var + infile: File of person; +begin + Assign(infile, fname); + Reset(infile); + Read(infile, read_file); + Close(infile); +end; + +function format_num(num: Integer) : String; +var + tempstr: String; +begin + tempstr := int_to_str(num); + if (tempstr = '0') then + tempstr := '*'; + format_num := tempstr; +end; + +procedure init_graphics; +var + gdriver, + gmode : Integer; +begin + DetectGraph(gdriver, gmode); + InitGraph(gdriver, gmode, ''); +end; + +procedure graphictext(x, y, size : Integer; text: String); +begin + SetTextStyle(0, 0, round(size/40)); + OutTextXY(x, y, text); +end; + +procedure drawrectnums(nums: Array of Integer; size: Integer); +var + xsize, + ysize, + xstart, + ystart: Integer; + +begin + xsize := GetMaxX; + ysize := GetMaxY; + xstart := Round(xsize/2) - round(size/2); + ystart := Round(ysize/2) - round(size/2); + SetTextStyle(0, 0, round(size/40)); + OutTextXY(xstart+size, ystart, format_num(nums[0])); + OutTextXY(xstart+size, ystart+size, format_num(nums[1])); + OutTextXY(xstart, ystart+size, format_num(nums[2])); + OutTextXY(xstart, ystart, format_num(nums[3])); +end; + +procedure draw_lines(xstart, ystart, size: Integer); +begin + Line(xstart, ystart, xstart+size, ystart); + Line(xstart+size, ystart, xstart+size, ystart+size); + Line(xstart+size, ystart+size, xstart, ystart+size); + Line(xstart, ystart+size, xstart, ystart); +end; + +begin + { Main Body } +end. \ No newline at end of file diff --git a/praxistest/persons/Name1.prs b/praxistest/persons/Name1.prs new file mode 100644 index 0000000000000000000000000000000000000000..4586cc9ff1095b02c22948dd3d7562bd63c3ab1d GIT binary patch literal 24 dcmZQ`%u7$rNn~JXFl6&hEy_;KaR9Od7ywg(26g}d literal 0 HcmV?d00001 diff --git a/praxistest/persons/Name2.prs b/praxistest/persons/Name2.prs new file mode 100644 index 0000000000000000000000000000000000000000..817894337d150b9e660ef0bb8252bad34179cd60 GIT binary patch literal 24 dcmZSeNX^WvN@QSYFl6^gElNr)Dgm;+7ywoS2D1PF literal 0 HcmV?d00001 diff --git a/praxistest/persons/Name3.prs b/praxistest/persons/Name3.prs new file mode 100644 index 0000000000000000000000000000000000000000..999aca3a1714b7fd8b96544d8512f10b5df8e38d GIT binary patch literal 24 dcmZScD$U6(EoNY7Fk}nLOifSCDFL!&830%(2BQD~ literal 0 HcmV?d00001 diff --git a/praxistest/persons/Name4.prs b/praxistest/persons/Name4.prs new file mode 100644 index 0000000000000000000000000000000000000000..7ac2526b72f6c701f35f7b8096171b4a02f6e32b GIT binary patch literal 24 dcmZPz$;i)5EM{P6Fl6yf%*#v7DFL!&7ywr529p2) literal 0 HcmV?d00001 diff --git a/praxistest/programm1.pas b/praxistest/programm1.pas new file mode 100644 index 0000000..58fee8b --- /dev/null +++ b/praxistest/programm1.pas @@ -0,0 +1,38 @@ +{ Julius Riegel, 20.12.18 } + +program programm1; + +uses + utils in './lib/utils.pas'; + +const + fname = './persons/Name'; + +procedure gen_entry(fnum: Integer); +var + temp_person: person; + curr_fname : String; +begin + curr_fname := fname + int_to_str(fnum) + '.prs'; + Write(' Name: '); + ReadLn(temp_person.pname); + Write(' Surname: '); + ReadLn(temp_person.psurname); + temp_person.number := Random(101); + WriteLn(' Number is: ', temp_person.number); + WriteLn; + write_file(curr_fname, temp_person); +end; + +var + i : Integer; + +begin + Randomize; + WriteLn; + for i := 1 to 4 do + begin + gen_entry(i); + end; + WriteLn('[+] All names saved.'); +end. \ No newline at end of file diff --git a/praxistest/programm2.pas b/praxistest/programm2.pas new file mode 100644 index 0000000..1a565bf --- /dev/null +++ b/praxistest/programm2.pas @@ -0,0 +1,41 @@ +{ Julius Riegel, 20.12.18 } + +program programm2; + +uses + utils in './lib/utils.pas'; + +const + fname = './persons/Name'; + +function reading_file_int(fnum: Integer): Integer; +var + curr_fname: String; + temp_entry: person; + +begin + curr_fname := fname + int_to_str(fnum) + '.prs'; + temp_entry := read_file(curr_fname); + graphictext(10, 20*fnum, 80, 'file' + int_to_str(fnum) + ': ' + curr_fname); + reading_file_int := temp_entry.number; +end; + +var + i: Integer; + numsum, num: Integer; + nums: Array [0..3] of Integer; + +begin + WriteLn; + numsum := 0; + init_graphics(); + for i := 1 to 4 do + begin + num := reading_file_int(i); + nums[i-1] := num; + numsum := numsum + num; + end; + graphictext(10, 100, 80, ('sum: '+ int_to_str(numsum))); + drawrectnums(nums, 80); + ReadLn; +end. \ No newline at end of file