CIS 220 - Program 3
Objectives: Gain experience using control structures.Description: This program is intended to provide you with experience using sequence, selection, and iteration. You will use nested if statements as well as nested loops.
A perfect number is a number that equals the sum of its factors, excluding the number itself. For example, 6 is a perfect number because the factors of 6 are 1, 2, 3, and 6. Excluding 6, the factors 1 + 2 + 3 equal 6, making it a perfect number.
Write a program in which the user inputs the number of perfect numbers to calculate, and then will determine that number of perfect numbers, excluding 1. You will have to determine the factors of each number under consideration, and then test them to see if their total equals the number itself.
Use a text box for user input, a command button to initiate program execution, and a list box to display your results. You also need to clear the list box when the command button is pressed in order to clear previous output before a new test.
Your GUI should resemble the following as closely as possible. Be sure that you exclude 1.
Finding more than three perfect numbers can take a long time, because the fourth perfect number is greater than 8000, and the fifth perfect number is greater than 33,550,000. With a simple algorithm like this one, in which every digit is checked to see if it is a factor, it takes a long time to determine the fourth perfect number. The delay between finding the second and third perfect number, while considerably shorter, is still noticeable.
Your program should print a warning message in a message box that it will not calculate more than four perfect numbers and then force the user to re-enter a value.
If the user requests four perfect numbers your program should warn the user that the results may be delayed. (See the demo for sample messages.)
Even with the smaller perfect numbers, unless your program indicates that it is still performing calculations, the user may think that the program has locked up. In order to provide some sign that the program is still executing, use the command Me.Cursor = Cursors.WaitCursor to change the shape of the cursor to an hourglass. When all perfect numbers have been found, reset the mouse pointer to the default with the command Me.Cursor = Cursors.Default. This is an example of how the user interface can be designed to provide information about program status to the user.