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.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 12RQ
icon
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.
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.
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to Template
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,