A student did 8 units in an exam and got different marks in each of the exam papers. He intends to calculate his total, mean score and exams decision for the exams using a program written in C++.
1. Assign 8 scores to the student in a one-dimensional array.
2. Declare a function that takes an array of the student’s scores as a parameter and calculates both the total and the mean score.
3. Pass the mean score from (2) above into another function by reference, that computes whether the student has passed or not given that a pass is 50 – 100 while a fail is 0 – 49.99
Write a C++ program that will compute the above.
#include <iostream>
using namespace std;
void Mean(float scores[], float &total, float &mean){
total = 0;
for(int i = 0; i < 8; i++){
total += scores[i];
}
mean = total / 8;
}
void passFail(float &mean){
if(mean < 50) cout<<"Fail\n";
else cout<<"Pass\n";
}
int main(){
float total, mean, scores[] = {55, 72, 46, 50, 80, 40, 44, 69};
Mean(scores, total, mean);
cout<<"Total: "<<total<<endl;
cout<<"Mean: "<<mean<<endl;
passFail(mean);
return 0;
}
Comments
Leave a comment