St. Ambrose CSCI 275 - ANSWERS TO REVIEW QUESTIONS - CSCI 275

Unformatted text preview:

ANSWERS TO REVIEW QUESTIONS – Chapter 41. What is the general format of the statement used to code decisions in an application?If (condition) Thenstatement(s)[ElseIf (condition) Thenstatement(s)]statement(s)]2. What is a condition?The test in an If statement is based on a condition. To form conditions, six relational operators, >, <,=, <>, >=, and <=, are used to compare values. The result of the comparison is either True or False.3. Explain the purpose of relational operators and logical operators.Conditions are formed using the six relational operators, >, <, =, <>, >=, and <=. The relationaloperators are used to compare values. Compound conditions test more than one condition. Compoundconditions are created using the logical operators; And, Or, and Not.4. Differentiate between a comparison performed on numeric data and a comparison performedon string data.An algebraic comparison is made when numeric values are involved in a test; that is, the sign of thenumber is taken into account. String variables can be compared to other string variables or stringliterals enclosed in quotation marks. The comparison begins with the leftmost character and proceedsone character at a time from left to right. As soon as a character in one string is not equal to thecorresponding character in the second string, the comparison is terminated, and the string with thelower ranking character is judged less than the other.5. How does Visual Basic compare the Text property of a text box?The Text property of a text box can be compared with numeric variables and constants, string variables andconstants, object properties, and arithmetic expressions. However, it is important to note that comparisonsmust be made on like types; that is, strings can be compared only to other strings, and numeric values canbe compared only to other numeric values, whether a variable, constant, property, or arithmetic expression.You can force a numeric comparison on a Text property by using the CInt or CDec functions.6. Why would it be useful to include the ToUpper method in a comparison?When comparing strings, the case of the characters is important. An uppercase Y is not equal to a lowercasey. Because the user may type a name or word in uppercase, lowercase, or as a combination of cases, wemust check all possibilities. The best way is to use the ToUpper (or ToLower) method of the String class,which will return the uppercase or lowercase equivalent of a string, respectively.7. Name the types of items that can be used in a comparison.The conditions to be tested can be formed with numeric variables and constants, string variables andconstants, object properties, and arithmetic expressions. However, it is important to note that comparisonsmust be made on like types; that is, strings can be compared only to other strings, and numeric values canbe compared only to other numeric values, whether a variable, constant, property, or arithmetic expression.8. Explain a Boolean variable test for True and False. Give an example.Visual Basic evaluates the condition in an If statement. If the condition is a Boolean variable name, it holdsthe values True or False. The default of a Boolean is False.For example:If blnSuccessfulOperation = True ThenIs equivalent toIf blnSuccessfulOperation Then9. Give an example of a situation where nested Ifs would be appropriate.An example where nested Ifs would be appropriate would be where multiple conditions must be tested forinput validation. You might want to make sure that the user has filled in all of the appropriate informationbefore any processing occurs. The following code is an example of nested Ifs for input validation.strName = txtName.TextintHours = CInt(txtHours.Text)decPayRate = CDec(txtPayRate.Text)If strName <> "" Then 'Notice that there is no blank between the quotesIf intHours > 0 ThenIf decPayRate > 0 Then'Write code for programElseMessageBox.Show ("Please enter the pay rate.")EndIfElseMessageBox.Show ("Please enter the number of hours.")EndIfElseMessageBox.Show ("Please enter your name.")EndIf10. Define the term validation. When is it appropriate to do validation?Verifying that appropriate values have been entered for a text box is called validation. Validation mayinclude making sure that data is numeric, checking for specific values, or making sure that required itemsare entered. Validation should be done to check the values entered into text boxes before beginning anycalculations. Validation may also include verifying that the user has selected radio buttons or check boxesif some selection is required.11. Define the term checking a range.Checking a range means checking the reasonableness of a value. For example, you could displahy amessage boxes to the user if they input their age as 200 instead of 20.12. Explain the difference between Step Into and Step Over.The stepping commands, Step Into or Step Over, are set at design time. The program will begin runningand immediately transfer to break time. With each of these commands the project executes a single line at atime and displays the Code window with the current statement highlighted. Most likely you will use theStep Into command more than Step Over. When you choose Step Into (from the menu, the toolbar button,or F11), the next line of code is executed and the program pauses again in break time. If the line of code isacall to another procedure, the first line of code of the other procedure will be displayed. The Step Overcommand also executes one line of code at a time. The difference between Step Over and Step Into occurswhen your code has calls to other procedures. Step Over will not display the code in the called procedure,but only displays the lines of code in the current procedure being analyzed. You can choose Step Over fromthe menu, from the toolbar button, or press F10.13. What steps are necessary to view the current contents of a variable during program execution?The steps for viewing the contents of a variable during run time are1. Break the execution using a breakpoint.2. If the code does not appear in the Editor, click on the editor's tab in the Document window.3. Point to the variable or expression that you wish to view.4. The current contents of the expression will pop up in a label.You can also check the current contents of variables by using the Locals window to display allobjects and variables that are within scope at break time. That means that if you break execution inthe btnCalculate_Click event procedure, all


View Full Document

St. Ambrose CSCI 275 - ANSWERS TO REVIEW QUESTIONS - CSCI 275

Download ANSWERS TO REVIEW QUESTIONS - CSCI 275
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view ANSWERS TO REVIEW QUESTIONS - CSCI 275 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view ANSWERS TO REVIEW QUESTIONS - CSCI 275 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?