summary14 - void display( const int grade[NUMBER_QUIZZES],...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
compute_quiz_ave(grade, quiz_ave); display(grade, st_ave, quiz_ave); } void compute_st_ave( const int grade[][NUMBER_QUIZZES], double st_ave[]) { for ( int st_num = 1; st_num <= NUMBER_STUDENTS; st_num++) { //Process one st_num: double sum = 0; for ( int quiz_num = 1; quiz_num <= NUMBER_QUIZZES; quiz_num++) sum = sum + grade[st_num-1][quiz_num-1]; //sum contains the sum of the quiz scores for student number st_num. st_ave[st_num-1] = sum/NUMBER_QUIZZES; //Average for student st_num is the value of st_ave[st_num-1] } } void compute_quiz_ave( const int grade[][NUMBER_QUIZZES], double quiz_ave[]) { for ( int quiz_num = 1; quiz_num <= NUMBER_QUIZZES; quiz_num++) { //Process one quiz (for all students): double sum = 0; for ( int st_num = 1; st_num <= NUMBER_STUDENTS; st_num++) sum = sum + grade[st_num-1][quiz_num-1]; //sum contains the sum of all student scores on quiz number quiz_num. quiz_ave[quiz_num-1] = sum/NUMBER_STUDENTS; //Average for quiz quiz_num is the value of quiz_ave[quiz_num-1] } } //Uses iostream and iomanip:
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: void display( const int grade[NUMBER_QUIZZES], const double st_ave, const double quiz_ave) { using namespace std; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(1); cout &lt;&lt; setw(10) &lt;&lt; &quot;Student&quot; &lt;&lt; setw(5) &lt;&lt; &quot;Ave&quot; &lt;&lt; setw(15) &lt;&lt; &quot;Quizzes\n&quot; ; for ( int st_num = 1; st_num &lt;= NUMBER_STUDENTS; st_num++) { //Display for one st_num cout &lt;&lt; setw(10) &lt;&lt; st_num &lt;&lt; setw(5) &lt;&lt; st_ave[st_num-1] &lt;&lt; &quot; &quot; ; for ( int quiz_num = 1; quiz_num &lt;= NUMBER_QUIZZES; quiz_num++) cout &lt;&lt; setw(5) &lt;&lt; grade[st_num-1][quiz_num-1]; cout &lt;&lt; endl; } cout &lt;&lt; &quot;Quiz averages = &quot; ; for ( int quiz_num = 1; quiz_num &lt;= NUMBER_QUIZZES; quiz_num++) cout &lt;&lt; setw(5) &lt;&lt; quiz_ave[quiz_num-1]; cout &lt;&lt; endl; } Summary Ch 10.5 Chapter 10.5 Multidimensional Arrays If you need an array with more than one index, you can use a multidimensional array, which is actually an array of arrays....
View Full Document

This note was uploaded on 08/26/2009 for the course CS 140 taught by Professor Staff during the Fall '08 term at Southern Illinois University Edwardsville.

Ask a homework question - tutors are online