CSSE 120 -- Intro. to Software Development

Homework 23

  1. Don't forget to refer to the Python vs C comparison document. You may find this helpful as you try to do things in C that you already know how to do in Python. Feel free to suggest things that we might add to this document.
  2. There is no Angel quiz for the next session.
  3. You must do this assignment using Eclipse and the ThatsPerfect project that you checked out from your individual SVN repository in class.

    Be sure to check out that project into your Eclipse C workspace, not your Python workspace.

  4. In the source file perfect.c, edit the initial comment to include your name and today's date.
  5. (10 points) Build and run the program.  Save your answer to this question in the file overflow.txt in the ThatsPerfect project .
    1. What's the largest int produced by doublingInt() before it overflows?
    2. What happens IN PYTHON when an integer value grows too large to be represented by the int type?
    3. Edit the doublingInt() function to count how many times the value 1.0 can be doubled before exceeding the maximum expressible int value (before it overflows)?. How many times can it be?
    4. Comment the call to doublingInt() in function main() and uncomment the call to doublingDouble().  Now edit the doublingDouble() function to count how many times the value 1.0 can be doubled before exceeding the maximum expressible double value. How many times can it be?
    5. commit your solutions to your svn repository with an appropriate commit message.
  6. (5 poins) Now, edit the main() function so that it uses a sentinel while loop, printf(), and scanf() to prompt the user to enter integers. Exit the loop when the user enters a negative number. Otherwise, just print the value the user entered and prompt for another number.

    When you have this part working, commit it to your repository and go on to the next step.

  7. (15 points) A perfect number is one that is the sum of its factors. For example, 6 and 28 are perfect because 1+2+3=6 and 1+2+4+7+14=28. But 24 is not perfect because 1+2+3+4+6+8+12 is not 24.

    Define a function

        int isPerfect(int n)
    

    that returns 1 if n is perfect and 0 if it is not perfect.

    Do not attempt to find a closed-form solution. Instead, actually compute the factors of n and add them together.

  8. (5 points) Change the while loop you created in step 5 so that it prints whether or not the entered number is perfect. A sample run of the program might be:
    	Enter an integer (negative to quit): 6
    	6 is perfect.
    
    	Enter an integer (negative to quit): 24
    	24 is not perfect.
    
    	Enter an integer (negative to quit): 28
    	28 is perfect.
    
    	Enter an integer (negative to quit): -1
    	Goodnight, Gracie.
    

    When you have this part working, commit it to your repository and go on to the next step.

  9. (10 points) The first two perfect numbers are 6 and 28. Modify your program so that after the interactive part, but before exiting, it calculates and prints the fourth perfect number. This number is quite large, so your program might take a while to run.

    When you have this part working, commit it to your repository and enjoy a refreshing beverage.