Computer Science 1107
AN INTRODUCTION TO FORTRAN PROGRAMMING FOR SCIENTISTS AND ENGINEERS

Fall 2001

Programming Assignment 5
Due date: Wednesday, October 10, 2001



Objective: To further explore writing FORTRAN 77 programs using repetitive execution.

A. Modified Text Problem 15, page 191.

Use a DO-loop in a FORTRAN program which reads two integer values, N and MAX, for input and then prints a list of all integers from 1 to MAX which are multiples of N as well as a final count of the number of multiples which exist.

For example if N = 2 and MAX = 7, then your program will output something that looks like:

MULTIPLES
=========
  2
  4
  6
There are   3 multiples of   2 less than or equal to   7.

  1. Your first idea of an algorithm might be to use a selective statement inside of the DO-loop to test each number from 1 to MAX, but this would be a very poor way to accomplish the task. A better method would first determine the number of multiples which exist and use this to accomplish the task without selection inside the loop. Create such an algorithm.

  2. Create a hand-drawn flow chart for the program using the appropriately shapes boxes for start-stop, Input/Output, and computation as discussed in class OR write out the algorithm for the entire program using pseudocode which should be written out by hand, not typed.

  3. Write the FORTRAN program, naming the source code file lab5a.f and including an explicit list of all Input and Output variables as well as a short description of the problem in a documentation section using comment lines at the beginning of the program. Be careful to choose the types of your variables appropriately and to include the names and student numbers of all authors in the documentation section.

  4. Run the program with sufficiently many carefully selected sets of input to demonstrate the correctness of your algorithm. (This will take several runs, so credit will be assigned for thoughtful testing.)

  5. Display your results in a single table with a single header followed by a single sentence.

  6. Check your results by hand before creating your script file.

  7. Write a paragraph describing why you believe that your algorithm is more better than one which uses selection inside the loop and when you believe this would make a difference to a user.

    B. Modified Text Problem 31, page 229.

    Write a FORTRAN program to accomplish the task described in Problem 31 on page 229 of the text. Output your minimum value in an appropriate sentence.
    1. Use a PARAMETER statement to hold the 100.0 and 6.0 values needed in the program.

    2. Create a hand-drawn flow chart for the program using the appropriately shapes boxes for start-stop, Input/Output, and computation as discussed in class OR write out the algorithm for the entire program using pseudocode which should be written out by hand, not typed.

    3. Write the FORTRAN program, naming the source code file lab5b.f and including an explicit list of all Input and Output variables as well as a short description of the problem in a documentation section using comment lines at the beginning of the program. Be careful to choose the types of your variables appropriately and to include the names and student numbers of all authors in the documentation section.

    4. Display your results in a single sentence.

    5. Check your results before creating your script file.

    6. In a paragraph explain how you know that you have found an appropriate minimum and give bounds on this minimum value in order to describe the accuracy of your answer. Then hand in the following for each of your two programs:
      • The flow chart OR the pseudocode listing.
      • A script file containing all of the following:
        • A printout of the source program obtained by using the UNIX cat command
        • A compilation of the program obtained by using the f77 command
        • Results of execution the program with the given data sets obtained by using a.out
      • The required paragraph.


      Recall: For this and all programming assignments you should follow good software engineering principles including documenting your program with comments and using meaningful names for variables. Failure to do this will lead to reduced credit.

      For this and subsequent assignments, you have the option of working in teams of two people. In this case, turn in one copy of your results with both names and student numbers included on every page of every item submitted.



      Course Policies Tentative Schedule Help and References
      Assignments Grades and Announcements Home