94.9k views
2 votes
When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This adjustment can be done by normalizing to values between 0 and 1, or throwing away outliers.

For this program, adjust the values by dividing all values by the largest value. The input begins with an integer indicating the number of floating-point values that follow.

Output each floating-point value with two digits after the decimal point, which can be achieved by executing

cout << fixed << setprecision(2); once before all other cout statements.

Ex: If the input is:

5 30.0 50.0 10.0 100.0 65.0
the output is:

0.30 0.50 0.10 1.00 0.65

User Momouu
by
8.4k points

2 Answers

2 votes

Final answer:

To adjust data sets by normalizing them to values between 0 and 1, divide each value by the largest value in the data set. Use the cout << fixed << setprecision(2) statement to display the adjusted values with two digits after the decimal point.

Step-by-step explanation:

When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. One way to adjust the data is by normalizing it to values between 0 and 1. In this case, we can divide all the values by the largest value in the data set.

Here's how you can do it:

  1. Read the input, which starts with an integer indicating the number of values that follow.
  2. Divide each value in the data set by the largest value.
  3. Use the cout << fixed << setprecision(2) statement once before printing the adjusted values to ensure they are displayed with two digits after the decimal point.

For example, if the input is 5 30.0 50.0 10.0 100.0 65.0, the output would be 0.30 0.50 0.10 1.00 0.65.

User Chgsilva
by
8.7k points
5 votes

Below is a simple C++ program that takes the number of floating-point values as input.

cpp

#include <iostream>

#include <iomanip>

#include <vector>

int main() {

// Set precision for floating-point output

std::cout << std::fixed << std::setprecision(2);

// Read the number of floating-point values

int numValues;

std::cin >> numValues;

// Read the floating-point values into a vector

std::vector<double> values(numValues);

for (int i = 0; i < numValues; ++i) {

std::cin >> values[i];

}

// Find the largest value

double max = values[0];

for (int i = 1; i < numValues; ++i) {

if (values[i] > max) {

max = values[i];

}

}

// Adjust and output the values

for (int i = 0; i < numValues; ++i) {

double adjustedValue = values[i] / max;

std::cout << adjustedValue << " ";

}

return 0;

}

User Lachezar Todorov
by
8.2k points