Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабы по МПО / МПО / Lab2 / Part3_MyLab / CPP Version / MAIN
.CPP// 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>
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() {
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++) {
clrscr();
seed = 4.0;
get_data(x,y,n);
write_data(x,y,n);
//----------------------------------------- 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;
cout << "Approximated with y=ax+b where a = " << resa << ", b=" << resb;
//------------------------------------------- Calculative part ends
}
}
Соседние файлы в папке CPP Version