Скачиваний:
19
Добавлен:
01.05.2014
Размер:
1.98 Кб
Скачать
// Here we are returning to Borland C++ v.3.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...

#include <Math.h>
#include <IOStream.h>
#include <Conio.h>

#include "Sampler.h"

const pi = 3.14159;
const max = 20;
const cyc_count = 20;

float seed;

float random(float dummy) {
  float x;  int i;
  x = seed + pi;
  x = exp(5.0 * log(x));
  seed = x - int(x);
  return seed;
}

void get_data(float *x, float *y, int &n) {
   const a = 5.0;
   const b = 2.0;
   int i,j;
   float fudge = 0.5;
   n = 10;
   for (i=1; i<=n; i++) {
	j = n + 1 - i;
	x[i] = j;
	y[i] = (a*j + b) * (1.0 + (2.0 * random(0) - 1.0) * fudge);
   }
}


void write_data(float *x, float *y, int n) {
  int i;
  for (i = 1; i <= n; i++)
     cout << "X[" << i << "]=" << x[i] << "\t\tY[" << i << "]=" << y[i] << "\n";
}


void main() {
  SAMPLE; //49
   float x[max];
   float y[max];
   int n;
   float sumx,sumy;
   float sumxy, sumx2;
   int k;
   float resa,resb;
   int cycle;

  for(cycle = 0; cycle < cyc_count; cycle++) {
 //   SAMPLE;  //59
    clrscr();
 //   SAMPLE;   //61
    seed = 4.0;
  //  SAMPLE;
    get_data(x,y,n);
  //  SAMPLE;  //65
    write_data(x,y,n);
 //   SAMPLE;  //67
	//----------------------------------------- Calculative part starts
	// Accumulating statistics
	sumx = 0; sumy = 0; sumxy = 0; sumx2 = 0;
	for (k=1; k<=n; k++) {
	  sumx  += x[k];
	  sumy  += y[k];
	  sumxy += x[k] * y[k];
	  sumx2 += x[k] * x[k];
	}
	// Recieving verdict
	resa = (sumxy  -  sumx*sumy/n) / (sumx2  -  sumx*sumx/n);
	resb = (sumy  -  resa * sumx) / n;
     //	SAMPLE;//80
	cout << "Approximated with y=ax+b where a = " << resa << ", b=" << resb;
	//------------------------------------------- Calculative part ends
      //	SAMPLE; //83
    }
    SAMPLE;  //86
}
Соседние файлы в папке CPP Version
  • #
    01.05.20141.98 Кб18MAIN.BAK
  • #
    01.05.20141.98 Кб19MAIN.CPP
  • #
    01.05.201430.71 Кб18MAIN.OBJ
  • #
    01.05.2014908 б18MAIN.SMP
  • #
    01.05.2014121 б19MAIN.SMV
  • #
    01.05.20141.88 Кб18MAIN_OPT.BAK
  • #
    01.05.20141.88 Кб19MAIN_OPT.CPP