Скачиваний:
18
Добавлен:
01.05.2014
Размер:
2.6 Кб
Скачать
{ Here we are returning to Borland Pascal v.7.0!! }
{ The concept is to calculate the Holstead metrics for this bullshit.. }

{ The following code really contains some bullshit... Yet, I am not }
{ expected to optimize it anyhow in the first lab... }

program cfit1A;
uses Crt;

const max = 20;
type index = 1..max;
ary = array[index] of real;
var x,y : ary;
n : integer;
first,done : boolean;
seed: real;
{-------------------}
sumx,sumy: real;
sumxy, sumx2: real;
k: integer;
resa,resb: real;


function random(dummy: integer): real;
const pi = 3.14159;
var x : real; i : integer;
begin
x:=seed+pi;
x:=exp(5.0*ln(x));
seed:=x-trunc(x);
random:=seed
end;


procedure get_data(var x,y: ary; var n: integer);
const a = 5.0; b = 2.0;
var i,j : integer;
fudge : real;
BEGIN
write('Fudge? (<0 to terminate): '); readln(fudge);
{ Fudge is a synonym to bullshit. Negative fudge breaks cycle! }
if fudge < 0.0 then
done:=true
else begin
{ Reading correct number of points }
repeat
write('How many points? ');
readln(n)
until (n>2) and (n<=max);
{ Mystical line for me now...}
if first then first:=false else ClrScr;
{ This, I expect, forms linear sequence with random deviation }
for i:=1 to n do begin
j:=n+1-i;
x[i]:=j;
y[i]:=(a*j + b) * (1.0 + (2.0 * random(0) - 1.0) * fudge);
end
end
END;


procedure write_data;
{ print out the answers }
var i : integer;
BEGIN
writeln;
writeln(' I X Y');
for i:=1 to n do
writeln(i:3,x[i]:8:1,y[i]:9:2);
writeln
END;


BEGIN
ClrScr;
seed:=4.0;
first:=true;
done:=false;
repeat
get_data(x,y,n);
if not done then
begin
write_data;
{----------------------------------------- Calculative part starts }
{ Accumulating statistics }
sumx := 0; sumy := 0; sumxy := 0; sumx2 := 0;
for k:=1 to n do begin
sumx := sumx + x[k];
sumy := sumy + y[k];
sumxy := sumxy + x[k] * y[k];
sumx2 := sumx2 + x[k] * x[k];
end;
{ Recieving verdict }
resa := (sumxy - sumx*sumy/n) / (sumx2 - sumx*sumx/n);
resb := (sumy - resa * sumx) / n;
writeln('Approximated with y=ax+b where a = ',resa,', b=',resb);
{------------------------------------------- Calculative part ends }
end
until done
END.
Соседние файлы в папке Sido Lab1