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++.
i. Assign 8 scores to the student in a one-dimensional array.
ii. Declare a function that takes an array of the student’s scores as a parameter and calculates both the total and the mean score.
iii. Pass the mean score from (ii) 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 calcTotalMean(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[] = {75, 82, 64, 50, 48, 30, 54, 67};
calcTotalMean(scores, total, mean);
cout<<"Total: "<<total<<endl;
cout<<"Mean: "<<mean<<endl;
passFail(mean);
return 0;
}
Comments
Leave a comment