Week 5 solution

1. If the user is typing data into a TextBox and types an invalid character, which of the followingactions would be inappropriate for the program to take? a. Change the TextBox’s background color to indicate the error. b. Silently discard the character. c. Display an asterisk next to the TextBox to indicate the error. d. Display a message box telling the user that there is an error. As displaying a message box, is an interactive way to inform the user that he/she has input invalid character so option d is the best action to take. Rest of the options are non-interactive ways. 2. If the user types an invalid value into a TextBox and moves focus to another TextBox, which of the following actions would be inappropriate for the program to take? a. Force focus back into the TextBox that contains the error. b. Change the first TextBox’s background color to indicate the error. c. Change the first TextBox’s font to indicate the error. d. Display an asterisk next to the first TextBox to indicate the error. If we change the background color of TextBox (option b), or we change the font of TextBox (option c), or display an asterisk (option d), in all the cases user will be able to input value in the next TextBox without correcting invalid input. Only option a forces user to input correct value otherwise user will not be able to proceed. So option a is the answer. 3. If the user enters some invalid data on a form and then clicks the form’s Accept button, which of the following actions would be appropriate for the program take? a. Change the background color of TextBoxes containing invalid values to indicate the errors. b. Display a message box telling the user that there is an error. c. Do not close the form until the user corrects all the errors. d. All the above. Changing the background color of Texbox indicates the location of error, message indicates that what is the error and till the user don’t input correct values, form should not be closed. So all the actions should be performed for correct input from the user, hence option d is the correct answer. 4. Which of the following methods returns true if a regular expression matches a string? a. Regex.Matches b. Regex.IsMatch c. Regexp.Matches d. String.Matches Regex.Matches searches an input string for all occurrences of a regular expression and returns all the matches. Regex.IsMatch indicates whether the regular expression finds a match in the input string. Regexp is not a class. String class don’t have a method Matches. So option d is the correct answer. 5. Which of the following regular expressions matches the Social Security number format ###-##-#### where # is any digit? a. ^###-##-####$ b. ^\d3-\d2-\d4$ c. ^\d{3}-\d{2}-\d{4}$ d. ^[0-9]3-[0-9]2-[0-9]4$ The number of occurrence is defined in {} in regular expressions so option c is the correct answer. 6. Which of the following regular expressions matches a username that must include between 6 and 16 letters, numbers, and underscores? a. ^[a-zA-Z0-9_]?{6}$ b. ^[a-zA-Z0-9_]{6,16}$ c. ^[A-Z0-9a-z_]?$ d. ^\w{16}?$ Option a allows only length of 6 for username. Option c allows only single character length. Option d defines maximum limit of 16 only but not defines minimum limit of 6. Option d also not allows underscore. Only option b defines minimum and maximum limit of 6 and 16 and allows letters, numbers and underscore. Hence option b is the answer.
Powered by