CIS-2730 Homework #1: Divisors

Due: Wednesday, January 21, 2015

  1. Read Chapter 2 in the text. You can skip or skim the material on floating point types and generics. We will spend a couple of weeks on the material in this chapter so don't feel like you have to read it all this week.

  2. First open a Git bash shell and use cd to change to your cis-2730 repository. Issue the commands

              $ git checkout master
              $ git pull
          

    This ensures you are on the master branch and then pulls any updates into your repository.

  3. Next create a branch for the assignment.

              $ git branch hw01
              $ git checkout hw01
          

    Note that you are branching from master because the master branch is current at the time you are doing this.

  4. Add the following declaration to the specification of package Number_Theory that I developed in class.

            procedure Print_Divisors(Number : in Positive);
          

    This procedure is to print all the divisors of the given number. For example, if given a number 12 it should print 1, 2, 3, 4, 6, 12. You can produce the output in whatever format you like (it need not be exactly as I show above).

  5. Implement procedure Print_Divisors in the body of package Number_Theory. The implementation starts like the declaration except it has the word "is" and the "begin... end" pair. You can use the other subprograms in that package as a guide. They also demonstrate the syntax of the various control structures.

  6. Here is a main program that uses this procedure. You can use this program to test your work. Modify the file main.adb.

            with Ada.Text_IO;
            with Ada.Integer_Text_IO;
            with Number_Theory;
    
            use Ada.Text_IO;
            use Ada.Integer_Text_IO;
    
            procedure Divisors is
               Value : Positive;
            begin
               Put("Enter a positive number: ");
               Get(Value);
               Number_Theory.Print_Divisors(Value);
            end Divisors;
          
  7. When you are done with your work don't forget to commit it to your branch:

              $ git commit -a -m "Implemented Print_Divisors"
          

Zip together the specification and body of your package Number_Theory and submit that to Moodle. I don't need the test program. It would be helpful to me if you named the zip file using the first letter of your first name followed by your last name. For example: pchapin.zip (except use your own name). This is not an absolute requirement but it makes things a little quicker for me.


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