Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

WARNING THIS QUESTION NEEDS A GEEK TO HELP ME ETHER RE-BUILD THE PROGRAM OR DEBU

ID: 3777733 • Letter: W

Question

WARNING THIS QUESTION NEEDS A GEEK TO HELP ME ETHER RE-BUILD THE PROGRAM OR DEBUG THIS CODE

Write a C++ program to obtain the Mid_term and Final exam scores for 10 students (Student 1 to Student 10) from the user and then compute and print the following:

1 Total score, where Total score = 40% (Mid_term) + 60%(Final).

2 Maximum score in Mid-Term exam and the corresponding student

3 Maximum score in Final exam and the corresponding student

Requirements:

1 .You have to use ARRAYS

2 .You are required to use user-defined functions for the following tasks:

a . Getting the Mid-term and Final exam scores from the user

b . Calculating the Total score

c . Computing the maximum scores in Mid-term and Final exam.

3 .Assume it’s a maximum of 10 students and all of them have scores >=0 but <=100. You are therefore, required to make sure the user’s input falls in the valid range. If not, give him/her one more chance to enter the right score.

4 .If the user does not enter the right score, after two chances, set the score to ZERO and move to the next score.

5 .Make sure you scan the user’s input as described above for one student, before going to the next.

Hint: Use one array each to store Mid-term and Final scores.

Sample RUN:

Please enter the Mid-term and Final scores for student 1

20

98.5

Please enter the Mid-term and Final scores for student 2

-10.9 35

Sorry, the scores have to be in the range of 0 to 100. Please enter the Mid-Term score again:

90

Please enter the Mid-Term and Final scores for Student 3

90

120

Sorry, the scores have to be in the range of 0 to 100. Please enter the Final Exam score again: 99

Please enter the Mid-Term and Final scores for Student 7

101 -20

Sorry, the scores have to be in the range of 0 to 100. Please enter the scores again: 999

-10

//After giving one more chance, if the user’s input is invalid, set the Mid-term and Final exam scores to 0 and move to the next student.

Please enter the Mid-Term and Final scores for Student 10

90

100

Thank you!

Here is the total score for all the students in your class.

Student 1

67.1

Student 2

57

Student 3

               

95.4

Student 7

0.0

Student 10

96

Maximum score in Mid-term exam is 99 and was scored by Student 4

Maximum score in Final exam is 100 and was scored by Student 10

Please, include comments to explain the user defined functions, especially if they include non-entry level code. Also, a sample run would be great on a Linux kernel distribution.

THIS IS what I GOT SO FAR, but still, the final output is not printing out the correct total of the student; I think because the values of the MidTerm[i] and FinalExam[i] don't get updated after finishing the maximum number of trials to re-enter the values of the midterm and final exam scores.

One last thing..... I have 3 CHECK stages in the body of my main:

1. if both the midterm && final exam score are entered wrong

2. if midterm exam score ONLY is entered wrong by the user

3. if Final exam score ONLY is entered wrongly by the user.

CODE

------------------------------------------------------------

#include <iostream>

using namespace std;

//Function that calculates total score
void calculateTotalScore(double MidTerm[], double FinalExam[])
{
int i;
double total;

cout << " Total Score of all students in the class: ";

//Iterating over scores
for(i=0; i<10; i++)
{
//Calculating total score as Total = 40% (Mid_term) + 60%(Final)
total = ( (40/100.0) * (MidTerm[i]) ) + ( (60/100.0) * (FinalExam[i]) );

//Printing result
cout << " Student " << (i+1) << " : " << total;
}

cout << " ";
}

//Function that finds the maximum mid term score
void findMaxMidTermScore(double MidTerm[])
{
int i, max=0;

//Iterating over midterm scores
for(i=0; i<10; i++)
{
//Updating max score index
if(MidTerm[i] > MidTerm[max])
max = i;
}

//Printing max mid term score details
cout << " Maximum score in Mid-term exam is " << MidTerm[max] << " and was scored by Student " << (max+1) << " ";
}


//Function that finds the maximum Final exam score
void findFinalExamScore(double FinalExam[])
{
int i, max=0;

//Iterating over final exam scores
for(i=0; i<10; i++)
{
//Updating max score index
if(FinalExam[i] > FinalExam[max])
max = i;
}

//Printing max final exam score details
cout << " Maximum score in Mid-term exam is " << FinalExam[max] << " and was scored by Student " << (max+1) << " ";
}

//Main function
int main()
{
double MidTerm[10], FinalExam[10];
double mid=0, finalScore=0;
int i, k, z, y;

//Iterating over 10 students
for(i=0; i<10; i++)
{
//Reading scores
cout << " Please enter the Mid-term and Final scores for student " << (i+1) << ": ";
cin >> mid >> finalScore;

//validating both midterm and finalscores
k=0;
if ( ( (mid < 0 || mid >100) && (finalScore < 0 || finalScore > 100) ) && k<=1 ) {
  
cout << " Sorry, the scores have to be in the range of 0 to 100. Please enter both midterm and Final Exam scores again" << endl;
cin >> mid >>finalScore;

k++;

cout << "The value of K in the if loop is =" << k <<endl;
}

else if (k > 1)
{

MidTerm[i]=0;
FinalExam[i]=0;
mid = 0;
finalScore = 0;

}

//Validating mid term score
z=0;
if( (mid < 0 || mid > 100) && z <= 1 && k!=1 )
{
cout << " Sorry, the scores have to be in the range of 0 to 100. Please enter the Mid-Term score again: ";
cin >> mid;

z++;
}

//Assigning value to mid term score
else if(z>1)
{
MidTerm[i] = 0;

}
else
{
MidTerm[i] = mid;
}

//Validating final exam score

y=0;
if( (finalScore < 0||finalScore > 100) && y <= 1 && k!=1)
{
cout << " Sorry, the scores have to be in the range of 0 to 100. Please enter the Final Exam score again: ";
cin >> finalScore;

y++;
}

//Updating final exam score details
else if(y>1)
{
FinalExam[i] = 0;
}
else
{
FinalExam[i] = finalScore;

}//end of else
}//end of for loop that iterates over the 10 students


//Calculating total scores
calculateTotalScore(MidTerm, FinalExam);

//Finding maximum midterm score
findMaxMidTermScore(MidTerm);

//Finding maximum final exam score
findFinalExamScore(FinalExam);

cout << " ";
return 0;
}

Student 1

67.1

Student 2

57

Student 3

               

95.4

Student 7

0.0

Student 10

96

Explanation / Answer

hi. Below is the working code for your question, I had comments & corrected the code :

#include "stdafx.h"
#include <iostream>

using namespace std;

//Function that calculates total score
void calculateTotalScore(double MidTerm[], double FinalExam[])
{
   int i;
   double total;
   cout << " Total Score of all students in the class: ";

   //Iterating over scores
   for (i = 0; i<10; i++)
   {
       //Calculating total score as Total = 40% (Mid_term) + 60%(Final)
       total = ((40 / 100.0) * (MidTerm[i])) + ((60 / 100.0) * (FinalExam[i]));

       //Printing result
       cout << " Student " << (i + 1) << " : " << total;
   }
   cout << " ";
}

//Function that finds the maximum mid term score
void findMaxMidTermScore(double MidTerm[])
{
   int i, max = 0;

   //Iterating over midterm scores
   for (i = 0; i<10; i++)
   {
       //Updating max score index
       if (MidTerm[i] > MidTerm[max])
           max = i;
   }

   //Printing max mid term score details
   cout << " Maximum score in Mid-term exam is " << MidTerm[max] << " and was scored by Student " << (max + 1) << " ";
}


//Function that finds the maximum Final exam score
void findFinalExamScore(double FinalExam[])
{
   int i, max = 0;

   //Iterating over final exam scores
   for (i = 0; i<10; i++)
   {
       //Updating max score index
       if (FinalExam[i] > FinalExam[max])
           max = i;
   }

   //Printing max final exam score details
   cout << " Maximum score in Mid-term exam is " << FinalExam[max] << " and was scored by Student " << (max + 1) << " ";
}

//Main function
int main()
{
   double MidTerm[10], FinalExam[10];
   double mid = 0, finalScore = 0;
   int i, k;

   //Iterating over 10 students
   for (i = 0; i<10; i++)
   {
       //Reading scores
       cout << " Please enter the Mid-term and Final scores for student " << (i + 1) << ": ";
       cin >> mid >> finalScore;

       //validating both midterm and finalscores
       int chances = 2; //user should be given two more chance to enter the correct score
       k = 0;
       while (chances > 0)
       {
           if (mid < 0 || mid >100 || finalScore < 0 || finalScore > 100)
           {
               cout << " Sorry, the scores have to be in the range of 0 to 100. Please enter both midterm and Final Exam scores again" << endl;
               cin >> mid >> finalScore;
               k = 1;
           }
           else
           {
               k = 0;
               break;
           }
       }
       if (k == 1)
       {
           MidTerm[i] = 0;
           FinalExam[i] = 0;
       }
       else
       {
           MidTerm[i] = mid;
           FinalExam[i] = finalScore;
       }

   }//end of for loop that iterates over the 10 students


   //Calculating total scores
   calculateTotalScore(MidTerm, FinalExam);

   //Finding maximum midterm score
   findMaxMidTermScore(MidTerm);

   //Finding maximum final exam score
   findFinalExamScore(FinalExam);

   cout << " ";
   return 0;
}

feel free to ask if you have any doubt :)