1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
//Compute a program that declares and initializes a two dimensional array called scores
#include<iostream>
#include<iomanip>
using namespace std;
const int testNum=3;
const int scores=10;
double ClassAvg(int scores[10][3], int testNum);
int main()
{
double CAvg1,CAvg2,CAvg3;
int table[scores][testNum]={{88,98,76},
{76,88,87},
{56,77,55},
{55,89,66},
{76,98,66},
{87,84,81},
{80,91,77},
{69,70,81},
{85,99,77},
{88,91,79} };
CAvg1=ClassAvg(scores,0);
CAvg2=ClassAvg(scores,1);
CAvg3=ClassAvg(scores,2);
cout<<"The class scores are:\n";
ClassAvg(table,scores)
cout<<setw(5)<<"Students #"<<setw(7)<<"Test #1"<<setw(7)<<"Test #2"<<setw(7)<<"Test #3"<<endl;
cout<<"The class average for test#1 is: "<<CAvg1<<endl;
cout<<"The class average for test#2 is: "<<CAvg2<<endl;
cout<<"The class average for test#3 is: "<<CAvg3<<endl;
return 0;
}
double ClassAvg(int array[][testNum], int numRows)
{
for(int row=0;row<numRows;row++)
{
for(int col=0;col<testNum;col++)
{
cout<<setw(5)<<array[row][col]<<" ";
}
cout<<endl;
}
}
}
|