T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 18 Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.

Slides:



Advertisements
Similar presentations
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 13 – Salary Survey Application: Introducing.
Advertisements

Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Microsoft Visual Basic: Reloaded Chapter Six Repeating Program Instructions.
Programming with Microsoft Visual Basic 2005, Third Edition
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
Chapter 18 Introducing 2 dimensional arrays Using radio buttons Revisit student grades application Problem definition.
 Pearson Education, Inc. All rights reserved Arrays.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Flag Quiz Application Introducing One-Dimensional Arrays and ComboBox es.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 16.1 Test-Driving the Flag Quiz Application.
IE 212: Computational Methods for Industrial Engineering
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Shipping Hub Application Introducing Generic Collections, LINQ, For Each...Next.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Chapter 8 Arrays Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhancing the Wage Calculator Application Introducing Function Procedures and.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Wage Calculator Application.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Fund Raiser Application Introducing Scope, Pass-by-Reference and Option Strict.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Wage Calculator Application: Introducing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 8 Dental Payment Application Introducing CheckBox es and Message Dialogs.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Ticket Information Application Introducing Sequential-Access Files.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 5 Completing the Inventory Application Introducing Programming.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
Tutorial 6 The Repetition Structure
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Security Panel Application Introducing the Select Case Multiple-Selection Statement.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Screen Scraping Application Introducing String Processing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Microwave Oven Application Building Your Own Classes and Objects.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Shipping Hub Application.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 4 Designing the Inventory Application Introducing TextBox es and Button s.
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 7 Wage Calculator Application Introducing Algorithms, Pseudocode and Program Control.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 11.1 Test-Driving the Interest Calculator Application 11.2 Essentials of Counter-Controlled Repetition.
 2005 Pearson Education, Inc. All rights reserved Arrays.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
14 Shipping Time App Using Dates and Timers
Tutorial 10 – Class Average Application Introducing the Do…Loop While and Do…Loop Until Repetition Statements Outline Test-Driving the Class Average.
Visual Basic 2010 How to Program
CHAPTER FIVE Decision Structures.
CHAPTER FIVE Decision Structures.
Tutorial 12 – Security Panel Application Introducing the Select Case Multiple-Selection Statement Outline Test-Driving the Security Panel Application.
Chapter 3: Introduction to Problem Solving and Control Statements
CIS 16 Application Development Programming with Visual Basic
Presentation transcript:

T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton s

 2009 Pearson Education, Inc. All rights reserved. 2 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

 2009 Pearson Education, Inc. All rights reserved. 3 In this tutorial you will learn: ■Understand the similarities and differences between one-dimensional and two-dimensional arrays. ■Declare and manipulate two-dimensional arrays. ■Understand how to use two-dimensional arrays. ■Use nested For...Next loops. ■Use RadioButton s to enable users to select exactly one option out of several. Objectives

Application Requirements  2009 Pearson Education, Inc. All rights reserved Test-Driving the Student Grades Application A teacher issues three tests to a class of 10 students. The grades on these tests are integers in the range from 0 to 100. The teacher has asked you to develop an application to keep track of each student’s average and the class average. The teacher has also asked that there be a choice to view the grades as either number or letter grades. The application should allow a user to input the student’s three test grades, then compute each student’s average and the class average.

 2009 Pearson Education, Inc. All rights reserved. 5 Test-Driving the Student Grades Application ■Run the completed application (Fig. 18.1). Figure 18.1 | Running the completed Student Grades application.

 2009 Pearson Education, Inc. All rights reserved. 6 Test-Driving the Student Grades Application (Cont.) Figure 18.2 | Inputting data to the Student Grades application. ■Enter numbers in the Test 1 :, Test 2 : and Test 3: TextBox es (Fig. 18.2).

 2009 Pearson Education, Inc. All rights reserved. 7 Test-Driving the Student Grades Application (Cont.) ■Click the Submit Grades Button to calculate the student’s average (Fig. 18.3). Figure 18.3 | Displaying the student’s numerical grade. Numeric RadioButton selected by default

 2009 Pearson Education, Inc. All rights reserved. 8 Test-Driving the Student Grades Application (Cont.) ■Once 10 students have been entered, all the controls in the Input Grades GroupBox are disabled (Fig. 18.4). Figure 18.4 | Input Grades GroupBox disabled after 10 students. Input Grades GroupBox disabled ListBox with numeric grades displayed Label with numeric class average displayed

 2009 Pearson Education, Inc. All rights reserved. 9 Test-Driving the Student Grades Application (Cont.) ■Change the ListBox ’s data to letter grades (Fig. 18.5). Figure 18.5 | Displaying the students’ letter grades. Select the Letter RadioButton ListBox with letter grades displayed Label with letter class average displayed

 2009 Pearson Education, Inc. All rights reserved. 10 ■Two-dimensional arrays require two indices to identify particular elements, in the form array(i, j). –Rectangular arrays are often used to represent tables of values arranged in rows and columns. ■Figure 18.6 illustrates a two-dimensional rectangular array Two-Dimensional Rectangular Arrays Figure 18.6 | Two-dimensional rectangular array with three rows and four columns.

 2009 Pearson Education, Inc. All rights reserved. 11 ■Two-dimensional arrays are initialized much like one- dimensional arrays: Dim numbers As Integer(,) = New Integer(0 To 1, 0 To 1) {} numbers(0, 0) = 1 numbers(0, 1) = 2 numbers(1, 0) = 3 numbers(1, 1) = 4 ■Note that a comma (, ) is required inside the parentheses following the data type to indicate that the array is two-dimensional. ■You can also write the declaration as: Dim numbers(0 To 1, 0 To 1) As Integer 18.2 Two-Dimensional Rectangular Arrays (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 12 ■Two-dimensional arrays also may be initialized using an initializer list: Dim numbers As Integer(,) = New Integer(,) {{1, 2}, {3, 4}} ■The preceding declaration can also be written as Dim numbers As Integer(,) = {{1, 2}, {3, 4}} ■You can specify the lower bounds of an array implicitly: Dim numbers As Integer(,) = New Integer(1, 1) {} Dim numbers(1, 1) As Integer 18.2 Two-Dimensional Rectangular Arrays (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 13 ■A RadioButton is a small white circle that either is blank or contains a smaller dot. –When a RadioButton is selected, a dot appears in the circle. – RadioButton s represent a set of mutually exclusive options—only one can be selected at a time. –By default, all RadioButton s added directly to a Form or GroupBox become part of the same group. ■If the RadioButton is checked, the Checked property returns the Boolean value True Using RadioButton s

 2009 Pearson Education, Inc. All rights reserved. 14 When the user clicks the Submit Grades Button: Retrieve the student’s grades from the TextBoxes Add the student’s test scores to the array Display the student’s test scores and average in the ListBox Display the class’s average in the Class average: Label Clear the student’s test scores from the TextBoxes If 10 students have been entered Disable the input controls When the user selects the Numeric RadioButton: Display each student’s numeric test scores and average in the ListBox Display the class’s numeric average in the Class average: Label When the user selects the Letter RadioButton: Display each student’s letter test scores and average in the ListBox Display the class’s letter average in the Class average: Label 18.3 Using RadioButton s (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 15 Figure 18.7 | ACE table for the Student Grades application. (Part 1 of 2.) ■Use an ACE table to convert the pseudocode into Visual Basic (Figure 18.7). Action/Control/Event (ACE) Table for the Student Grades Application

 2009 Pearson Education, Inc. All rights reserved. 16 Figure 18.7 | ACE table for the Student Grades application. (Part 2 of 2.) Action/Control/Event (ACE) Table for the Student Grades Application (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 17 ■Select the View GroupBox on the template application’s Form, and add two RadioButton s. ■Name the left one numericRadioButton, and set its Text property to Numeric. Name the right one letterRadioButton, and set its Text property to Letter. ■Set the Checked property of numericRadioButton to True (Fig. 18.8). Adding RadioButton s to the View GroupBox Figure 18.8 | RadioButton s placed in the GroupBox.

 2009 Pearson Education, Inc. All rights reserved. 18 GUI Design Tip Use RadioButton s when the user must choose only one option from a group.

 2009 Pearson Education, Inc. All rights reserved. 19 GUI Design Tip Always place each group of RadioButton s in a separate container (such as a GroupBox ).

 2009 Pearson Education, Inc. All rights reserved. 20 GUI Design Tip Align groups of RadioButton s either horizontally or vertically.

 2009 Pearson Education, Inc. All rights reserved. 21 Good Programming Practice Append the RadioButton suffix to RadioButton control names.

 2009 Pearson Education, Inc. All rights reserved. 22 Error-Prevention Tip To avoid subtle logic errors, one RadioButton in a group is often selected by default, by setting its Checked property to True. This can be done using code or by setting the value using the Properties window.

 2009 Pearson Education, Inc. All rights reserved. 23 Declaring a Two-Dimensional Array ■Line 2 (Fig. 18.9) declares a 10-by-3 array of Integer s to contain the test scores. ■Each row in the array represents a student. Each column represents a test. Figure 18.9 | Declaring a two-dimensional array.

 2009 Pearson Education, Inc. All rights reserved. 24 Finishing the Submit Grades Butto n’s Click Event Handler ■Double click the Submit Grades Button to display its Click event handler (Fig ). Figure | Storing the student’s test scores. Store the student’s test scores in the array

 2009 Pearson Education, Inc. All rights reserved. 25 ■The For...Next statement (Fig ) reviews each of the student’s test scores. ■Retrieve the highest index of the array’s second dimension, indicated by passing 1 as the argument to GetUpperBound. Finishing the Submit Grades Butto n’s Click Event Handler (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 26 Finishing the Submit Grades Butto n’s Click Event Handler (Cont.) Figure | Displaying the output. Iterating over the student’s test scores Determining how to display the test scores Calling the LetterGrade method Displaying the student’s average Update the number of students Displaying the class average

 2009 Pearson Education, Inc. All rights reserved. 27 ■If grades array is full, line 51 (Fig ) disables the Input Grades GroupBox. –Disabling a GroupBox disables all the controls it contains. ■The Length property of a two-dimensional array would return the total number of elements (rows times columns). Finishing the Submit Grades Butto n’s Click Event Handler (Cont.) Figure | Application does not allow more than 10 data entries. Disable the input controls when the grades array is full

 2009 Pearson Education, Inc. All rights reserved. 28 ■The For...Next statement (Fig ) sums the grades contained in the specified student row of the grades array. ■The format control string "{0:F}" formats the test average with exactly two digits following the decimal point. Coding Methods to Average Test Grades

 2009 Pearson Education, Inc. All rights reserved. 29 Figure | Calculating a student’s test average. Calculate the student’s test average Coding Methods to Average Test Grades (Cont.) Sum the student’s test grades

 2009 Pearson Education, Inc. All rights reserved. 30 ■The CalculateStudentAverage method (Fig ) uses nested For...Next statements to iterate over the columns in each row. Figure | Calculating the class’s test average. Coding Methods to Average Test Grades (Cont.) Outer For...Next statement iterates over each row Inner For...Next statement iterates over each column Calculate the class’s test average

 2009 Pearson Education, Inc. All rights reserved. 31 ■Double click the Numeric RadioButton to generate its CheckedChanged event handler (Fig ). Figure | Method numericRadioButton_CheckedChanged. Coding Event Handlers for the RadioButton s Displaying the class’s grades

 2009 Pearson Education, Inc. All rights reserved. 32 ■Double click the Letter RadioButton to generate its event handler (Fig ). Figure | Method letterRadioButton_CheckedChanged. Coding Event Handlers for the RadioButton s (Cont.) Displaying the class’s grades

 2009 Pearson Education, Inc. All rights reserved. 33 ■Method DisplayClassGrades (Fig ) displays each student’s grades and test average, as well as the class average, in the format selected by the user. Coding Event Handlers for the RadioButton s (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 34 Figure | Method DisplayClassGrades. Coding Event Handlers for the RadioButton s (Cont.) Displaying the class’s average Inner For...Next statement adds the grades in each column of the current row to the output String Outer For...Next statement iterates over each row of the array

 2009 Pearson Education, Inc. All rights reserved. 35 ■Figure presents the source code for the Student Grades application. Outline (1 of 11 ) Creating a two- dimensional array Assigning values to elements of a two- dimensional array

 2009 Pearson Education, Inc. All rights reserved. 36 Outline (2 of 11 ) Using the Checked property of a RadioButton control Calling the LetterGrade method with an element of a two-dimensional array Accessing an element of a two-dimensional array Iterating over the columns in a row of a two-dimensional array

 2009 Pearson Education, Inc. All rights reserved. 37 Outline (3 of 11 ) Determining the number of rows in a two-dimensional array Disabling all the controls in a GroupBox

 2009 Pearson Education, Inc. All rights reserved. 38 Outline (4 of 11 ) Iterating over the columns in a row of a two- dimensional array Using the Checked property of a RadioButton control Calculating the student’s average and formatting it as a number with two digits after the decimal point

 2009 Pearson Education, Inc. All rights reserved. 39 Outline (5 of 11 ) Using nested For... Next statements to iterate over the columns in each row of a two-dimensional array

 2009 Pearson Education, Inc. All rights reserved. 40 Outline (6 of 11 ) Using the Checked property of a RadioButton control Calculating the class’s average and formatting it as a number with two digits after the decimal point

 2009 Pearson Education, Inc. All rights reserved. 41 Outline (7 of 11 )

 2009 Pearson Education, Inc. All rights reserved. 42 Outline (8 of 11 ) Handling the CheckedChanged event of a RadioButton control

 2009 Pearson Education, Inc. All rights reserved. 43 Outline (9 of 11 )

 2009 Pearson Education, Inc. All rights reserved. 44 Outline (10 of 11 ) Outer For...Next statement iterates over the rows of a two- dimensional array Inner For...Next statement iterates over the columns of a row in a two-dimensional array Using the control variable’s name to improve readability of nested For...Next statements

 2009 Pearson Education, Inc. All rights reserved. 45 Outline (11 of 11 ) Using the control variable’s name to improve readability of nested For...Next statements