CSCI 689 Computer Assignment 2 Perfect Numbers

$30.00

Category: Tags: , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

Greek mathematicians took a special interest in numbers that are equal to the sum of
their proper divisors, which is simply any divisor less than the number itself. They
called such numbers perfect numbers. For example, is a perfect number because it
is the sum of and which are integers less than that divide evenly into
Similarly, is a perfect number because it is sum of and
Write a predicate function that takes an unsigned integer and returns true if
is perfect, and false otherwise. Test your implementation by writing a main program in
C++ that uses the function to check for perfect numbers in the range to
by testing each number in turn. When a perfect number is found, your program displays
it on and also displays its divisors. The first two lines of the output should be
and Your program should find two other perfect numbers
in the range as well.
You can name your source/header files anything you want as far as they have proper
extensions: for source files and for header files. Guard the statements in your
header file using the following format. (This is necessary because you don’t want the
statements in a header file are processed more than once.)
Include all system header files (that you need in your program) in your header files. For
example, to gain access to the library, which defines a set of simple I/O
operations, insert the line in your header files, and at the top of each
source file, insert corresponding header files by the following statement:
Define the constant value as an unsigned integer and put its
definition in the program header file. Also put the prototype of the predicate function
in the header file as well.
Each perfect number should be displayed as where are
the divisors of with . Generate such sequence as a C++ by a function.
To use the in your program, you need to insert the line in your
header file, and to convert each divisor (an integer) to a you can use the conversion
function from the C++ library. You also need to include the prototype of
function in your header file.
To compile your source file and link its object file with the system library routines, you
need to create a Insert the statements in this file in the following format, where
the first line defines a macro that includes several options we use for the C++ compiler,
and in the rest each entry consists of a line containing a colon (the dependency line), and
one/more command lines beginning with a tab. To the left of the colon on the
2
dependency line is a target (an executable file); to the right of the colon are the target’s
prerequisites. For target, you can choose any valid name, and the advantages of using a
will be discussed in class. After creating this file, simply execute the UNIX
command without any arguments.
For a final test of your program, execute it as: When the execution is
successful, you will see the four perfect numbers on your computer screen and the output
will also be stored in the output file You can find the correct output
in file which is in directory: After you are done, you
don’t need the object and executable files any more. To delete them, execute:
Submit your source and header files to your TA by executing: