Time：2021-6-28

Achievement statistics

1) Write a function randscore to generate an integer of [0100] interval（ Tip: use rand function)

``````int randScore(){
int num = rand() % 101;
return num;
}``````

2) Write a function, using the above randscore function, randomly generate the results of a course for the whole class.

``````void stuRandomScore(int stuScore[]){
for (int i = 0; i < stuNum; i++)
stuScore[i] = randScore();
for (int i = 0; i < stuNum; i++)
Cout < < I + 1 < < students' scores are: < stuscore [i] < endl;
}``````

3) Write a function score2grade to realize the conversion from the hundred point system to the five point system.

``````void Score2Grade(int stuScore[]){
for (int i = 0; i < stuNum; i++)
if (stuScore[i] >= 50)
score2Grade[i] = float(stuScore[i]) / 10 - 5;
else
for (int i = 0; i < stuNum; i++)
Cout < "No." < I + 1 < "grade points of students: < score2grade [i] < endl;
}``````

4) Write a function to use score2grade to count the proportion of different grades of the whole class.

``````void PersentGrade(float score2Grade[5]){
int per[5] = {0};
for (int i = 0; i < stuNum; i++){
per[0]++;
per[1]++;
per[2]++;
per[3]++;
per[4]++;
}
for (int i = 0; i < 5; i++){
Cout < "the proportion is: < persentgrade [i] < endl;
}
}``````

5) Write a function to calculate the average score and standard deviation of the whole class.

``````float Average(int *stuScore){
int sum = 0;
for (int i = 0;  i < stuNum;  I + +) // sum
sum += stuScore[i];
return float(sum) / stuNum; //  Get the average
}
float StandardDeviation(int *stuScore){
float sum = 0;
float average = Average(stuScore);
for (int i = 0;  i < stuNum;  I + +) // sum
sum += pow(stuScore[i] - average, 2);
return sqrt(sum / stuNum);
}``````

The procedures are summarized below

``````#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;
class MyScores{
public:
int stuNum;
int *stuScore;
int randScore(){
int num = rand() % 101;
return num;
}
void stuRandomScore(int stuScore[]){
for (int i = 0; i < stuNum; i++)
stuScore[i] = randScore();
for (int i = 0; i < stuNum; i++)
Cout < < I + 1 < < students' scores are: < stuscore [i] < endl;

}
for (int i = 0; i < stuNum; i++)
if (stuScore[i] >= 50)
score2Grade[i] = float(stuScore[i]) / 10 - 5;
else
for (int i = 0; i < stuNum; i++)
Cout < "No." < I + 1 < "grade points of students: < score2grade [i] < endl;
}
int per[5] = {0};
for (int i = 0; i < stuNum; i++){
per[0]++;
per[1]++;
per[2]++;
per[3]++;
per[4]++;
}
for (int i = 0; i < 5; i++){
/ stuNum;
Cout < < I < "~" < I + 1 < "the proportion is: < persentgrade [i] < endl;
}
}
float Average(int *stuScore){
int sum = 0;
for (int i = 0;  i < stuNum;  I + +) // sum
sum += stuScore[i];
return float(sum) / stuNum; //  Get the average
}
float StandardDeviation(int *stuScore)
{
float sum = 0;
float average = Average(stuScore);
for (int i = 0;  i < stuNum;  I + +) // sum
sum += pow(stuScore[i] - average, 2);
return sqrt(sum / stuNum);
}
};

void main(){
MyScores t;
cin >> t.stuNum;
t.stuScore = new int[t.stuNum];
t.stuRandomScore(t.stuScore);
cout << endl;
cout << endl;