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

I need C++ programming with output Test Scores. Write a class called TestScores.

ID: 3864295 • Letter: I

Question

I need C++ programming with output

Test Scores. Write a class called TestScores. The class constructor should accept an array of test scores as its argument. The class should have a member function that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an exception. There should be two classes for the exceptions; one should be called NegativeScore and other should be TooLargeScore. These exception classes will have a data member that is an integer value called score. This data member will be set in the constructor via the parameter. It should also provide a member function called getScore which returns score data member. The function in TestScores called getAverages will calculate the average (as a double) of the test scores in the array. It will also check if the score is negative or greater than 100. If it is negative it should throw an exception using the NegativeScore class. If the score is greater than 100 it should throw an excpetion using the TooLargeScore class. Main will create the instance of the TestScores class and catch the exceptions. So it needs to handle both exceptions and display the error message with the score that is invalid.

Explanation / Answer

#include<iostream>


class TestScores
{

public:
        
   int * state;  
   TestScores(int *arr)     
   {

        state = new int[25];
            
       for(int i=0;i<64;++i)
                 
       state[i] = arr[i];

   }
          

void negativeScore(int score)
          
{
              
   if(score<0)
              
   {
             

       std::cout<<score<<" TestScore is less Than 0.";
              
   }
          
}
          
void TooLargeScore(int score)

{
              
if(score>100)
              
{
                  

   std::cout<<score<<" TestScore is more Than 100.";
              
}
          
}
          
void getAverages()
    

{
              
double average=0;
              
int iloop;
          
try {
                  
   for(iloop=0;iloop<25;iloop++)
                  
   {
                      
       if(state[iloop]<0)
                    

       negativeScore(state[iloop]);//throw the negative score exception

       else if(state[iloop]>100)
                      
       TooLargeScore(state[iloop]);
//throw Toolargescore exception                      
       else
                      

       average=average+state[iloop];
                  
   }
                  
              
}catch (const char* msg) {}
              
average=average/25;
              
std::cout<<"Average is "<<average;//prints the Average
          
}
          
int getScore(int n)//returns the Score
          
{
              
return state[n];
          
}

};//End of class TestScores

int main(void)

{
  
   int arr[25]={1,2,56,34,34,32,12,54,65,76,78,98,54,101,-12,23,54,54,54,56,7,8,9,10,45};
  
   TestScores t(arr);
  
   t.getAverages();

}//End of main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote