Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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#image text in transcribed

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 List object, and delete the class variable for the score count. 3. Modify the Click event handler for the Add button so it adds the score that's 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

Write a note on transfer policy.

Answered: 1 week ago

Question

Discuss about training and development in India?

Answered: 1 week ago

Question

Explain the various techniques of training and development.

Answered: 1 week ago

Question

Explain the various techniques of Management Development.

Answered: 1 week ago

Question

=+ a. What happens to the labor demand curve?

Answered: 1 week ago