Computer Science 2611
Spring 2000
Laboratory Assignment 3

Handed out: June 26.

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. Don't 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.