Question
Visual Basic 2022 Construct a Sorter that can display 8 numbers in a list box which are input through the display. The list array is
Visual Basic 2022
Construct a Sorter that can display 8 numbers in a list box which are input through the display. The list array is constructed to handle up to 15 numbers. The person enters the numbers one at a time in the display and clicks ENTER to add the number to the end of the list. If the person wants to sort the numbers, the SORT key must be clicked. If the person wants to sum the current numbers in the list, the SUM key is clicked. If the person enters more than 15 numbers, an error message is displayed.
Clear Display Clears only the number just entered in the display.
Clear All Clears all values in the array and is ready to start a new list to sort.
Enter Moves the number from the DISPLAY to the List.
Sort Sorts the Current List.
Sum Sums the values in the Current List.
Sorting Use DO LOOPs or FORs to sort the numbers, NOT a Property or Function.
Display |
Clear Display |
Clear ALL |
Enter |
Sort |
Sum |
3 4 9
List of Numbers (Sorted when Sort Key clicked) |
SUM |
16 |
Sorting Numbers
Sorting 5 Numbers
Create an array to store the list of 5 numbers, call it ALIST.
Enter your numbers into the ALIST.
The ALIST may not use all 5 locations, therefore you must keep track of the number of entries.
Sort (in Ascending Order) using the following steps:Compare the first two entries: ALIST (1) and ALIST (2).
If ALIST(1) <= ALIST(2), no change in list. Go to (b).
If ALIST(1) > ALIST(2). Swap values using SWAP below.
Compare ALIST (1) and ALIST (3).
If ALIST(1) <= ALIST(3), no change in list. Go to (c).
If ALIST(1) > ALIST(3). Swap values using SWAP below.
Continue comparing ALIST(1) to all the values in ALIST.
When you finish comparing ALIST(1) to all values (swapping if the number is smaller), then ALIST(1) contains the smallest value in the list.
Repeat the above sequence for ALIST (2), steps a, b, and c.
Repeat the above process for ALIST(3), etc. for all values in ALIST.
SWAP: Remember that when you code A=B , that the value of B is written in A destroying what was in A.
Since the value of A is lost when written over,
you must store it somewhere, say TEMP.
Move ALIST(1) to TEMP. TEMP=ALIST(1)
Move smaller value to ALIST(1). ALIST(1)=ALIST(2)
Move the larger value to ALIST(2). ALIST(2)=TEMP
Use two loops with the ALIST subscripts changing to sequentially sort the numbers.
|
Values in the ALIST TEMP
|
|
|
|
ALIST(1)
|
|
|
ALIST(2)
|
ALIST(3)
|
ALIST(4)
|
ALIST(5)
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