Chapter 7: Input Validation

Slides:



Advertisements
Similar presentations
©G. Millbery 2003Data, Information, Knowledge and Processing Slide 1 Validation  Making sure that the data value entered is sensible and reasonable 
Advertisements

Programming Logic and Design Eighth Edition
Commercial Data Processing Lesson 3: Data Validation.
Objectives In this chapter, you will learn about:
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Java Programming Practice.
11.3 Function Prototypes A Function Prototype contains the function’s return type, name and parameter list Writing the function prototype is “declaring”
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 4- 1.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Chapter 4 Making Decisions
1 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and Custom Forms.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Looping Exercises Deciding Which Loop to Use At this.
Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital Media.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
System Development Lifecycle Verification and Validation.
Programming Logic and Design Sixth Edition Chapter 5 Looping.
Making Decisions. 4.1 Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >= Greater than.
Systems Life Cycle. Know the elements of the system that are created Understand the need for thorough testing Be able to describe the different tests.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
Chapter 4 Making Decision Csc 125 C++ programming language Fall 2005.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Chapter Making Decisions 4. Relational Operators 4.1.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 4 Making Decisions.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
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?
Data Validation while loops. Data validation Programs get input data from different sources All data should be ‘validated’ before the program tries to.
Data Validation.
Validation final steps Stopping gaps being entered in an input.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 5 Repetition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
CSC 1010 Programming for All Lecture 4 Loops Some material based on material from Marty Stepp, Instructor, University of Washington.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions 1.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 10 Using Menus and Validating Input.
Input, Output and Processing.. What data needs to be input into the system? Identify the sources – i.e. where does the data come from? What is the volume.
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Validation and verification 1.2
IS1500: Introduction to Web Development
Control Structures II Chapter 3
Chapter 2: Input, Processing, and Output
Topics Introduction to Repetition Structures
Chapter 4: Making Decisions.
Data Validation and Protecting Workbook
Validation Bury College.
Chapter 4: Making Decisions.
Javascript Conditionals.
Topics Introduction to Repetition Structures
Chapter 4: Making Decisions.
Little work is accurate
G063 - Testing.
Patterns to KNOW.
JavaScript Form Validation
Starting Out with Programming Logic & Design
Topics Augmented Assignment Operators Sentinels Input Validation Loops
Looping III (do … while statement)
Using the Target Variable Inside the Loop
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Topics Introduction to Repetition Structures
Chapter 3: Selection Structures: Making Decisions
Validation and Verification
The while Looping Structure
The while Looping Structure
CHAPTER 6 Testing and Debugging.
Presentation transcript:

Chapter 7: Input Validation Starting Out with Programming Logic & Design Second Edition by Tony Gaddis

Chapter Topics 7.1 Garbage In, Garbage Out 7.2 The Input Validation Loop 7.3 Defensive Programming

7.1 Garbage In, Garbage Out If a program reads bad data as input, it will produce bad data as output Programs should be designed to accept only good data Input Validation All input should be inspected before processing If it’s invalid, it should be rejected and the user should be prompted to enter the correct data

7.1 Garbage In, Garbage Out

7.2 The Input Validation Loop Input validation is commonly done with a loop that iterates as long as input is bad Figure 7-1 Logic containing an input validation loop

7.2 The Input Validation Loop Priming read is the first input to be tested // Get a test result Display “Enter a test score.” Input score //Make sure it is not lower than 0. While score < 0 OR score > 100 Display “ERROR: The score cannot be less than 0 ” Display “or greater than 100.” Display “The the correct score.” End While

7.2 The Input Validation Loop Writing Validation Functions For complex validation, it is recommended to write a function. This process can make the code look cleaner Validating String Input Some strings must be validated such as those programs that ask for a specific string input like “yes” Or programs that specify a string to be a specific length like password validation

7.3 Defensive Programming Input validation is defensive programming The practice of anticipating both obvious and unobvious errors that can happen Types of errors to consider Empty input, where a user accidentally hits enter before entering data The user enters the wrong type of data

7.3 Defensive Programming Common errors to be aware of State abbreviations should be 2-character strings Zip codes should be in the proper format of 5 or 9 digits Hourly wages and salary amounts should be numeric values and within ranges Dates should be checked Time measurements should be checked Check for reasonable numbers