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

Fall 2001

Programming Assignment 3
Due date: Wednesday, September 26, 2001



Objective: To further explore writing FORTRAN 77 programs using integer and real variables.

A. Text Problem 14, page 109.

The period of a pendulum is given by the formula:

where g = 980 cm per seconds squared, L = pendulum length in cm, and A = the angle of displacement in degrees. Write a program which reads values for L and A and then calculates and displays the period of a pendulum having this length and angle of displacement.

Note that the sine function applied to a variable in FORTRAN is given by SIN(variable).

  1. 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.

  2. Write the FORTRAN program, naming the source code file lab3a.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.

  3. Run your program with the following inputs:
    L (cm) A (degrees)

    120 15
    90 20
    60 5
    74.6 10
    83.6 12

  4. Display your results in a table format which lists the inputs and the output such as:
    LENGTH (cm) ANGLE (degrees)PERIOD (sec)
    =====================================
    120 15 answer

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

    B. Text Problem 18, page 111.

    Castings produced by a certain company must be shipped in special containers which come in four sizes-- huge, large, medium, and small-- which can hold 50, 20, 5, and 1 casting respectively. Write a program that reads the numnber of castings to be shipped and displays the number of containers needed to send the shipment most efficiently.

    The output for an input of 598 should be similar to:
    CONTAINERNUMBER
    ===================
    HUGE 11
    LARGE 2
    MEDIUM 1
    SMALL 3

    1. 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.

    2. Write the FORTRAN program, naming the source code file lab3b.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.

    3. Run the program with the following inputs:
      1. 598
      2. 205
      3. 3
      4. 747
      5. 0

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

      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
      • A brief paragraph discussing your conclusions about the utility of integer vs. real arithmetic in these two FORTRAN programs.


      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