Specification
Create a prototype program which gives information about tax rebates.
Your program will ask for the names and incomes of 6 people.
If a person’s income is less than £18000 then they will be due a tax rebate.
The user should input the name and income of six people. Income should be validated to ensure it is greater than 0.
The program will store all names and incomes and whether or not they qualify for a rebate.
The program should output:
- all of the names and incomes
- the total number of people who qualify for the rebate.
Designing the code
- DECLARE names AS ARRAY OF STRING INITIALLY []
- DECLARE income AS ARRAY OF INTEGER INITIALLY []
- DECLARE rebate AS ARRAY OF BOOLEAN INITIALLY []
- DECLARE rebate_count AS INTEGER INITIALLY 0
- FOR person FROM 0 TO 5 DO
- RECEIVE names [person] FROM KEYBOARD
- RECEIVE income [person] FROM KEYBOARD
- WHILE income [person] <=0 DO
- SEND “Please enter an income larger than 0” TO DISPLAY
- RECEIVE income [person] FROM KEYBOARD
- END WHILE
- IF income [person] < 18000 THEN
- SET rebate [person] TO TRUE
- SET rebate_count TO rebate_count + 1
- ELSE
- SET rebate [person] TO FALSE
- END IF
- END FOR
- FOR person FROM 0 TO 5 DO
- SEND names [person] TO DISPLAY
- SEND income [person] TO DISPLAY
- END FOR
- SEND rebate_count & “ people qualified for the rebate.” TO DISPLAY
Designing the user interface
This is where a lovely wireframe will go. But I haven't scanned it in yet.
VB code - solution
This solution assumes the form contains a listbox (called lstOutput):
Dim names (5) As String
Dim income (5) As Integer
Dim rebate (5) As Boolean
Dim rebate_count As Integer
For person = 0 To 5
name (person) = InputBox("Please enter your name")
income (person) = InputBox("Please enter your income")
Do While income (person) <=0
income (person) = InputBox (“Please enter an income larger than 0”)
Loop
If income (person) < 18000 Then
rebate (person) = True
rebate_count = rebate_count + 1
Else
rebate (person) = False
End If
Next
For person = 0 To 5
LstOutput.Items.Add name (person)
LstOutput.Items.Add income (person)
Next
LstOutput.Items.Add rebate_count & “ people qualified for the rebate.”
Testing
Testing the input validation of income
Type of data | Income | Expected result | Actual result |
Normal | 15000 | Input accepted and program continues | As expected |
Normal | 7500 | Input accepted and program continues | As expected |
Extreme | 1 | Input accepted and program continues | As expected |
Exceptional | 0 | Prompted to re-enter income - "Please enter an income larger than 0" | As expected |
Exceptional | -40000 | Prompted to re-enter income - "Please enter an income larger than 0" | As expected |
Exceptional | Omelette | Prompted to re-enter income - "Please enter an income larger than 0" | Program crashed as it expected an integer. I may try to fix this to make the program more robust. |
Evaluation
Fitness for purpose
My testing demonstrates that my program meets the requirements of the specification and is therefore fit for purpose. It asks for the names of 6 people and stores them in an array. It also asks for their incomes and stores them in another array. The user can not input an income of 0 or less - they will be asked to re-enter. It works out if anyone is due a rebate based on their income being less than £18000. At the end the program displays all of the names and incomes which were input. It also displays the number of people who qualified for a rebate.
Robustness
My program is not particularly robust. If the user inputs any non-numerical value then it crashes. I think I could fix this using the IsNumeric function. However, it does ensure that only positive values can be input.
Efficiency
I think my program is quite efficient in its use of data structures - I have used arrays where appropriate, rather than lots of variables. This meant I was able to use a loop to traverse the arrays. If I had used variables then I wouldn't have been able to use a loop which would have resulted in more code.
Readability
I have used meaningful variable and array names so that their purpose is clear. I have used indentation and white space to help the various control structures or segments of code stand out. However, I have not put any internal commentary in - this would have improved readability massively and make it much easier to work out what the program is doing.