029
09.01.2004, 13:28 Uhr
~Gizzzy
Gast
|
Wir ham das jetzt nochmal überarbeitet, vielleicht nicht unbedingt so, wie von euch vorgeschlagen, jetzt sind nur noch drei Linker-Fehler da, und wir wissen nicht wo die herkommen!
MAINDATEI:
C++: |
#include <stdlib.h> #include <iostream.h> #include "PointIo.h" #include "MeanVarCalculation.h"
int main() { float Middle, Varianz; char File[]="values.dat"; int Anzahl;
Anzahl = getNumberOfDataPoints(File); Middle=CalculateMean(Anzahl); cout<< "Der Mittelwert des Vektors beträgt : "<<Middle<< "./n";
Varianz=CalculateVar(Anzahl); cout<< "Die Varianz des Vektors beträgt : "<<Varianz<< "./n";
return 0; }
|
BERECHNUNGSDATEI :
C++: |
#include <stdlib.h> #include "PointIo.h"
int CalculateMean (int xDataOut[]) { char File[] = "values.dat"; int NumberOfValues, ContentOfFile, *xData, SumOfValues = 0, Mean = 0; NumberOfValues = getNumberOfDataPoints(File); xData = new int[NumberOfValues]; ContentOfFile = readDataPoints (File,xData,NumberOfValues);
for(int i = 0; i < NumberOfValues; i++) { SumOfValues += ContentOfFile; } Mean = SumOfValues/NumberOfValues; return Mean; }
int CalculateVar (int xDataOut[]) { char File[]="values.dat"; int NumberOfValues, a = 0, b = 0, SumOfValues, Mean = 0, Var = 0;
NumberOfValues = getNumberOfDataPoints(File); for(int i = 0; i < NumberOfValues; i++) { SumOfValues += xDataOut[i]; }
Mean=SumOfValues/NumberOfValues;
int DeviationOne[50], DeviationTwo[50]; ;//Abweichungen do { for(int j=0;j<NumberOfValues;j++) { if (j>Mean) { DeviationOne[j]=(j-Mean)*(j-Mean); } if (j<Mean) { DeviationTwo[j]=(Mean-j)*(Mean-j); } } } while(NumberOfValues == (a+b));
Var=(DeviationOne[a]+DeviationTwo[ b ])/(NumberOfValues-1);
return Var; }
|
DATEI ZUM AUSLESEN DES VEKTORS :
C++: |
#include <iostream> #include <fstream>
using namespace std;
#include "PointIo.h"
// ------------------------------------------------------------------- // getNumberOfDataPoints returns the number of points in the data file // Input szFileName: ZeroTerminted String which contains the complete Path and FileNAme // return Value is the number of DataPoints in the File // negative Values indicate an error // -1 : File could not be found or openend // -2 : File has not the correct format // ------------------------------------------------------------------- int getNumberOfDataPoints(char *values) { int NrOfPoints; ifstream NeueDatei(values,ios::out|ios::in);
if (NeueDatei.fail()) return -1;
NeueDatei >> NrOfPoints;
if (NrOfPoints < 1) return -2;
NeueDatei.close();
return NrOfPoints; } // ------------------------------------------------------------------- // readDataPoints reads data points from a file // Input : szFileName: ZeroTerminted String which contains the complete Path and FileNAme // : NrOfPoints: integer to indicate the memory allocation for the points (only for safety reasons) // Output : xDataOut and yDataOut pointer to allocated memory for the data points to read. // If the function returns without any error the memory contains the data // return : ErrorCode // -1 : File could not be found or openend // -2 : The saved Number of Data Points are not fitting the requested number // -3 : ReadError // ------------------------------------------------------------------- int readDataPoints (char *values, int *xDataOut, int NrOfPoints) { int ReadNrOfPoints; ifstream NeueDatei(values,ios::out|ios::in);
if (NeueDatei.fail()) return -1;
NeueDatei >> ReadNrOfPoints;
if (NrOfPoints != ReadNrOfPoints) return -2;
int kk; for (kk = 0; kk < NrOfPoints; kk++) { NeueDatei >> xDataOut[kk];
if (!NeueDatei) return -3; }
NeueDatei.close();
return 0; }
|
BERECHNUNGS HEADER :
C++: |
#ifndef MEANVARCALCULATION_IHA_H_ #define MEANVARCALCULATION_IHA_H_
int CalculateMean (int xDataOut);
int CalculateVar (int xDataOut);
#endif
|
AUSLESE HEADER :
C++: |
/****************************************************************************************** FileName : PointIo.h Purpose : Read and Write of Data Points Date Of Creation: 16.12.2003 Modification History : Version Date Modifications By Whom 0.1 16.12.2003 First Build Joerg Bitzer ******************************************************************************************/
#ifndef POINT_IO_IHA_H_ #define POINT_IO_IHA_H_ // -------------------- // Point Definition //--------------------- struct Point { float x; };
// ------------------------------------------------------------------- // getNumberOfDataPoints returns the number of points in the data file // Input szFileName: ZeroTerminted String which contains the complete Path and FileNAme // return Value is the number of DataPoints in the File // negative Values indicate an error // -1 : File could not be found or openend // -2 : File has not the correct format // ------------------------------------------------------------------- int getNumberOfDataPoints(char *values); // ------------------------------------------------------------------- // readDataPoints reads data points from a file // Input : szFileName: ZeroTerminted String which contains the complete Path and FileNAme // : NrOfPoints: integer to indicate the memory allocation for the points (only for safety reasons) // Output : xDataOut and yDataOut pointer to allocated memory for the data points to read. // If the function returns without any error the memory contains the data // return : ErrorCode // -1 : File could not be found or openend // -2 : The saved Number of Data Points are not fitting the requested number // -3 : ReadError // ------------------------------------------------------------------- int readDataPoints (char *values, int *xDataOut, int NrOfPoints);
#endif
|
DATA.DAT MESSWERTE DES VEKTORS :
C++: |
15 2 46 58 96 45 67 34 56 8 98 67 123 43 67 78
|
Bearbeitung von Pablo: |
[ b ] Fehler behoben
|
Dieser Post wurde am 09.01.2004 um 13:30 Uhr von Pablo editiert. |