© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.

Slides:



Advertisements
Similar presentations
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 16 – Shopping List Application: Introducing.
Advertisements

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Ticket Information Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 12 – Security Panel Application Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 13 – Salary Survey Application: Introducing.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 11 – Fundraiser Application: Introducing Scope.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 16 – Craps Game Application Introducing Random-Number.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
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.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition
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.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
 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.
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.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Wage Calculator Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 27 - Phone Book Application Introducing Multimedia.
6.3 List Boxes and Loops Some Properties, Methods, and Events of List Boxes List Boxes Populated with Strings List Boxes Populated with Numbers Searching.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment 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.
ListBox, ComboBox, Menu Chapter 5.4, ComboBox Control: Properties & Methods u Combines TextBox features with a short drop- down list  cboOne.AddItem(string)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 – Graphical User Interfaces Part 2 Outline.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Ticket Information Application Introducing Sequential-Access Files.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 19.1 Test-Driving the Shipping Hub Application.
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.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Shipping Hub Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Application: Middle Tier Introducing Code-Behind Files, Session State.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 8.1 Test-Driving the Car Payment Calculator.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 15 – Fund Raiser Application Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Enhanced Car Payment.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Unit 6 Repetition Processing Instructor: Brent Presley.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 16 – Craps Game Application Introducing Random-Number.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 11.1 Test-Driving the Interest Calculator Application 11.2 Essentials of Counter-Controlled Repetition.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Dental Payment Application.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Tutorial 10 – Class Average Application Introducing the Do…Loop While and Do…Loop Until Repetition Statements Outline Test-Driving the Class Average.
Tutorial 9 - Car Payment Calculator Application Introducing the while Repetition Statement Outline 9.1 Test-Driving the Car Payment Calculator Application.
Visual Basic 2010 How to Program
Tutorial 12 – Security Panel Application Introducing the Select Case Multiple-Selection Statement Outline Test-Driving the Security Panel Application.
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
CIS16 Application Development and Programming using Visual Basic.net
CIS 16 Application Development Programming with Visual Basic
Presentation transcript:

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional Arrays and ComboBox es Outline 17.1 Test-Driving the Flag Quiz Application 17.2 Introducing Arrays 17.3 Declaring and Allocating Arrays 17.4 Constructing the Flag Quiz Application 17.5 Sorting Arrays 17.6 Wrap-Up

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Objectives In this tutorial, you will learn to: –Create and initialize arrays. –Store information in an array. –Refer to individual elements of an array. –Sort arrays. –Use ComboBox es to display options in a drop-down list. –Determine whether a specific character is in a string. –Remove a character from a string. –Convert a string to lowercase characters.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Flag Quiz Application

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Flag Quiz Application Figure 17.1 Flag Quiz application’s Form. PictureBox displays flag Load the Flag Quiz application –Debug > Start –Note that a different flag from the one in Fig may appear ComboBox contains answers (country names)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Flag Quiz Application Figure 17.2 Selecting an answer from the ComboBox. Answer being selected Scrollbar in ComboBox ’s drop-down list

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Flag Quiz Application Figure 17.3 Submitting the correct answer.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Flag Quiz Application Figure 17.4 Displaying the next flag.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Flag Quiz Application Figure 17.5 Submitting an incorrect answer.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Flag Quiz Application Figure 17.6 Finishing the quiz. Program ends after 5 questions - Buttons and ComboBox will be disabled ComboBox is disabled when the quiz ends

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introducing Arrays Group of memory locations Contain data using same variable name and data type Each value or object stored at a position –Position numbers start at zero Zeroth element is first element –Position also called index or subscript –Index must be zero, a positive int, or an int expression

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introducing Arrays Figure 17.7 Array consisting of 13 elements

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Declaring and Allocating Arrays Figure 17.8 Sum Array application’s Form in design view.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Declaring and Allocating Arrays You must specify the size, name and data type for an array before using Allocating memory for the array –Use new to create the array –Initializer list Specifies initial values of elements

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Declaring and Allocating Arrays Figure 17.9 Declaring an array in the event handler. Creating an array of int s

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Declaring and Allocating Arrays GetUpperBound method –Returns highest index in the array Length property –Returns the length of the array

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Declaring and Allocating Arrays Figure Calculating the sum of the values of an array’s elements. Retrieve the value of each element and add it to the total, one at a time

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Declaring and Allocating Arrays Figure Displaying the sum of the values of an array’s elements.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Declaring the array of country names –Each element is a string containing the name of a country –Compiler allocates the size of the array to hold the number of items in the list

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure string array that stores country names. Creating an array of string s to store country names

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Creating and using a bool array –Game should not display a flag more than once –Random-number generation could cause a flag to be repeated –Use a bool array to keep track of which flags have been displayed

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure bool array that keeps track of displayed flags. Creating an array of bool values with the same number of elements as the array of country names

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Instance variables used in the Flag Quiz application –Counter ( m_intCount ) –string variable to store answer ( m_strCountry )

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Instance variables, used throughout the application. Creating instance variables

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Flag Quiz template application’s Form.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application ComboBox control –A combination of TextBox and ListBox –Allows you to select items from a list and/or enter your own text as input

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application ComboBox properties –DropDownStyle property Determines ComboBox ’s appearance –MaxDropDownItems property Determines how many items can be displayed in the drop- down list

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure ComboBox added to Flag Quiz application’s Form.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Rearranging and commenting the new control declaration.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Displaying items in the ComboBox –DataSource specifies source of ComboBox ’s contents You will use m_StrOptions

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Assigning the string elements of an array to a ComboBox. Specifying the source of the ComboBox items

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Removing whitespace –Method IndexOf Returns index of the specified character in the s tring If character does not appear, returns –1 –Remove method Takes an index and the number of characters to remove as arguments Removes specified number of characters starting at specified index Operates on a copy of the string

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Removing whitespace from the country name. Removing whitespace from country names

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Building a flag-image file’s path name –Use the ToLower method to ensure all letters are lowercase –Append extension to strOutput (.png ) –Add the fully qualified path name Insert adds the CurrentDirectory and “/images/” to the file name

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Building the flag-image file path name. Constructing full path name for flag images Returning full path name of flag images

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Selecting a unique flag to display –Generate a random index between 0 and m_blnUsed.Length –If index has been selected before, value will be true –Repeat above steps until a false value is found

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Generating a unique index. Determining if a country’s flag has been displayed previously

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Returning the index of a value containing false –Set element at selected index of m_blnUsed to true –Return index

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Returning the unique index. Indicating that flag will be used and returning the flag’s index for use

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Choosing a random country name. Getting index of unused flag Retrieving the flag’s corresponding country name

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Displaying a flag –Obtain unique index –Retrieve country name –Build path name –Set PictureBox picFlag ’s Image property to the Image object returned by method Image.FromFile Method

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Displaying a flag image. Getting the path name of the flag and displaying the flag image

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Displaying a flag when the Form is loaded. Displaying a flag when application is first run

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Processing a user’s answer –Determine whether user’s response matches correct answer

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Submit Button Click event handler. Retrieving user’s answer Determining if user’s answer is correct

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Determine whether the quiz is over –If 5 flags have been displayed Disable Button s Display text informing user that the quiz is over –Otherwise continue quiz Disable Submit Button

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Testing whether the quiz is finished. Determining if quiz is over

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Displaying the next flag –Call DisplayFlag to place the next flag in the PictureBox –Clear previous results

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Flag Quiz Application Figure Next Flag Button Click event handler. Displaying the next flag for the user to identify

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Sorting Arrays Sorting the array of country names –Array.Sort method Returns array in ascending alphabetical order

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Sorting Arrays Figure Sorting the array of country names. Alphabetizing country names in the array

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 53 FlagQuiz.cs (1 of 9)

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 54 FlagQuiz.cs (2 of 9) Declaring an creating an array with an initializer list Declaring an array

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 55 FlagQuiz.cs (3 of 9)

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 56 FlagQuiz.cs (4 of 9) Sorting an array Displaying array elements in a ComboBox Creating a bool array with the new operator

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 57 FlagQuiz.cs (5 of 9) Locating a space character in a string Removing a character from a string Converting a string to lowercase Inserting characters into a string

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 58 FlagQuiz.cs (6 of 9) Assigning a value to an array element

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 59 FlagQuiz.cs (7 of 9) Converting the selected value from the ComboBox into a string Retrieving a value from an array

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 60 FlagQuiz.cs (8 of 9) Disabling the ComboBox

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 61 FlagQuiz.cs (9 of 9) Setting the selected ComboBox item