10 Chapter 101 Using Menus and Validating Input Programming Logic and Design, Second Edition, Comprehensive 10.

Slides:



Advertisements
Similar presentations
Programming Logic and Design Eighth Edition
Advertisements

CS 275Tidwell Course NotesPage 110 Chapter 7: Getting Input From Users Designing interactive forms, in which the user is expected to supply information.
Programming Logic and Design Sixth Edition
Programming in Visual Basic
Programming Logic and Design, Third Edition Comprehensive
Programming Logic and Design Fourth Edition, Introductory
Objectives In this chapter, you will learn about:
Chapter 9 Describing Process Specifications and Structured Decisions
COMP2001 Testing. Aims of Testing To achieve a correct system producing correct results with a variety of input data.
Writing a Complete Program
Testing an individual module
C++ for Engineers and Scientists Third Edition
Chapter 13: Object-Oriented Programming
Guide To UNIX Using Linux Third Edition
Chapter 14: Event-Driven Programming with Graphical User Interfaces
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
© 2005 by Prentice Hall Chapter 3c Designing Interfaces and Dialogues.
- Meeting 4 – Writing a Complete Program
Fundamentals of Python: From First Programs Through Data Structures
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Visual Basic Chapter 1 Mr. Wangler.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
Fundamentals of Python: First Programs
Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs.
Output and User Interface Design
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Chapter 3 Making Decisions
Data entry: Validation
Checking data Chapter 7 Prepared by:Sir Mazhar Javed.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Programming Logic and Design, Second Edition, Comprehensive
Programming Logic and Design Fifth Edition, Comprehensive
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Indexed and Relative File Processing
Programming Logic and Design Sixth Edition Chapter 5 Looping.
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
Programming with Microsoft Visual Basic th Edition
Chapter 5: Making Decisions
The Software Development Process
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
Verification & Validation. Batch processing In a batch processing system, documents such as sales orders are collected into batches of typically 50 documents.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
Chapter 10: Using Menus and Validating Input Programming Logic and Design, Third Edition Comprehensive.
Chapter 11 Data Validation. Question Should your program assume the data is correct, or should your program edit the data to ensure it is correct?
1 AQA ICT AS Level © Nelson Thornes 2008 Good quality data and information Data terms.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
1 Work Orders. 2 Generating a Work Order There are two methods to generating a Work Order in the WYNNE STSTEM. First method: Option 11 – 12 – 13 * Open.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 10 Using Menus and Validating Input.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Chapter 7: Getting Input From Users
The Selection Structure
Designing and Debugging Batch and Interactive COBOL Programs
Two methods to observe tutorial
Writing a Complete Program
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Programming Logic and Design Fifth Edition, Comprehensive
Chapter 3: Selection Structures: Making Decisions
Chapter 10: Using Menus and Validating Input
CHAPTER 6 ELECTRONIC DATA PROCESSING SYSTEMS
Chapter 4: Writing and Designing a Complete Program
Presentation transcript:

10 Chapter 101 Using Menus and Validating Input Programming Logic and Design, Second Edition, Comprehensive 10

Chapter 102 Objectives After studying Chapter 10, you should be able to: Understand the need for interactive, menu-driven programs Create a program that uses a single-level menu Code modules as black boxes Improve menu programs

10 Chapter 103 Objectives After studying Chapter 10, you should be able to: Use a case structure to manage a menu Create a program that uses a multilevel menu Validate input Understand types of data validation

10 Chapter 104 Using Interactive Programs Programs for which all the data are gathered prior to running use batch processing Programs that depend on user input while they are running use interactive processing Interactive computer programs are often called real- time applications, because they run while a transaction is taking place, not at some later time You can refer to interactive processing as online processing, because the user’s data or requests are gathered during the execution of the program

10 Chapter 105 Using Interactive Programs A batch processing system can be off-line; that is, you can collect data such as time cards or purchase information well ahead of the actual computer processing of the paychecks or bills A menu program is a common type of interactive program in which the user sees a number of options on the screen and can select any one of them

10 Chapter 106 Using a Single-Level Menu The program in Figure 10-1 uses a single-level menu; that is, the user makes a selection from only one menu before using the program for its ultimate purpose— arithmetic practice

10 Chapter 107 Mainline Logic for Arithmetic Drill Menu Program

10 Chapter 108 Using a Single-Level Menu The startUp() module in the arithmetic drill program defines variables and opens files

10 Chapter 109 Using a Single-Level Menu When the looping() module ends, control passes to the main program

10 Chapter 1010 Coding Modules as Black Boxes Programmers often refer to modules such as addition() and subtraction() as existing within a black box meaning that the module statements are “invisible” to the rest of the program When programmers develop systems containing many modules, they often code “empty” black box procedures called stubs Most programming languages provide you with built-in modules or functions, which are subroutines that automatically provide a mathematical value such as a square root, absolute value, or random number

10 Chapter 1011 Coding Modules as Black Boxes You can make many additional improvements to any of the addition() modules shown in Figures 10-7, 10-9, and 10-10

10 Chapter 1012 Making Improvements to a Menu Program The programmer can assist the user by displaying a message when the selected response is not one of the allowable menu options, as shown in Figure 10-11

10 Chapter 1013 Using the Case Structure to Manage a Menu The arithmetic drill program contains just three valid user options: numeric entries that represent Addition, Subtraction, or Quit All menu-driven programs should be user- friendly, meaning that they should make it easy for the user to make desired choices Programmers often overlook the fact that computers recognize uppercase letters as being different from their lowercase counterparts

10 Chapter 1014 Menu Program Using the Case Structure

10 Chapter 1015 Menu Program Using the Case Structure with Multiple Allowed Responses

10 Chapter 1016 Using Multilevel Menus When you need to present the user with a large number of options, you invite several potential problems: –Not all the options will appear on the screen, and the user might not realize that additional options are available –The screen is too crowded to be visually pleasing when you try to force all the options to fit on the screen –Users become confused and frustrated when you present them with too many choices

10 Chapter 1017 Using Multilevel Menus When you have many menu options to present, using a multilevel menu might be more effective than using a single-level menu With a multilevel menu, the selection of a menu option leads to another menu where the user can make further, more refined selections You refer to a menu that controls whether or not the program will continue as the main menu of a program Alternatively, the user can choose to continue the program, selecting an Addition, Subtraction, Multiplication, or Division arithmetic drill

10 Chapter 1018 Using Multilevel Menus No matter which drill the user chooses you can display a second menu like the one shown in Figure A second-level menu is a submenu

10 Chapter 1019 Third Menu for Arithmetic Drill Program

10 Chapter 1020 Using Multilevel Menus You would not need to learn any new techniques to create as many levels of menus as the application warrants The module that controls each new level can: 1.Display a menu 2.Accept a response 3.While the user does not select the quit option for the specific menu level, perform another module based on the selection (or inform the user of an error) 4.Display the menu and accept a response again

10 Chapter 1021 Validating Input The programs you write will be improved if you employ defensive programming, which means trying to prepare for all possible errors before they occur You can circumvent potential problems caused by a user’s invalid data entries by validating the user’s input Validating input involves checking the user’s responses to ensure they fall within acceptable bounds

10 Chapter 1022 Validating Input Alternatively, you can force the invalid data to a default value Forcing a field to a value means you override incorrect data by setting the field to a specific value New programmers often make the following two kinds of mistakes when validating data: –They use incorrect logic to check for valid responses when there is more than one possible correct entry –They fail to account for the user making multiple invalid entries

10 Chapter 1023 Validating Input

10 Chapter 1024 Best Method for Validating User Response

10 Chapter 1025 Understanding Types of Data Validation Some of the techniques you want to master include validating: –Data type –Range –Reasonableness and consistency of data –Presence of data

10 Chapter 1026 Validating a Data Type Some programming languages allow you to check data to make sure they are the correct type

10 Chapter 1027 Validating a Data Range Sometimes a user response or other data must fall within a range of values

10 Chapter 1028 Validating Reasonableness and Consistency of Data Data items can be the correct type and within range, but still be incorrect You have experienced this phenomenon yourself if anyone has ever misspelled your name or over billed you There are many data items that you cannot check for reasonableness; it is just as reasonable that your name is Catherine as it is that your name is Katherine or Kathryn

10 Chapter 1029 Validating Presence of Data Sometimes data are missing from a file, either on purpose or by accident A job applicant might fail to submit an entry for the salaryAtPreviousJob field or a client has no entry for the Address field Good defensive programs try to foresee all possible inconsistencies and errors

10 Chapter 1030 Summary Programs for which all the data are gathered prior to running use batch processing When you create a single-level menu, the user makes a selection from only one menu before using the program for its ultimate purpose When you code a module as a black box, the module statements are invisible to the rest of the program A programmer can improve a menu program and assist the user by displaying a message when the selected response is not one of the allowable menu options

10 Chapter 1031 Summary You can use the case structure to make decisions when you need to test a single variable against several possible values When a program requires more options than can easily fit in one menu, you can use a multilevel menu You can circumvent potential problems caused by a user’s invalid data entries by validating the user’s input Some of the techniques you want to master include: validating data type, range, reasonableness and consistency of data, and presence of data