DataMining-Experiment1
[cpp]
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
class KanhaSum
{
public:
double sum;
KanhaSum()
{
sum = 0;
}
void reset()
{
sum = 0;
}
void add(double value)
{
sum += value;
}
double get_sum()
{
return sum;
}
};
class Median
{
public:
int n;
double median;
double sum;
public:
Median()
{
n = 0;
median = 0.0;
sum = 0.0;
}
void reset()
{
sum = 0;
}
void add(double value)
{
n++;
sum += value;
}
double get_median()
{
return sum/n;
}
};
class Vector
{
public:
int N;
double *DMVector;
public:
Vector(int n)
{
N = n;
DMVector = (double *)malloc(sizeof(double)*N);
}
~Vector()
{
free(DMVector);
}
void fill(double value)
{
for(int i=0; i<N; i++)
{
DMVector[i] = value;
}
}
double get(int i)
{
return DMVector[i];
}
void set(int i, double value)
{
DMVector[i] = value;
}
void add(const Vector &v)
{
for(int i=0; i<N; i++)
{
DMVector[i] += v.DMVector[i];
}
}
void sub(const Vector& v)
{
for(int i=0; i<N; i++)
{
DMVector[i] -= v.DMVector[i];
}
}
void mul(double k)
{
for(int i=0; i<N; i++)
{
DMVector[i] = DMVector[i]*k;
}
}
void inc_mul(const Vector &v, int k)
{
for(int i=0; i<N; i++)
{
DMVector[i] += k*v.DMVector[i];
}
}
double dot(const Vector &v)
{
double sum = 0.0;
for(int i=0; i<N; i++)
{
sum += DMVector[i]*v.DMVector[i];
}
return sum;
}
double square_norm()
{
double square = 0.0;
for(int i=0; i<N; i++)
{
square += DMVector[i]*DMVector[i];
}
return square;
}
double norm()
{
double ret = 0.0;
ret = sqrt(square_norm());
return ret;
}
double sum()
{
double sum = 0.0;
for(int i=0; i<N; i++)
{
sum += DMVector[i];
}
return sum;
}
double min_vector()
{
double minv = 0.0;
for(int i=0; i<N; i++)
{
if(DMVector[i] < minv)
&
补充:软件开发 , C++ ,