I'm trying to take a list of student id numbers along with a list of grades for each student for 5 quizes, store them into a 2-dimensional array, then output the minimum, maximum, and average for each column. I need help on how to do the minimum and maximum for each individual column ( excluding column 1, which is the student ID#s). PS, this is due tonight. He gave us the project after class today, but I had to work til 10, so I've only had about 45 mins to work on it so far and I really need help. The text file looks like this:
Well, I figured it out. Here's the completed source code thanks to no one, but myself... even though it was due an hour & a half ago.
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
ifstream infile;//input file name
int min[ 5], max[ 5 ];//arrays for min and max value of each column
int quizarr[ 26 ][ 6 ];//declares two dimensional array of 26 rows, 6 columns
int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0;//totals for each column
int r = 0, c = 0;// rows and columns
cout << "Program is now opening 'QuizGrades.txt'" << endl << endl;
infile.open( "QuizGrades.txt" );//opens QuizGrades.txt
if( !infile )
{
cerr << "ERROR 001 OCCURRED WHEN ATTEMPTING TO OPEN 'QuizGrades.txt'\n\n" << endl;//shows error if QuizGrades.txt does not open
exit( 001 );//exits the program if file is not opened
}//end if
cout << "Program is now storing the students ID numbers and quiz grades into an array \nand calculating the average, maximum, and minimum for each quiz.\n\n";
cout << "Press any key to get to the quiz grades.\n\n";
system ( "PAUSE" );//pauses the output screen
system ( "CLS" );//clears the output screen
cout << setw ( 12 ) << "ID #" << setw ( 12 ) << "Quiz 1" << setw ( 12 ) << "Quiz 2" << setw ( 12 ) << "Quiz 3" << setw ( 12 ) << "Quiz 4" << setw ( 12 ) << "Quiz 5" << endl << endl;
for ( r = 0; r < 26; r++ )//puts each ID# and quiz grade into their appropriate positions in the 2-dimensional array
{
for ( c = 0; c < 6; c++ )
{
infile >> quizarr[ r ][ c ];
cout << setw ( 12 );
cout << quizarr[ r ][ c ];
}//end for
cout << endl;
}//end for
cout << endl;
system ("PAUSE");
system("CLS");
cout << setw ( 12 ) << "ID #" << setw ( 12 ) << "Quiz 1" << setw ( 12 ) << "Quiz 2" << setw ( 12 ) << "Quiz 3" << setw ( 12 ) << "Quiz 4" << setw ( 12 ) << "Quiz 5" << endl << endl;
for ( r = 0; r < 26; r++ )//puts each ID# and quiz grade into their appropriate positions in the 2-dimensional array
{
for ( c = 0; c < 6; c++ )
{
cout << setw ( 12 );
cout << quizarr[ r ][ c ];
}//end for
cout << endl;
}//end for
for ( r = 0; r < 26; r++ )//determines the sum for each column ( excluding column 0 )
{
sum1 += quizarr[ r ][ 1 ];//sum for column 1
sum2 += quizarr[ r ][ 2 ];//sum for column 2
sum3 += quizarr[ r ][ 3 ];//sum for column 3
sum4 += quizarr[ r ][ 4 ];//sum for column 4
sum5 += quizarr[ r ][ 5 ];//sum for column 5
}//end for
for ( c = 1; c < 6 ; c++ )
{
min[ c ] = quizarr[ 0 ][ c ]; //assumes first element in cth Column is min
max[ c ] = quizarr[ 0 ][ c ]; //assumes first element in cth Column is max
for ( r = 1; r < 26; r++ )//finds the min and max value for each column
{
if ( max[ c ] < quizarr[ r ][ c ])
{
max[ c ] = quizarr[ r ][ c ];
}//end if
if ( quizarr[ r ][ c ] < min[ c ] )
{
min[ c ] = quizarr[ r ][ c ];
}//end if
}//end for
}//end for
cout << endl << "________________________________________________________________________________" << endl << endl;
cout << setw ( 12 ) << "Average:" << setw ( 12 ) << setprecision( 4 ) << sum1 / 26.0 << setw ( 12 ) << setprecision( 4 ) << sum2 / 26.0 << setw ( 12 ) << setprecision( 4 ) << sum3 / 26.0 << setw ( 12 ) << setprecision( 4 ) << sum4 / 26.0 << setw ( 12 ) << setprecision( 4 ) << sum5 / 26.0 << endl << endl;
cout << setw ( 12 ) << "Minimum:" << setw ( 12 ) << min[ 1 ] << setw ( 12 ) << min[ 2 ] << setw ( 12 ) << min[ 3 ] << setw ( 12 ) << min[ 4 ] << setw ( 12 ) << min[ 5 ] << endl << endl;
cout << setw ( 12 ) << "Maximum:" << setw ( 12 ) << max[ 1 ] << setw ( 12 ) << max[ 2 ] << setw ( 12 ) << max[ 3 ] << setw ( 12 ) << max[ 4 ] << setw ( 12 ) << max[ 5 ] << endl << endl;
system( "PAUSE" );//pauses the output screen
system( "CLS" );//clears the output screen
cout << "The program is now closing the input file 'QuizGrades.txt'\n\n";
infile.close( );//closes input file
cout << "The program has completed all necessary tasks.\n\n";
system( "PAUSE" );
}//end main
So you posted it a little bit before your due date, and didn't even bother formating your code with [code][/code] tags. And bother to point out "thanks to no one but yourself" ...
So, if you read the description, I said The teacher gave us the assignment in class at 3:00, I had to work from 4:00-10:00, I got home at 10:45, and it was due by midnight, which means I had a grand total of 1 hour and 15 minutes to complete it and email it to the professor. Thanks for posting a sarcastic comment when you obviously didn't even thoroughly read the description.
Thanks for posting a sarcastic comment when you obviously didn't even thoroughly read the description.
Maybe you should read the forum rules (ie. how to use code tags). It is not anyone's problem how your work schedule conflicts with your assignments. Try being a little less rude and maybe you will get better responses.