Week 5 Discussion Problems

Week 5 Discussion Problems - Week 5 D iscussion P roblems...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Week 5 Discussion Problems (User-Interface Validation) For the following questions, model the solutions in pseudo code and a flowchart. These problems are based on this week’s Lecture. Example 1: Validating Numeric Input Write a program that calculates total daycare costs. Assume you have a form with a textbox, a button, and a listbox on it. The textbox is named txtNumChildren and should receive the number of children a person has. When the user presses the button, the program gets the number of children from the user. If the textbox is empty or does not have a numerical value, the program displays an error message to the listbox. If the textbox has valid data, the program multiplies the number of children by 200 and displays the total to the listbox. Example 1 Solution: Start Declare Variables Boolean formsivalid=true numeric numchildren numeric totaldaycare If num children textbox contents are not numeric then formisvalid=false display error message End if If formisvalid=true then totaldaycare= numchildren*200 display totaldaycare endif ( Note: You could also solve this problem using a double-alternative if-structure, and forgo using the formisvalid Boolean altogether. However for user-interfaces with many different
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
textboxes requiring all different kinds of validation, using the formisvalid Boolean is a good idea, so we used it in this example) Matched Problems 1. Create a sales tax calculator. Assume you have a form with a textbox called txtSubtotal, a button, and a listbox . This textbox accepts a value which indicates the subtotal of an order. When the user presses a button, the program gets the value in the textbox and checks if it’s numeric. If not, it sends an error message to the user. If the textbox contains valid data, the program multiplies the subtotal by .06 to arrive at the tax, and displays it to the listbox. 2. Create a the logic of the button_click even that average grades. Assume your form has two textboxes called txtGrade1 and txtGrade2. The program also has a button and a listbox. When the user presses the button, the program does a check. It checks if both textboxes contain numeric data. If not, the program displays error messages to the user. If the entire form’s textboxes are valid, the program uses an AverageGrades method of a GradeAverager class to average the grades. The class diagram looks like this: GradeAverage
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

Week 5 Discussion Problems - Week 5 D iscussion P roblems...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online