Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a member function that returns the aver- age of the test scores. If any test score in the array is negative or greater than 100, the class should throw an exception. Demonstrate the class in a program.
Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a member function that returns the aver- age of the test scores. If any test score in the array is negative or greater than 100, the class should throw an exception. Demonstrate the class in a program.
Chapter11: Exception Handling
Section: Chapter Questions
Problem 2E
Related questions
Question
See attached images
C++
![7. TestScores Class
Write a class named TestScores. The class constructor should accept an array of test
scores as its argument. The class should have a member function that returns the aver-
age of the test scores. If any test score in the array is negative or greater than 100, the
class should throw an exception. Demonstrate the class in a program.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F88ce7fe7-6055-4d88-a2fe-fb962619b6d1%2Fbb32f989-6700-4267-b014-31a6725722d6%2Fns1wsgr_processed.png&w=3840&q=75)
Transcribed Image Text:7. TestScores Class
Write a class named TestScores. The class constructor should accept an array of test
scores as its argument. The class should have a member function that returns the aver-
age of the test scores. If any test score in the array is negative or greater than 100, the
class should throw an exception. Demonstrate the class in a program.
![For the test score array inside the class you can assume you will pass the TestScores class constructor an array with 10
integers, and that the class's array member has is hardcoded for 10 elements. Recall that to copy an array, you must use a
for loop and copy the elements one at a time from the source to the destination. You’ll have to do this in the constructor.
The constructor is where you should “throw" exceptions, not in the member function that returns the average of the test
scores. By placing the "throw" commands in the constructor you will prevent bad data from being stored in the
constructor. You should check each value in the source array as you copy it into the member array.
For the exceptions use the exception class you built in lab 6.1. Throw different exceptions for less than zero and greater
than 100. You can easily copy the two exception classes from lab 6.1 for this.
Test your class with three test cases:
1. All data is good
2. One element is less than zero
3. One element is greater than 100.
Test by creating a TestScores class object and then:
1. Passing the constructor an array with one value less than zero
2. Passing the constructor an array with one value greater than 100
3. Passing the constructor valid data.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F88ce7fe7-6055-4d88-a2fe-fb962619b6d1%2Fbb32f989-6700-4267-b014-31a6725722d6%2Fi2gipc_processed.png&w=3840&q=75)
Transcribed Image Text:For the test score array inside the class you can assume you will pass the TestScores class constructor an array with 10
integers, and that the class's array member has is hardcoded for 10 elements. Recall that to copy an array, you must use a
for loop and copy the elements one at a time from the source to the destination. You’ll have to do this in the constructor.
The constructor is where you should “throw" exceptions, not in the member function that returns the average of the test
scores. By placing the "throw" commands in the constructor you will prevent bad data from being stored in the
constructor. You should check each value in the source array as you copy it into the member array.
For the exceptions use the exception class you built in lab 6.1. Throw different exceptions for less than zero and greater
than 100. You can easily copy the two exception classes from lab 6.1 for this.
Test your class with three test cases:
1. All data is good
2. One element is less than zero
3. One element is greater than 100.
Test by creating a TestScores class object and then:
1. Passing the constructor an array with one value less than zero
2. Passing the constructor an array with one value greater than 100
3. Passing the constructor valid data.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,