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
|
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
// Constants
const int REQUIRED_COLUMNS = 5;
// Function Prototypes
void extractDesignatedColumns(int nbrOfRows, float &totalColumnTwo,
float &totalColumnFour);
void printStatistics(int nbrOfRows, float totalColumnTwo, float totalColumnFour);
// ############################################################
int main(void)
{
int rowCount, columnCount;
float totalColumnTwo, totalColumnFour;
cin >> rowCount >> columnCount ;
if (rowCount <= 0)
cout << "Incorrect entry" << endl;
else if (columnCount != REQUIRED_COLUMNS)
cout << "Incorrect entry" << endl;
else
extractDesignatedColumns(nbrOfRows, &totalColumnTwo, &totalColumnFour);
printStatistics (nbrOfRows, totalColumnTwo, totalColumnFour);
system ("PAUSE");
return 0;
} // End main
// ############################################################
void extractDesignatedColumns(int nbrOfRows, float &totalColumnTwo,
float &totalColumnFour)
{
float columnOne,columnTwo,columnThree,columnFour,columnFive;
int counter;
for (int counter = 1; counter <= nbrOfRows; counter++)
{
cin >> columnOne >> columnTwo >> columnThree >> columnFour >> columnFive ;
totalColumnTwo = columnTwo + totalColumnTwo;
totalColumnFour = columnFour + totalColumnFour;
cout << setw(10) << totalColumnTwo << setw(10) << totalColumnFour << endl;
}
}
// ############################################################
void printStatistics(int nbrOfRows, float totalColumnTwo, float totalColumnFour)
{
cout << "Total of Column Two : " << totalColumnTwo << endl;
cout << "Average of Column Two is " << (totalColumnTwo / nbrOfRows) << endl;
cout << "Total of Column Four : " << totalColumnFour << endl;
cout << "Average of Column Four is " << (totalColumnFour / nbrOfRows) << endl;
}
|