Question
C# using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace ScoreCalculator { public partial class
C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace ScoreCalculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int total = 0; int count = 0; int[] scoresArray = new int[20]; private void btnExit_Click(object sender, EventArgs e) { this.Close(); } private void btnAdd_Click(object sender, EventArgs e) { try { if (IsValidData()) { int score = Convert.ToInt32(txtScore.Text); scoresArray[count] = score; total += score; count += 1; int average = total / count; txtScoreTotal.Text = total.ToString(); txtScoreCount.Text = count.ToString(); txtAverage.Text = average.ToString(); txtScore.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.Message + " " + ex.GetType().ToString() + " " + ex.StackTrace, "Exception"); } } private void btnDisplay_Click(object sender, EventArgs e) { Array.Sort(scoresArray); string scoresString = ""; foreach (int i in scoresArray) if (i != 0) { scoresString += i.ToString() + " "; } MessageBox.Show(scoresString, "Sorted Scores"); txtScore.Focus(); } private void btnClear_Click(object sender, EventArgs e) { total = 0; txtScore.Text = ""; txtScoreTotal.Text = ""; txtScoreCount.Text = ""; txtAverage.Text = ""; txtScore.Focus(); scoresArray = new int[20]; } public bool IsValidData() { return // Validate the Score text box IsPresent(txtScore, "Score") && IsInt32(txtScore, "Score") && IsWithinRange(txtScore, "Score", 01, 100); } public bool IsPresent(TextBox textBox, string name) { if (textBox.Text == "") { MessageBox.Show(name + " is a required field.", "Entry Error"); textBox.Focus(); return false; } return true; } public bool IsInt32(TextBox textBox, string name) { int number = 0; if (Int32.TryParse(textBox.Text, out number)) { return true; } else { MessageBox.Show(name + " must be a valid integer.", "Entry Error"); textBox.Focus(); return false; } } public bool IsWithinRange(TextBox textBox, string name, decimal min, decimal max) { decimal number = Convert.ToDecimal(textBox.Text); if (number max) { MessageBox.Show(name + " must be between " + min + " and " + max + ".", "Entry Error"); textBox.Focus(); return false; } return true; } } }
Extra 8-2 Display a test scores list In this exercise, you'll modify the Score Calculator form of extra exercise 8-1 so the scores are stored in a list instead of an array. X Score Calculator Sorted Scores Score 981 Add 472 89 Score total: Score count: 5 Average: 94 98 Display Scores Clear Scores Exit OK 1. Open the ScoreCalculator project in the Extra Exercises Chapter 08\ScoreCalculator With List directory. 2. Replace the declaration for the array variable with a declaration for a ListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started