Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Code Responsibly-- How Can I Properly Validate nput? heck all input: Below is a partial list of some checks to include: . Type check input
Code Responsibly-- How Can I Properly Validate nput? heck all input: Below is a partial list of some checks to include: . Type check input should be checked to ensure it is the datatype expected, e.g., age must be integer . Length check: variables are checked to ensure they are the appropriate length, for example, a US telephone number has 10 digits. Range check-numbers checked to ensure they are within a range of possible values, for example, the value for month should lie between 1 and 12 Reasonable check: values are checked for their reasonableness, e.g. (age> 16) && (age 100) Divide by Zero: variables are checked for values that might cause problems such as division by zero. .Format check - Checks that the data is in a specified format (template), e.g, dates have to be in the format DD/MM/YYYY Input checking can be difficult. Checking a telephone number may require consideration of the many differing telephone formats used by countries around the world. Recover Appropriately A robust program will respond to invalid input in a manner that is appropriate correct, and secure. When your program runs across invalid input, it should recover as much as possible and then repeat the request, or otherwise continue on. Arbitrary decisions such as truncating or otherwise reformatting data to "make it fit" should be avoided. The following method shows input validation to check range and/or reasonableness: in ValidNum(int min, ?nt max) int value; sin value; while ((value max)) cout
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started