APCO 1P93 Lecture Notes - Lecture 11: Data Validation, Defensive Programming

51 views2 pages

Document Summary

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. Input validation is commonly done with a loop that iterates as long as input is bad. Priming read is the first input to be tested: //make sure it is not lower than 0. While score < 0 or score > 100. Display error: the score cannot be less than 0 . 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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents