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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream>
#include <iomanip>
using namespace std;
const int NUMBER_STUDENTS = 200, MIN_Numb = 1,ID=500;
const int MAX_SCORE = 100, MIN_SCORE = 1;
void randomInitArray(int grade[][MIN_Numb], int min, int max);
void computeStAve(const int grade[][MIN_Numb], double StAve[]);
void display(const int grade[][MIN_Numb], const double StAve[]);
int main(){
int grade[NUMBER_STUDENTS][MIN_Numb];
double StAve[NUMBER_STUDENTS];
srand(time(NULL));
randomInitArray(grade, MIN_SCORE, MAX_SCORE);
computeStAve(grade, StAve);
display(grade, StAve);
system("pause");
return 0;
}
void randomInitArray(int grade[][MIN_Numb], int min, int max){
for (int stNum = 1; stNum <= NUMBER_STUDENTS; stNum++)
{
for (int randNumb = 1; randNumb <= MIN_Numb; randNumb++)
{
grade[stNum - 1][randNumb - 1] = rand() % max + min;
}
}
}
void computeStAve(const int grade[][MIN_Numb], double StAve[]){
for (int stNum = 1; stNum <= NUMBER_STUDENTS; stNum++){
int sum = 0;
for (int randNumb = 1; randNumb <= MIN_Numb; randNumb++){
sum = sum + grade[stNum - 1][randNumb - 1];
}
StAve[stNum - 1] = (double)sum / MIN_Numb;
}
}
void display(const int grade[][MIN_Numb], const double StAve[]){
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << setw(10) << "Student ID"
<< setw(10) << "Score\n";
for (int stNum = 1; stNum <= NUMBER_STUDENTS; stNum++){
cout << setw(10) << stNum
<< setw(10) << StAve[stNum - 1] << " ";
for (int randNumb = 1; randNumb <= MIN_Numb; randNumb++){
}
cout << endl;
}
}
|