Question
I could really use some help with this problem! The code must be in C# and must be easy to understand as I am a
I could really use some help with this problem!
The code must be in C# and must be easy to understand as I am a beginner.
---------------------------------------------------------------------------------------------------
In this exercise, youll modify the Score Calculator form of the below code so the scores are stored in a list instead of an array.
1.Your exercise name is Assignment6 \Ex2_ScoreCalculator.
2. Replace the declaration for the array variable with a declaration for a List
and delete the class variable for the score count.
3. Modify the Click event handler for the Add button so it adds the score thats entered by the user to the list.
In addition, delete the statement that increments the score count variable you deleted.
Then, declare a local variable to store the count, and assign the Count property of the list to this variable.
4. Modify the Click event handler for the Clear Scores button so it removes any scores that have been added to the list.
5. Modify the Click event handler for the Display Scores button so it sorts the scores in the list and then displays them in a dialog box.
6. Test the application to be sure it works correctly.
----------------------------------------------------------------------------------------
The code that must be modified
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 WindowsFormsApplication12 { public partial class Form1 : Form { int[] arr = new int[20]; int total = 0; int count = 0; int i = 0; public Form1() { InitializeComponent();
} private void Form1_Load(object sender, EventArgs e) {
}
private void label2_Click(object sender, EventArgs e) {
}
private void button1_Click(object sender, EventArgs e) { try { if (IsValidData()) { int score = Convert.ToInt32(txtScore.Text); arr[i] = score; total =total+ arr[i]; count += 1; int average = total / count; txtScoreTotal.Text = total.ToString(); txtScoreCount.Text = count.ToString(); txtAverage.Text = average.ToString(); i++; txtScore.Focus(); } } catch (Exception ex) { MessageBox.Show("Invalid input"); }
}
private void button4_Click(object sender, EventArgs e) { this.Close(); }
private void button3_Click(object sender, EventArgs e) { txtScore.Text = ""; txtScoreTotal.Text = ""; txtScoreCount.Text = ""; txtAverage.Text = ""; txtScore.Focus(); }
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=="" ) { return false; } else return true; } public bool IsInt32(TextBox textBox, string name) { int value; if (int.TryParse(textBox.Text, out value)) { return true; } else return false;
} public bool IsWithinRange(TextBox textBox, string name, decimal min, decimal max) { if (Convert.ToInt32(textBox.Text)>max || Convert.ToInt32(textBox.Text) private void button2_Click(object sender, EventArgs e) { Array.Resize(ref arr, i); string toDisplay = string.Join(Environment.NewLine, arr); MessageBox.Show(toDisplay); } } } ---------------------------------------------------------------------------- Thanks!
Step 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