program laba12_8a type arr array 10 of real ob object vec arr byte id

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
program laba12_8a;
type
arr = array[1..10] of real;
ob = object
vec:^arr;
n:byte;
id:string;
constructor init;
procedure inp;
procedure out;
function scal(a:ob):real;
destructor done;
end;
constructor ob.init;
begin
new(vec);
end;
destructor ob.done;
begin
if vec<>nil then dispose(vec);
end;
procedure ob.inp;
var i:byte;
begin
write('Enter id:'); readln(id);
write('Enter n: '); readln(n);
for i:=1 to n do begin
write(id,'[',i,']: ');readln(vec^[i]);
end;
end;
procedure ob.out;
var i:byte;
begin
for i:=1 to n do
writeln(id,'[',i,']=',vec^[i]);
end;
function ob.scal;
var s:real;
i:byte;
begin
s:=0;
if(n <> a.n) then writeln('error')
else begin
for i:=1 to n do
s:=s+ vec^[i]*a.vec^[i];
scal:=s;
end;
end;
var a,b:ob;
begin
a.init;
b.init;
a.inp;
b.inp;
writeln('Scal:',a.scal(b):5:3);
readln;
end.