CIS221 Assignment #5
Working with Functions and Subroutines:
Factors and Prime Numbers
DueThursday11/18/10 before midnight
DESIRED PROGRAM BEHAVIOR
In this assignment, you are to write a program that behaves as described below. There are five options, as shown in the image below.
When the program first loads, it should look like this:
When the user selects an option from the list, the necessary controls should appear, allowing the user to enter the number(s) and click the button to produce the necessary calculations and responses.
If the user selects the option to determine if one number is a factor of another, the program should display the following:
The user will enter a two numbers. The results should show whether the first is a factor of the second (i.e. number 1 divides evenly into number 2). These two screens show what happens when the button is clicked for a YES and a NO result:
If the user chooses to list the factors of a number, the screen should look like this:
When the user enters a number and clicks the button, the list of factors should display, as shown below:
If the user chooses to determine if a number is prime, the screen should look like this:
Below shows results for a prime number, and for a non-prime number:
If the user chooses to list the primesup to a certain number, the screen should look like this:
When the user enters a number and clicks the button, the list of primes should display, as shown below:
If the user chooses to determine if a number is perfect, the screen should look like this:
Below shows results for a perfect number, and for a non-perfect number:
PROGRAMMING TASKS
You must create three Function Procedures that return Boolean results. One is called isFactor, and takes two integer parameters. The second is called isPrime, taking one integer parameter, and the third is isPerfect, also taking a single integer parameter. These perform the necessary tests on the parameter to make the determination. Here are the rules for deciding:
1)One number is a factor of the second number if the first number divides EVENLY into the second. The Mod operator is useful for this.
2)A number is prime if it has no factors other than itself and 1.
3)A number is perfect if all of its factors (other than itself) SUM to the number itself. For example, the number 6 is a perfect number (1 + 2 + 3). Similarly, 28 is a perfect number (1 + 2 + 4 + 7 + 14). Also, 496 is a perfect number (1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248).
NOTE: These functions must NOT directly read a user input or display anything to the user. All they should do is take one (or two) integers as input parameters and return Boolean values. Your button’s event procedure should call these functions, passing them the necessary arguments, and then display the appropriate results based on the functions’ return values.
In addition to the Functions, your program should also have two Sub Procedures; these are for listing the appropriate results. The Sub Procedures, unlike the functions, can directly display the string, by putting them into the results text box. In the ListFactors sub procedure, you should make use of the isFactor function. In the ListPrimes sub procedure, you should make use of the isPrime function.
So, in summary, you will have three user-defined functions (isFactor, isPrime, and isPerfect), and two user defined sub procedures (ListFactors and ListPrimes).
In addition, you will need one event procedure for the user-selection list box (to clear the form of previous values and to display the appropriate controls), and a second event procedure for the button (to call the functions or subroutines based on the user’s current selection from the list and the number(s) entered by the user.
As always, you need to use good programming practices. Names of controls, variables, and parameters should be meaningful. Comments are required in your code. You must ensure that the user enters legitimate values (Integers only). And, you need your header comments in your code (name, program name, honor code statement).
Deliverables:
You will zip your project folder, and post the zipped file to Blackboard’s digital dropbox by the evening of the due date, before midnight.