#include <iostream>
#include <iomanip>
using namespace std;
//Global constant variable declaration
const int MaxRows = 8, MaxCols = 10, SEED = 10325;
//Functions Declaration
void PrintNameHeader(ostream& out);
void Fill2DArray(double ary[][MaxCols]);
void Print2DArray(const double ary[][MaxCols]);
double GetTotal(const double ary[][MaxCols]);
double GetAverage(const double ary[][MaxCols]);
double GetRowTotal(const double ary[][MaxCols], int theRow);
double GetColumnTotal(const double ary[][MaxCols], int theRow);
double GetHighestInRow(const double ary[][MaxCols], int theRow);
double GetLowestInRow(const double ary[][MaxCols], int theRow);
double GetHighestInCol(const double ary[][MaxCols], int theCol);
double GetLowestInCol(const double ary[][MaxCols], int theCol);
double GetHighest(const double ary[][MaxCols], int& theRow, int& theCol);
double GetLowest(const double ary[][MaxCols], int& theRow, int& theCol);
int main()
{
int theRow;
int theCol;
PrintNameHeader(cout);
cout << fixed << showpoint << setprecision(1);
srand(static_cast<unsigned int>(SEED));
double ary[MaxRows][MaxCols];
cout << "The seed value for random number generator is: " << SEED << endl;
cout << endl;
Fill2DArray(ary);
Print2DArray(ary);
cout << " The Total for all the elements in this array is: " << setw(7) << GetTotal(ary) << endl;
cout << "The Average of all the elements in this array is: " << setw(7) << GetAverage(ary) << endl;
cout << endl;
cout << "The sum of each row is:" << endl;
for(int index = 0; index < MaxRows; index++)
{
cout << "Row " << (index + 1) << ": " << GetRowTotal(ary, theRow) << endl;
}
cout << "The highest and lowest of each row is: " << endl;
for(int index = 0; index < MaxCols; index++)
{
cout << "Row " << (index + 1) << ": " << GetHighestInRow(ary, theRow) << " " << GetLowestInRow(ary, theRow) << endl;
}
cout << "The highest and lowest of each column is: " << endl;
for(int index = 0; index < MaxCols; index++)
{
cout << "Col " << (index + 1) << ": " << GetHighestInCol(ary, theRow) << " " << GetLowestInCol(ary, theRow) << endl;
}
cout << "The highest value in all the elements in this array is: " << endl;
cout << GetHighest(ary, theRow, theCol) << "[" << theRow << "]" << "[" << theCol << "]" << endl;
cout << "The lowest value in all the elements in this array is: " << endl;
cout << GetLowest(ary, theRow, theCol) << "[" << theRow << "]" << "[" << theCol << "]" << endl;
return 0;
}
//Define Functions
void PrintNameHeader(ostream& out)
{
out << "*******************************" << endl;
out << "* *" << endl;
out << "* C.S M10A Spring 2010 *" << endl;
out << "* Programming Assignment 10 *" << endl;
out << "* Due Date: Thurs. Mar. 25 *" << endl;
out << "*******************************" << endl;
out << endl;
}
void Fill2DArray(double ary[][MaxCols])
{
for(int index1 = 0; index1 < MaxRows; index1++)
{
for(int index2= 0; index2 < MaxCols; index2++)
{
ary[index1][index2] = (rand()%1000)/10;
}
}
}
void Print2DArray(const double ary[][MaxCols])
{
cout << " Column ";
for(int index = 0; index < MaxCols; index++)
{
int column = index + 1;
cout << " " << column << " ";
}
cout << endl;
cout << " ";
for(int index = 0; index < MaxCols; index++)
{
int column = index +1;
cout << "----- ";
}
cout << endl;
for(int index1 = 0; index1 < MaxRows; index1++)
{
cout << "Row " << (index1 + 1) << ":";
for(int index2= 0; index2 < MaxCols; index2++)
{
cout << setw(6) << ary[index1][index2];
}
}
}
double GetTotal(const double ary[][MaxCols])
{
double total = 0;
for(int theRow = 0; theRow < MaxRows; theRow++)
{
total = total + GetRowTotal(ary, theRow);
}
return total;
}
double GetAverage(const double ary[][MaxCols])
{
double total = 0, average = 0;
total = GetTotal(ary);
average = total / (MaxRows * MaxCols);
return average;
}
double GetRowTotal(const double ary[][MaxCols], int theRow)
{
double sum = 0;
for(int index = 0; index < MaxCols; index++)
{
sum = sum + ary[theRow][index];
}
return sum;
}
double GetColumTotal(const double ary[][MaxCols], int theCol)
{
double sum = 0;
for(int index = 0; index < theCol; index++)
{
sum = sum + ary[index][theCol];
}
return sum;
}
double GetHighestInRow(const double ary[][MaxCols], int theRow)
{
double highest = 0;
for(int index = 0; index < MaxCols; index++)
{
if(ary[theRow][index] > highest)
highest = ary[theRow][index];
}
return highest;
}
double GetLowestInRow(const double ary[][MaxCols], int theRow)
{
double lowest = 0;
for(int index = 0; index < MaxCols; index++)
{
if(ary[theRow][index] < lowest)
lowest = ary[theRow][index];
}
return lowest;
}
double GetHighestInCol(const double ary[][MaxCols], int theCol)
{
double highest = 0;
for(int index = 0; index < MaxRows; index++)
{
if(ary[index][theCol] > highest)
highest = ary[index][theCol];
}
return highest;
}
double GetLowestInCol(const double ary[][MaxCols], int theCol)
{
double lowest = 0;
for(int index = 0; index < MaxRows; index++)
{
if(ary[index][theCol] < lowest)
lowest = ary[index][theCol];
}
return lowest;
}
double GetHighest(const double ary[][MaxCols], int& theRow, int& theCol)
{
theRow = 0;
theCol = 0;
double highest = ary[theRow][theCol];
for(int index = 0; index < MaxRows; index++)
{
for(int index1 = 0; index1 < MaxCols; index1++)
{
double highest = 0;
if(ary[index1][theCol] > highest)
{
highest = ary[index][index1];
theRow = index;
theCol = index1;
}
}
}
return highest;
}
double Getlowest(const double ary[][MaxCols], int& theRow, int& theCol)
{
theRow = 0;
theCol = 0;
double lowest = ary[theRow][theCol];
for(int index = 0; index < MaxRows; index++)
{
for(int index1 = 0; index1 < MaxCols; index1++)
{
double lowest = 0;
if(ary[index1][theCol] < lowest)
{
lowest = ary[index][index1];
theRow = index;
theCol = index1;
}
}
}
return lowest;
}
.
1>------ Build started: Project: teddy lab 10, Configuration: Debug Win32 ------
1>Compiling...
1>lab 10.cpp
1>c:\users\owner\documents\visual studio 2008\projects\teddy lab 10\teddy lab 10\ lab 10.cpp(46) : warning C4700: uninitialized local variable 'theRow' used
1>c:\users\owner\documents\visual studio 2008\projects\teddy lab 10\teddy lab 10\ lab 10.cpp(62) : warning C4700: uninitialized local variable 'theCol' used
1>Linking...
1> lab 10.obj : error LNK2028: unresolved token (0A0002E0) "double __cdecl GetLowest(double const (* const)[10],int &,int &)" (?GetLowest@@$$FYANQAY09$$CBNAAH1@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1> lab 10.obj : error LNK2019: unresolved external symbol "double __cdecl GetLowest(double const (* const)[10],int &,int &)" (?GetLowest@@$$FYANQAY09$$CBNAAH1@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>C:\Users\owner\Documents\Visual Studio 2008\Projects\ lab 10\Debug\ lab 10.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://c:\Users\owner\Documents\Visual Studio 2008\Projects\ lab 10\teddy lab 10\Debug\BuildLog.htm"
1>teddy lab 10 - 3 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========