Lab Project #6 - Perfect Sums
THE PROBLEM: Design and write a program in C++ that
will solve the perfect sums problem for the values of 1 to 100 inclusive. A number is said to be perfect if the sum of its divisors (except for itself) is equal to
itself. For example, 6 is a perfect
number because the sum of its divisors (1+2+3) is 6. The number 8 is said to be
deficient because the sum of its
divisors (1+2+4) is only 7. The number
12 is said to be abundant because the
sum of its divisors (1+2+3+4+6) is 16.
Write a program that lists all the divisors of the numbers between 1 and
100 and classifies each number as perfect, deficient, or abundant.
Example Output:
Number: Divisors: Classification:
1 () Deficient
2 (1) Deficient
3 (1) Deficient
4 (1+2) Deficient
100 (1+2+4+5+10+20+25+50) Abundant
THE DESIGN: Recall the steps in problem-solving,
go through each one in this project.
Your top-down design should be included as comments at the top of your
source code. The design must be complete. Your design will be compared to your
program.
IMPLEMENTATION: You should use many functions to write
this program. There is no input, only
output. Essentially, you must loop from
1 to 100, calling a function that prints out the divisors of a number, then
adds them up and figures out if the number is deficient, perfect or
abundant. Write a function that handles
one line of the output, given the number to classify. Write a function to print out the list of divisors. Write a function that classifies the number
based on the sum of its divisors. Write
a function to find the next greatest divisor.
Write a function that returns a boolean that tells whether or not a
given value is a divisor of another value.
Other functions are possible as well.
Note: To get full credit, you must format the output as
above. That is, you must make each of
the 100 answers take a single line, and you must get the columns to line up as
they do in the example.
Hint: This problem is a short one, but takes an understanding of
loops and functions, and how to call a function with a loop in it from another
function.