Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

This is a C++ program... it doesnt work... I don't like C++!!!!

 

// Double-subscripted array example
#include <iostream>

using std::cout;
using std::endl;
using std::ios;

#include <iomanip>

using std::setw;
using std::setiosflags;
using std::setprecision;

const int s = 7; // number of students
const int e = 3; // number of exams

int minimum( int [][ e ], int, int ); // finds the minimum grade
int maximum(int [][ e ], int, int ); // finds the maximum grade
double average( int [], int ); //average grade
void printArray( int [][ e ], int, int ); //prints the array
void copy1(char *,const char *);
void copy2(char *,const char *);
int main()
{
int studentGrades[ s ][ e ] =
{ { 77, 68, 86,},
{ 96, 87, 89,},
{ 70, 90, 86,},
{ 45, 59, 63,},
{ 62, 55, 78,},
{ 10, 48, 36,},
{ 56, 45, 43,},

};
cout << "The array is:\n";
printArray( studentGrades, s, e );
cout << "\n\nLowest grade: "
<< minimum( studentGrades, s, e )
<< "\nHighest grade: "
<< maximum( studentGrades, s, e ) << '\n';

for ( int person = 0; person < s; person++ )
cout << "The average grade for student " << person << " is "
<< setiosflags( ios::fixed | ios::showpoint )
<< setprecision( 3 )
<< average( studentGrades[ person ], e ) << endl;

return 0;
}

// Find the minimum grade
int minimum( int grades[][ e ], int pupils, int tests )
{
int lowGrade = 100;

for ( int i = 0; i < pupils; i++ )

for ( int j = 0; j < tests; j++ )

if ( grades[ i ][ j ] < lowGrade )
lowGrade = grades[ i ][ j ];

return lowGrade;
}

// Find the maximum grade
int maximum( int grades[][ e ], int pupils, int tests )
{
int highGrade = 0;

for ( int i = 0; i < pupils; i++ )

for ( int j = 0; j < tests; j++ )

if ( grades[ i ][ j ] > highGrade )
highGrade = grades[ i ][ j ];

return highGrade;
}

// Determine the average grade for a particular student
double average( int setOfGrades[], int tests )
{
int total = 0;

for ( int i = 0; i < tests; i++ )
total += setOfGrades[ i ];

return static_cast< double >( total ) / tests;
}

// Print the array
void printArray( int grades[][ e ], int pupils, int tests )
{
cout << " [0] [1] [2] [3]";

for ( int i = 0; i < pupils; i++ ) {
cout << "\nstudentGrades[" << i << "] ";

for ( int j = 0; j < tests; j++ )
cout << setiosflags( ios::left ) << setw( 5 )
<< grades[ i ][ j ];
}

// copy s2 to s1 using array notation
void copy1( char *s1, const char *s2 )
{
for ( int i = 0; ( s1[ i ] = s2[ i ] ) != '\0'; i++ )
; // do nothing in body}
}
// copy s2 to s1 using pointer notation
void copy2( char *s1, const char *s2 )
{
for ( ; ( *s1 = *s2 ) != '\0'; s1++, s2++ );
; // do nothing in body
}

}

Back More
Home