Hope Michael, a DBIT student did 8 units in an exam and got different marks in each of the exam papers. She intends to calculate her total, mean score and exams verdict for the exams using a program written in C++. Requirements/Guide. (All the instructions below should be done in the same single program)
i. Assign 8 scores to Hope in a one-dimensional array. [2 Marks]
ii. Declare a function that takes an array of Hope’s scores as a parameter and calculates both the total and the mean score. [3 Marks]
iii. Pass the mean score from (ii) above into another function by reference, that computes whether Hope has passed or not given that a pass is 50 – 100 while a fail is 0 – 49.99 Marks. [3 Marks]
iv. Display Hope’s results as follows: (this is a sample output, use arbitrary values in your solution) [2 Marks]
Student Name: Hope Michael
Test Scores: 40, 50, 60, 80, 98, 82, 70, 32
Total Marks: 512
Mean Score: 64
Exams Verdict: Pass
#include <iostream>
using namespace std;
double calculateTotalAndMean(int arr[]){
int total=0;
for(int i=0;i<8;i++){
total+=arr[i];
}
double mean=(total/8.0);
return mean;
}
string passOrFail(double n){
if(n>=50 && n<=100){
return "Pass";
}
else if(n>=0 && n<=49.99){
return "Fail";
}
return "";
}
int main()
{
int scores[]={40, 50, 60, 80, 98, 82, 70, 32};
cout<<"\nTest Scores: ";
for(int i=0;i<8;i++){
cout<<scores[i]<<", ";
}
cout<<"\nTotal Marks: "<<calculateTotalAndMean(scores)*8;
cout<<"\nMean Score: "<<calculateTotalAndMean(scores);
cout<<"\nExams Verdict: "<<passOrFail(calculateTotalAndMean(scores));
return 0;
}
Comments
Leave a comment