Скачиваний:
19
Добавлен:
01.05.2014
Размер:
2.32 Кб
Скачать
{ 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, Sampler;

const max = 20;
cyc_count = 20;
PName: string[10] = 'Main.pas';

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

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
fudge := 0.5;
n := 10;
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;


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
SAMPLE(PName,1); {65}
for cycle := 1 to cyc_count do begin
{ SAMPLE(PName,1); }
ClrScr;
{ SAMPLE(PName,2); }
seed:=4.0;
{ SAMPLE(PNa,3); }
get_data(x,y,n);
{ SAMPLE(PName,4); }
write_data;
{ SAMPLE(PName,5); }
{----------------------------------------- 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;
{ SAMPLE(PName,6); }
writeln('Approximated with y=ax+b where a = ',resa,', b=',resb);
{------------------------------------------- Calculative part ends }
{ SAMPLE(PName,7); }
end;
SAMPLE(PName,2); {91}
END.
Соседние файлы в папке PAS Version
  • #
    01.05.20142.32 Кб18MAIN.BAK
  • #
    01.05.2014478 б18MAIN.MAP
  • #
    01.05.20142.32 Кб19MAIN.PAS
  • #
    01.05.2014908 б18MAIN.SMP
  • #
    01.05.2014121 б18MAIN.SMV
  • #
    01.05.20142.21 Кб18MAIN_OPT.BAK
  • #
    01.05.2014478 б18MAIN_OPT.MAP
  • #
    01.05.20142.21 Кб19MAIN_OPT.PAS