1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#include <iostream>
#include <cmath>
using namespace std;
const int ROWS = 3, COLUMNS = 3;
// Function: dataManipulation
// Purpose: To get data from user and
// get the average and maximum
// Variables: A lot
int dataManipulation()
{
int sum = 0, row_sum = 0, column_sum = 0, row_average, column_average,
average, average_firstrow, average_secondrow, average_thirdrow,
average_firstcolumn, average_secondcolumn, average_thirdcolumn,
highest_row = 0, highest_column = 0, highest_total = 0,
max_firstrow, max_secondrow, max_thirdrow,
data[ROWS][COLUMNS];
for (int x = 0; x < ROWS; x++)
{
for (int y = 0; y < COLUMNS; y++)
{
if (y == 0) // Reset the variables if we are at the start of the loop and display set
{
row_sum = 0;
column_sum = 0;
row_average = 0;
column_average = 0;
cout << "SENSOR SET " << (x + 1) << endl;
cout << "------------\n";
}
cout << "Sensor " << (y + 1) << ": ";
cin >> data[x][y];
cin.ignore();
sum += data[x][y]; // Running total that does not reset
row_sum += data[x][y]; // Running total of the rows
column_sum += data[y][x]; // Running total of the columns
if (y == 2) // Only do this the last time the loop goes through
{
row_average = row_sum / COLUMNS;
column_average = column_sum / COLUMNS;
}
if (data[x][y] > highest_row) // Find the highest number in the row
{
highest_row = data[x][y];
}
}
if (x == 0)
{
average_firstrow = row_average;
average_firstcolumn = column_average;
max_firstrow = highest_row;
}
else if (x == 1)
{
average_secondrow = row_average;
average_secondcolumn = column_average;
max_secondrow = highest_row;
}
else if (x == 2)
{
average = sum / pow(COLUMNS, 2);
average_thirdrow = row_average;
average_thirdcolumn = column_average;
max_thirdrow = highest_row;
}
cout << endl;
}
cout << "----------------------------------------------\n\n";
cout << "Average for sensor set 1: " << average_firstrow << endl;
cout << "Average for sensor set 2: " << average_secondrow << endl;
cout << "Average for sensor set 3: " << average_thirdrow << endl << endl;
cout << "Average for first sensor in every set: " << average_firstcolumn << endl;
cout << "Average for second sensor in every set: " << average_secondcolumn << endl;
cout << "Average for third sensor in every set: " << average_thirdcolumn << endl << endl;
cout << "The maximum number for the first set of sensors is " << max_firstrow << endl;
cout << "The maximum number for the second set of sensors is " << max_secondrow << endl;
cout << "The maximum number for the third set of sensors is " << max_thirdrow << endl << endl;
cout << "The average sensor reading is " << average << endl;
cout << "The maximum sensor reading is " << highest_row << endl;
}
int main()
{
cout << "Geological sensor data\n";
cout << "----------------------\n\n";
cout << "Enter the following data\n\n";
dataManipulation();
cin.get();
return 0;
}
|