Computer Science 2611
Summer 2002
Laboratory Assignment 4

Handed out: 5/24/02

Assignment 1 describes perfect numbers. Modify your solution to assignment 1 as follows.

  1. Create a function called isPerfect that takes a number n and tells whether n is perfect. It should return 1 if n is perfect, and 0 if n is not perfect. It should begin like this.

         bool isPerfect(int n)
    

    Include a clear and concise contract for function isPerfect. Write the contract before you write the function.

  2. Make the main program read a number n and print the first n perfect numbers. Be sure to use function isPerfect to ask whether a number is perfect. Just use a loop, and count how many numbers have been printed.

Test your solution. Do not try to print more than the first four perfect numbers, since the fifth one is quite large.

Turn in a printed copy of your program. Be sure that your name and the assignment number are in comments at the top of the program. Also, be sure to include a comment near the top of the program telling what the program does. Consult the checklist.