Netwars

pascal, recordy

[#1]
14.12.2006 00:39

witam ;-) kolega poprosil mnie zebym mu napisał jakis tam program, no to cos naskrobałem:

program bro;

type
point = record
x,y: real; {declaration of point type, consisting of two coorginates}
end;

triangle = record {declaration of triangle type, consisting of threepoints}
a,b,c : point;
end;

side = record {declaration of triangle sides lenght type}
A, B, C: real;
end;

var
p1,p2,p3 : point;
t : triangle;
x1,x2,x3,y1,y2,y3 : real;

procedure subprogram1(var x,y:real; p: point); {procedure initialize point (name of points is one of parameters) using 2 coordinates passed as parameters}
begin
p.x:=x;
p.y:=y;
end;

procedure subprogram2(var a,b,c: point); {procedure initialize triangle, using 3 points passed as parameters}
begin
t.a:=p1;
t.b:=p2;
t.c:=p3;
end;

function subprogram3(var t: triangle):boolean; {function returns true if 3 points in triangle type really defines a traingle}
var D,E,F: real;
begin
D := sqrt(sqr(t.a.x - t.b.x) + sqr(t.a.y - t.b.y));
E := sqrt(sqr(t.b.x - t.c.x) + sqr(t.b.y - t.c.y));
F := sqrt(sqr(t.c.x - t.a.x) + sqr(t.c.y - t.a.y));
subprogram3 := (D+E > F) AND (E+F > D) AND (D+F > E);
end;

function subprogram4(var t: triangle):side; {function returns the length of sides of a triangle (passed as parameter) in a defined type}
begin
subprogram4.A := sqrt(sqr(t.a.x - t.b.x) + sqr(t.a.y - t.b.y));
subprogram4.B := sqrt(sqr(t.b.x - t.c.x) + sqr(t.b.y - t.c.y));
subprogram4.C := sqrt(sqr(t.c.x - t.a.x) + sqr(t.c.y - t.a.y));
end;

begin
writeln('Point1 x:'); read(x1);
writeln('Point1 y:'); read(y1);
writeln('Point2 x:'); read(x2);
writeln('Point2 y:'); read(y2);
writeln('Point3 x:'); read(x3);
writeln('Point3 y:'); read(y3);
subprogram1(x1,y1,p1);
subprogram1(x2,y2,p2);
subprogram1(x3,y3,p3);
subprogram2(p1,p2,p3);
if subprogram3(t) then writeln('This is correct triangle') else writeln('Sorry, this is not a triangle');
writeln;
writeln('Lenght of sides in this triangle are:');
writeln(subprogram4(t).A);
writeln(subprogram4(t).B);
writeln(subprogram4(t).C);
end.

mi sie to kompiluje bez problemu, natomiast jemu wyrzuca:

"In function 'Subprogram4'
request for field 'A' in something not a record, schema or object" :/ dla B i C to samo...

ocb ? help :P

[#2]
14.12.2006 00:46

przerobilem to na:

function subprogram4(var t: triangle):side; {function returns the length of sides of a triangle (passed as parameter) in a defined type}
var pom: side;
begin
pom.A := sqrt(sqr(t.a.x - t.b.x) + sqr(t.a.y - t.b.y));
pom.B := sqrt(sqr(t.b.x - t.c.x) + sqr(t.b.y - t.c.y));
pom.C := sqrt(sqr(t.c.x - t.a.x) + sqr(t.c.y - t.a.y));
subprogram4 := pom;
end;

i mu działa... dlaczego ?!? :P

[#4]
14.12.2006 08:57

NIgdy nie mialem pojecia jak w ogole mozna cos takiego napisac :PPP

[#5]
14.12.2006 09:17

"witam ;-) kolega poprosil mnie zebym mu napisał jakis tam program, no to cos naskrobałem:"
W takiej sytuacji proponowal bym napisac jakis prosty program bez rekordow procedur i funkcji,a nie szpanowac przed kolega i scena netwars.

[#6]
14.12.2006 09:20

A odpowiedz na pytanie dlaczego ?
Moze ma jakis zepsuty kompilator ? :-)

[#7]
14.12.2006 10:54

napisz jaki masz kompilator a jaki ma kolega

[#8]
14.12.2006 21:43

ja mam freepascala, a kolega nie wie co ma

#5 Rion zle mnie rozumiales... kazal mi napisac dokladnie taki program jak mu napisalem :) pozatym co to za szpan napisac takie cos jak napisalem ? lol ;< przeciez to 'bezmyslne przepisywanie termów' :)

[#9]
14.12.2006 21:47

hmm czyli to raczej tylko kwestia kompilatora? bo nie pisalem wczesniej funkcji zwracajacej rekord w pascalu i myslalem ze moze nie mozna od razu zwracac pól w rekordzie, tylko moze potrzeba caly wypelniony rekord :)

Zaloguj się, żeby odpowiedzieć.