#include using namespace std; class Scale { double scale_factor; public: Scale(void) : scale_factor(1.0) {} Scale(double actual, double desired) : scale_factor(1.0) { reset(actual,desired); } double operator() (void) const { return scale_factor; } double operator() (double x) const { return scale_factor * x; } void reset(double actual, double desired) { scale_factor = desired/actual; return; } }; int main(void) { Scale s; long d[10] = { 34, 56, 23, 76, 5, 12, 4, 48, 65, 30 }; short i; long max; cout << "Initial scores: "; for (i = 0; i != 9; i++) { cout << d[i] << ' '; } cout << d[i] << endl; max = d[0]; for (i = 1; i != 10; i++) { if (d[i] > max) { max = d[i]; } } cout << "\nMaximum value: " << max << endl; cout << "\nScaling to 100"; s.reset(max, 100); for (i = 0; i != 10; i++) { d[i] = long(s(d[i])+0.5); // round too, why not? cout << ((i+1)%3 == 0 ? "." : ""); // a . every 33% or so } cout << "\n\nScaled scores: "; for (i = 0; i != 9; i++) { cout << d[i] << ' '; } cout << d[i] << endl; return 0; }