Download presentation
Presentation is loading. Please wait.
Published byDouglas Owens Modified over 9 years ago
1
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing Two-Dimensional Arrays and RadioButtons Outline 18.1 Test-Driving the Student Grades Application 18.2 Two-Dimensional Rectangular Arrays 18.3 Using RadioButton s 18.4 Inserting Code into the Student Grades Application 18.5 Wrap-Up
2
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Objectives In this tutorial, you will learn to: –Understand the differences between one-dimensional and two-dimensional arrays. –Declare and manipulate two-dimensional arrays. –Understand the usefulness of two-dimensional arrays. –Use RadioButton s to enable users to select exactly one option out of several.
3
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3 18.1 Test-Driving the Student Grades Application
4
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 4 Running the Student Grades application –Open the application and select Debug > Start 18.1 Test-Driving the Student Grades Application
5
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 5 Figure 18.1 Running the completed Student Grades application. 18.1 Test-Driving the Student Grades Application
6
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 6 Figure 18.2 Inputting data to the Student Grades application. 18.1 Test-Driving the Student Grades Application Entering data –Enter “Gretta Green” in Student name: TextBox –Enter 87, 94 and 93 in the Test 1:, Test 2: and Test 3: TextBox es –Click Submit Grades Button
7
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 7 Figure 18.3 Displaying the student’s numerical grade. 18.1 Test-Driving the Student Grades Application The Numeric RadioButton displays the student’s test score average as a number. Numeric RadioButton selected as the default
8
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8 Figure 18.4 Displaying the student’s resulting letter grade. 18.1 Test-Driving the Student Grades Application The Letter RadioButton displays the student’s test score average as a letter (A, B, C, D or F). Select the Letter RadioButton
9
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 9 18.2 Two-Dimensional Rectangular Arrays Two-dimensional arrays –Also called double subscripted –Require two indices to identify particular elements –Often used to arrange tables into rows and columns –m-by-n array has m rows and n columns
10
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 10 Row 0 Row 1 Column 0Column 1Column 2Column 3 Column index (or subscript) Row index (or subscript) Row 2 Array name Figure 18.5 Two-dimensional rectangular array with three rows and four columns. 18.2 Two-Dimensional Rectangular Arrays
11
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 11 18.2 Two-Dimensional Rectangular Arrays Array declaration int[,] intNumbers = new int[ 2, 2 ]; intNumbers[ 0, 0 ] = 1; intNumbers[ 0, 1 ] = 2; intNumbers[ 1, 0 ] = 3; intNumbers[ 1, 1 ] = 4; OR int[,] intNumbers = { { 1, 2 }, { 3, 4 } };
12
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 12 18.3 Using RadioButton s RadioButton s –Black dot appears in circle when selected –State button (on/off) –Usually mutually exclusive options (only one can be selected at a time) –To separate groups of RadioButtons, each group must be placed in separate containers
13
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 13 18.3 Using RadioButton s
14
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 14 18.3 Using RadioButton s
15
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 15 18.3 Using RadioButton s Figure 18.7 RadioButton s placed in the GroupBox. Two mutually exclusive RadioButton s in the View GroupBox
16
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 16 18.4 Inserting Code into the Student Grades Application Figure 18.8 Rearranging and commenting the new control declarations.
17
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 17 18.4 Inserting Code into the Student Grades Application Figure 18.9 Declaring a two-dimensional array. First column of array contains names Second column contains test scores
18
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 18 18.4 Inserting Code into the Student Grades Application Figure 18.10 Storing the student information. Store the student name and test average in the arrays Increment counter
19
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 19 18.4 Inserting Code into the Student Grades Application Figure 18.11 Displaying the output. Checked property of RadioButton s determines which is selected Calling method DisplayNumericGrades Calling method DisplayLetterGrades
20
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 20 18.4 Inserting Code into the Student Grades Application Figure 18.12 Application does not allow more than ten data entries. Disable btnSubmit when 10 grades have been entered
21
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 21 18.3 Using RadioButton s Displaying numeric grades –Clear ListBox –for loop iterates over array Add each student to ListBox –Calculate and display class average
22
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 22 18.4 Inserting Code into the Student Grades Application Figure 18.13 DisplayNumericGrades method code. Displaying the student names and test averages in the ListBox Clearing the ListBox Updating the class total Calculating and displaying the class average
23
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 23 18.3 Using RadioButton s Displaying letter grades –Similar to DisplayNumericGrade method –Includes calls to ConvertToLetterGrade
24
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 24 18.4 Inserting Code into the Student Grades Application Figure 18.14 DisplayLetterGrades method code. Displaying the student names and test averages in the ListBox Clearing the ListBox Updating the class total Calculating and displaying the class average
25
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 25 18.3 Using RadioButton s RadioButton event handlers –Double-click in design view. –Call DisplayNumericGrades and DisplayLetterGrades depending on RadioButton chosen.
26
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26 18.4 Inserting Code into the Student Grades Application Figure 18.15 Method radNumeric_CheckChanged. Calling the DisplayNumericGrades method
27
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 27 18.4 Inserting Code into the Student Grades Application Figure 18.16 Method radLetter_CheckChanged. Calling the DisplayLetterGrades method
28
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 28 StudentGrades.cs (1 of 10)
29
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 29 StudentGrades.cs (2 of 10) RadioButton control
30
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30 StudentGrades.cs (3 of 10) Creating a two-dimensional array
31
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 31 StudentGrades.cs (4 of 10)
32
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 32 StudentGrades.cs (5 of 10)
33
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 33 StudentGrades.cs (6 of 10) Assigning a value to a two- dimensional array Using format control string
34
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 34 StudentGrades.cs (7 of 10)
35
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 35 StudentGrades.cs (8 of 10) Accessing the elements of a two-dimensional array
36
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 36 StudentGrades.cs (9 of 10)
37
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 37 StudentGrades.cs (10 of 10) Creating a RadioButton ’s CheckedChanged event handler
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.