hey all...this code compiles and runs correctly...all except a Kernell32.dll error that pops up during the run. Anyone see
a pile of dlls on the stack inappropriately that would cause this?
(It's one of my early 2d array progs that i did in my 1st class).
I never was able to debug the error out.
thanks a bunch, it may teach me something about how to trouble-shoot these and other errors
mouse163
Code:
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
const int kcols = 6;
const int krows = 4;
void Loadit(int arr2d[][kcols], int rows);
void Printit_a(int arr2d[][kcols], int rows);
void Printit_b(int arr2d[][kcols], int rows);
void Maxit(int arr2d[][kcols], int rows);
void RsumL(int arr2d[][kcols], int rows);
void CsumS(int arr2d[][kcols], int rows);
ofstream outfile("A:\\0F1031c.txt");
int main ()
{
if(!outfile)
{
cerr << "Cannot open output file" << endl;
return 1;
}
int arr2d[][kcols]={0};
Loadit(arr2d, krows);
Printit_a(arr2d, krows);
Printit_b(arr2d, krows);
Maxit(arr2d, krows);
RsumL(arr2d, krows);
CsumS(arr2d, krows);
outfile.close();
return 0;
}
//Part1 : Function definition: Load
void Loadit(int arr2d[][kcols], int rows)
{
ifstream infile("A:\\IF1031.txt");
if(!infile)
{
cerr << "Cannot open input file" << endl;
} //inf
for ( int i = 0; i < rows; i++ ){
for ( int j = 0; j < kcols; j++ ){
infile >> arr2d[i][j];
}//j loop
}
infile.close();
}// fx end
//Part2a : Function definition: Print(ordered pairs)
void Printit_a(int arr2d[][kcols], int rows)
{
outfile << "\n\n";
outfile<< setw(60)
<< "Part 1 & 2 - Loaded & Printed Array as an Ordered Pair:"
<< "\n\n" << endl;
outfile<< setw(30) << endl;
for ( int i = 0; i < krows; i++ )
{
for ( int j = 0; j < kcols; j++ )
{
outfile << "arr2d[" << i << "]" << "[" << j << "] =";
outfile<< arr2d[i][j]<< endl << setw(30);
}// j loop
}//i loop
outfile << "\n\n";
}// fx end
//Part2b : Function definition: Print (matrix)
void Printit_b(int arr2d[][kcols], int rows)
{
outfile << "\n\n";
outfile<< setw(50)
<< "Loaded & Printed Array as a Matrix:"
<< "\n\n" << endl;
outfile<< setw(23) << "";
for (int j = 0; j < kcols; j++ )
{
outfile << j << setw(4);
} // j loop
outfile << endl;
outfile<<setw(3*kcols)<<" ";
for (int line = 0;line < kcols;line++)
{
outfile<<"-----";
}//line
outfile << endl;
for (int i = 0; i < krows; i++)
{
outfile<< setw(20) << i << "|" << setw(2);
for ( int j = 0; j < kcols; j++ )
{
outfile<< setw(4) << arr2d[i][j]<< setw(6);
}//j loop
outfile << endl;
}//i loop
outfile << "\n\n-------------------------------------------------------------------\n";
}// fx end
//Part3 : Function definition: Largest Int & Address
void Maxit(int arr2d[][kcols], int rows)
{
outfile << "\n\n";
outfile<< setw(57)
<< "Part 3 - Largest Int in the Array and it's Location:"
<< "\n\n" << endl;
int maxi = 0;
int maxj = 0;
for (int i = 0; i < krows; i++)
{
for (int j = 0; j < kcols; j++)
{
if (arr2d[i][j] > arr2d[maxi][maxj])
{
maxi = i;
maxj = j;
}// if
}//j loop
}//i loop
outfile<< setw (25) << "The Max Value is "
<< arr2d[maxi][maxj];
outfile<< " it occurs at arr2d["
<< maxi <<"][" << maxj << "]" << endl;
outfile << "\n\n-------------------------------------------------------------------\n";
}// fx end
//Part4 : Function definition: Row Sums / Largest Sum
void RsumL(int arr2d[][kcols], int rows)
{
outfile << "\n\n";
outfile<< setw(62)
<< "Part 4 - Sum of each Row & the Row with the largest Sum: "
<< "\n\n" << endl;
int maxi = 0;
int maxsum = 0;
for (int i = 0; i < krows; i++)
{
int sum = 0;
for (int j = 0; j < kcols; j++)
{
sum += arr2d[i][j];
}//j loop
outfile << setw(30)
<< "Sum of Row "
<< i<< " is " << sum << endl;
if (sum > maxsum)
{
maxsum = sum; // assign max sum
maxi = i; // call row w/ maxsum
}//if
}//i loop
outfile << setw(42)
<< " The Max Sum is in Row "
<< maxi << endl;
outfile << setw(29) << " The Sum = "
<< maxsum << endl;
outfile << "\n\n-------------------------------------------------------------------\n";
}// fx end
//Part5 : Function definition: Column Sums / Smallest Sum
void CsumS(int arr2d[][kcols], int rows)
{
outfile << "\n\n";
outfile<< setw(69) << "Part 5 - Sum of each Column & the Column with the Smallest Sum: " << "\n\n" << endl;
int minj = 0;
int minsum = 32768;
for (int j = 0; j < kcols; j++)
{
int sum = 0;
for (int i = 0; i < krows; i++)
{
sum += arr2d[i][j]; // for each row add one to the col sum
}//i loop
outfile << setw(33)
<< "Sum of Column "<< j
<< " is " << sum << endl;
if(sum < minsum)
{
minsum = sum; //assign min sum
minj = j; // call the col with the min sum
}// if
}//j loop
outfile << setw(45)
<< " The Min Sum is in Column " << minj << endl;
outfile << setw(29) << " The Sum = "
<< minsum << endl;
outfile << "\n\n-------------------------------------------------------------------\n";
}//fx end