A perfect number is an integer p>1 such that the sum of the positive divisors of
ID: 3620697 • Letter: A
Question
A perfect number is an integer p>1 such that the sum of the positive divisors of p equals p. For example, 6 is a perfect number since 1+2+3 = 6; 28 is a perfect number since 1+2+4+7+14 = 28.Write a complete C++ program to write to the file perfect.out all perfect numbers between 1 and a specied named integer constant LIMIT. For the purposes
of the assignment, set the value of LIMIT to 10000.
The program is to define and use the following two functions:
int sum_of_positive_divisors(int number)
that calculates and returns the sum of all positive divisors of the integer argument number; candidate divisors of number range from 1 to number / 2. sum_of_positive_divisors() will only be called by is_perfect().
bool is_perfect(int number)
is a predicate (a boolean-valued function) that returns true iff the integer argument number is a perfect number and false otherwise. is_perfect() will call
sum_of_positive_divisors(); is_perfect() will only be called by main().
Explanation / Answer
Dear.. ##include #include #include using namespace std; const int LIMIT = 10000; int sum_of_positive_divisors(int number){ int possible_divisor = 0, sum_of_positive_divisors = 0; while (numberRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.