how to create a classification table using c++ -
i wondering how possible create classification table using arrays. started code below , stuck on how replace numbers in set range , make equal else. went further detail of mean; commenting in code. hope able give me direction on this.
int main(int argc, _tchar* argv[]) { vector<vector<double>> arrays = { { 0.2746458, 0.484255, 0.15154546, 0.0325468}, { 0.141573001, 0.129732453, 0.3524564, 0.000458475} }; size_t count = 0; double sum = 0; float element = 0; (const vector<double> &array : arrays) { (float element : array) { if (0.0 <= element && element <= 0.24) { /* part of code should replace number within given range of 0.0 0.24 , make number equal 1 want above array end looking this: { 0.2746458, 0.484255, 1, 1}, { 1, 1, 0.3524564, 1} */ } if (0.24 <= element && element <= 0.5) { /* part of code meant similar above 1 finds number within range of 0.24 0.5 , make each of numbers equal 2 array ends looking { 2, 2, 1, 1}, { 1, 1, 2, 1} */ } } } cout << "classification table " << endl; //print arrays after has gone through above code return 0;
}
you can use proxy class. example:
class dynamicvalue { private: int c; public: dynamicvalue() : c(0) {} dynamicvalue(double x) : c() { this->c = this->classification(x); } dynamicvalue(const dynamicvalue& dv) c(dv.c) {} ~dynamicvalue() {} dynamicvalue& operator = (double x) { this->c = this->classification(x); return *this; } dynamicvalue& operator = (const dynamicvalue& dv) { this->c = dv.c; return *this; } operator int () { return this->c; } int classification(double x) { if(x < 0.0) return 0; else if(x < 0.24) return 1; else if(x < 0.5) return 2; else return 3; } };
then can use this:
std::vector<dynamicvalue> values(5); values[0] = 0.3; values[1] = -0.01; values[2] = 0.1; values[3] = 0.63; values[4] = 0.21; for(std::size_t = 0; < values.size(); ++i) std::cout << (int)values[i] << std::endl; // print 20131
Comments
Post a Comment