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

I would like a C++ program in visual studio that does the following; Test Scores

ID: 667704 • Letter: I

Question

I would like a C++ program in visual studio that does the following;

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

import java.lang.IllegalArgumentException;
//declare and initialize public class TestScores
public class TestScores
{
double average;                            
double[] scoresAR;                       
/* Constructor* @xyz double[] scores*/
public TestScores(double[] scores)
{
//begin class definition
this.scoresAR = new double[scores.length];
try                                       
{
//begin try statements
for(int i = 0; i < scores.length ; i++)     //for loop will loop according to scores.length
{
this.scoresAR[i] = scores[i];//set this(current object's).scoresAR[i] = scores[i] (i = current loop #)
if((this.scoresAR[i] < 0) || (this.scoresAR[i] > 100 ))
throw new IllegalArgumentException(Double.toString(this.scoresAR[i]));
}
this.calcAverage();//this(current object).calcAverage(); (call the calcAverage method)
}
//defines operations for when an exception is caught
catch(IllegalArgumentException e)
{
System.out.println("The array contains values which are not valid " +//output text to user explaininge.getMessage() + " is less than 0 or greater than 100.");       //that the value is invalid, and displays the value in which it is        
}
//end catch statements                                                                
}
/*** method will calculate the average of the scores*/
void calcAverage()
{                                                   //begin definition of private method: calcAverage()
int count = 0; //declare and initialize int count as 0
double sum = 0;//declare and intiialize double sum as 0
//loop amount according to scoresAR.length
for(int i = 0; i < this.scoresAR.length; i++)
{                                  //begin loop statement
sum = sum + this.scoresAR[i];//set sum to sum + this(current object).scoresAR[i](current number in array spot i)
count++;//increment count +1
}
this.average = sum / count;   //set this(current object).average to sum divided by count
}
/*** accessor method for average* @return double average;*/
public double getAverage()
{                          //begin definition of getAverage() public method
return this.average;//return this(current object's).average;
}                            //end definition of getAverage() public method
}                            //end of TestScores class1