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

Fall 2001

Programming Assignment 6
Due date: Friday, October 19, 2001



Objective: To explore writing FORTRAN 77 programs using formatted input and output.

A. Addition and Subtraction

Write a FORTRAN program which takes two integers for input, and then finds their sum and their difference, printing the output on the screen as follows (with the right-most digits lined up):
  2001   2001
  +   1234   -   1234
 
 
  3235   767

Note that the input integers can each be positive, zero, or negative, but you may assume that neither input is longer than 4 digits.
  1. Create a hand-drawn flow chart for the program using the appropriately shaped 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 lab6a.f and including an explicit list of all 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 sufficiently many carefully selected sets of input to demonstrate the correctness of your algorithm.

  4. Check your results before creating your script file.

    B. Modified Text Problem 11, page 310.

    In this problem, we will work with a formatted input file. Use your right mouse button to save-link-as Users.dat to your itlabs account. Then use this file in your FORTRAN program with the OPEN, READ, and CLOSE commands discussed in class.

    At the end of each month, a report is produced that shows the status of each user's account in the file Users.dat. This file is formatted in the following way:
    Columns 1-15: User's last name
    Columns 16-30: User's first name
    Columns 31-35: User-ID
    Columns 36-40: Password
    Column 41: Space
    Columns 42-44: Resource limit (in dollars)
    Columns 45-49: Resources used to date (in pennies)

    Write a FORTRAN program to accept the current date from the user at the keyboard and to produce an output report on the screen as below in which the astericks (***) indicate that the user has already used 90% of more of the resources available to him or her that month.

    Your output should be formatted and should look something like:

      User Accounts -- 9/31/2001  
     
      Resource     Resources  
      User-ID  Limit Used



    10101 $750  $380.81
    10102 $650  $598.84***
    .
    .
    .
    1. Create a hand-drawn flow chart for the program using the appropriately shaped 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 lab6b.f and including an explicit list of all 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. Check your results 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 required paragraph which discussed the utility of formatted input and formatted output. Be sure to discuss any reasons that formatting must be used.


      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