Nov 6, 2019 09:22 PM
(This post was last modified: Nov 6, 2019 09:24 PM by Racken.)
In this exercise, you’ll create a form that accepts one or more scores from the user. Each time a score is added, the score total, score count, and average score are calculated and displayed.
1. Start a new project named ScoreCalculator.
2. Add labels, text boxes, and buttons to the default form and set the properties of the form and its controls so they appear as shown above. When the user presses the Enter key, the Click event of the Add button should fire. When the user presses the Esc key, the Click event of the Exit button should fire.
3. Declare two class variables to store the score total and the score count.
4. Create an event handler for the Click event of the Add button. This event handler should get the score the user enters, calculate and display the score total, score count, and average score, and move the focus to the Score text box. It should provide for integer entries, but you can assume that the user will enter valid integer values.
5. Create an event handler for the Click event of the Clear Scores button. This event handler should set the two class variables to zero, clear the text boxes on the form, and move the focus to the Score text box.
6. Create an event handler for the Click event of the Exit button that closes the form.
7. Test the application to be sure it works correctly.
As an additional challenge...
1. Declare a class variable for an array that can hold up to 20 scores.
2. Modify the Click event handler for the Add button so it adds the score that’s entered by the user to the next element in the array. To do that, you can use the score count variable to refer to the element.
3. Move the Clear Scores button as shown above. Then, modify the Click event handler for this button so it removes any scores that have been added to the array. The easiest way to do that is to create a new array and assign it to the array variable.
4. Add a Display Scores button that sorts the scores in the array, displays the scores in a dialog box, and moves the focus to the Score text box. Be sure that only the elements that contain scores are displayed.
5. Test the application to be sure it works correctly.
1. Start a new project named ScoreCalculator.
2. Add labels, text boxes, and buttons to the default form and set the properties of the form and its controls so they appear as shown above. When the user presses the Enter key, the Click event of the Add button should fire. When the user presses the Esc key, the Click event of the Exit button should fire.
3. Declare two class variables to store the score total and the score count.
4. Create an event handler for the Click event of the Add button. This event handler should get the score the user enters, calculate and display the score total, score count, and average score, and move the focus to the Score text box. It should provide for integer entries, but you can assume that the user will enter valid integer values.
5. Create an event handler for the Click event of the Clear Scores button. This event handler should set the two class variables to zero, clear the text boxes on the form, and move the focus to the Score text box.
6. Create an event handler for the Click event of the Exit button that closes the form.
7. Test the application to be sure it works correctly.
As an additional challenge...
1. Declare a class variable for an array that can hold up to 20 scores.
2. Modify the Click event handler for the Add button so it adds the score that’s entered by the user to the next element in the array. To do that, you can use the score count variable to refer to the element.
3. Move the Clear Scores button as shown above. Then, modify the Click event handler for this button so it removes any scores that have been added to the array. The easiest way to do that is to create a new array and assign it to the array variable.
4. Add a Display Scores button that sorts the scores in the array, displays the scores in a dialog box, and moves the focus to the Score text box. Be sure that only the elements that contain scores are displayed.
5. Test the application to be sure it works correctly.
It's only after we've lost everything that we're free to do anything.


