#include #include #include using namespace std; int main() { const int ARRAY_SIZE = 64; const int TOP_PERCENTILE = 2; const int MIDDLE_PERCENTILE = 1; const int LOWER_PERCENTILE = 0; int i = 0; // generic counter variable int size; // size of the dataset int max = 0; // max value in dataset double upper_threshold, lower_threshold; // max * 0.9, max * 0.1 int dataset[ARRAY_SIZE]; cout << "Hello again, it feels so good to be executed (I'm a program, after all).\n"; cout << "I will read in a data file and output discretized values, depending " << "on the lowest 10%, middle, and highest 10% thresholds.\n\n"; ifstream data_file("DATA"); if (!data_file) { cerr << "There was a problem opening the data file." << endl; system("PAUSE"); exit(1); } // read size of dataset, which is the first number in the series if ( !(data_file >> size)) { cerr << "The size digit was not able to be read." << endl; system("PAUSE"); exit(1); } // push each element in the datafile into an array location for (i = 0; i < size; ++i) { data_file >> dataset[i]; } // DEBUG: Am I sane? Print the values in the array, to make sure. // for (i = 0; i < size; ++i) { // cout << dataset[i] << endl; // } // what is the maximum value in the dataset? for (int i = 0; i < size; ++i) { if (dataset[i] > max) max = dataset[i]; } // DEBUG: Am I sane? Print the values in the array, to make sure. // cout << "MAX: " << max << endl; // determine the 90% and 10% thresholds, just using max (per the rubric) upper_threshold = max * 0.9; lower_threshold = max * 0.1; // Compare each value in the array to my thresholds. // Replace original value with the discretized value for (i = 0; i < size; ++i) { if (dataset[i] > upper_threshold) { dataset[i] = TOP_PERCENTILE; } else if (dataset[i] >= lower_threshold && dataset[i] <= upper_threshold) { dataset[i] = MIDDLE_PERCENTILE; } else { dataset[i] = LOWER_PERCENTILE; } } cout << "The resulting discretization of the dataset looks like this:\n\n"; // Print the output to the screen for (i = 0; i < size; ++i) { cout << dataset[i]; } cout << endl << endl; system("PAUSE"); return 0; }