Answer to Question #272711 in C++ for Phil

Question #272711

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. 

ii. Declare a function that takes an array of Hope’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 Hope has passed or not given that a pass is 50 – 100 while a fail is 0 – 49.99 Marks.

iv. Display Hope’s results as follows: (this is a sample output, use arbitrary values in your

solution)

Student Name: Hope Michael

Test Scores:

Total Marks:

Mean Score:

Exams Verdict: Pass

40, 50, 60, 80, 98, 82, 70, 32


1
Expert's answer
2021-11-28T05:27:00-0500

Source code

#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
    int scores[8];
    cout<<"\nEnter the eight scores: ";
    for(int i=0;i<8;i++){
        cin>>scores[i];
    }
    cout<<"\nTest Scores: ";
    for(int i=0;i<8;i++){
        if (i==7)
            cout<<scores[i];
        else
            cout<<scores[i]<<", ";
    }
    cout<<"\nTotal Marks: "<<calculateTotalAndMean(scores)*8;
    cout<<"\nMean Score: "<<calculateTotalAndMean(scores);
    cout<<"\nExams Verdict: "<<passOrFail(calculateTotalAndMean(scores));
    return 0;
}


Output





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS