CIS-3012 Homework #1: Basic Concepts

Due: Wednesday, January 25, 2017

Read Chapter 2 in the text, but especially focus on Sections 2.3 (Compound Types) and 2.4 (const Qualifier). Read LESSON #3 in my C++ tutorial that covers the basics of IOStreams. You may also find LESSON #2 on references and const a useful supplement to the text.

  1. Write a C++ function called find_proper_divisors with the following declaration:

      void find_proper_divisors( unsigned long long &number, vector<unsigned long long> &divisors );
    

    The function takes a number and replaces the elements of the given vector with all of that number's proper divisors. A proper divisor of a number n, is an integer less than n that divides n evenly. For example if given the number 12, find_proper_divisors should append 1, 2, 3, 4, and 6 to divisors (use the push_back method in vector). If the given number is less than 2, ignore it. Erase divisors in that case.

  2. Write a C++ function called is_perfect with the following declaration:

      bool is_perfect( unsigned long long number );
    

    The function returns true if the given number is a perfect number and false otherwise. By definition, a perfect number is a number that is equal to the sum of its proper divisors.

  3. Write a main program that prints all perfect numbers that exist between 1 and 10,000. You can check your work against the information in the Wikipedia article linked above.

  4. Can either (or both) of the parameters to find_proper_divisors be made references to const? If so, make that change; if not add a comment explaining why not.

Submit a single file, say Hw01.cpp, containing your final program. Be sure you include your name at the top of the file. I recommend (but do not require) you follow the style guide for your submissions. In any case, use a reasonable and consistent style. Be sure your submission can be compiled and tested; I will try it.


Last Revised: 2017-01-10
© Copyright 2017 by Peter C. Chapin <PChapin@vtc.vsc.edu>