Lab 2

Goals

  • define a minimum COBOL program
  • internal documentation
  • write your own simple program (similar to lab1)

Assumptions

  • The user will enter the input data correctly for ALL portions of this lab (The users work in your company's Fantasy Land branch office).

Part A – Minimum COBOL program

Write a COBOL program that displays your name to the terminal monitor. Include only the minimum number of statements possible to compile and run the program successfully, as well as comments in the Identification Division to describe what the program is doing. Name the program lab2a.cob

From now on (for the rest of the programs you write for this class), be sure to include a comment in the Identification Division which includes the author’s name (the person who wrote the program - should be you) and describes the purpose of the program.

All of the answers to the questions given in this lab should be typed into a file called lab2ques.txt. When changes to the program are made for a question, undo the change before proceeding to the next question.

  1. Delete the paragraph name in the Procedure Division and compile/run the program.  What happens?
  2. Delete the STOP RUN statement from the program and compile/run the program.  What happens?  What does the STOP RUN statement do?

Part B – Generic COBOL program

Write a COBOL program that includes all of the division and section information possible in a COBOL program (don’t forget the comments in the identification division!). Include a paragraph name (for the initial paragraph) in the PROCEDURE DIVISION. Name the program genprog.cob. This program can be used as a starting point for all of your other programs for this class.

  1. Does this program still execute (runcbl command) even though there are no statements in the paragraph of the procedure division?
  2. Here is a DISPLAY statement whose string literal will not fit on one line in a COBOL program.  However, the output to the screen should appear all on one line.  Find a solution to this problem.
DISPLAY 'I graduated from Woodrow Wilson High School and Youngstown State University (twice!)'

Part C – Writing your first COBOL program

Write an interactive COBOL program, lab2c.cob, to do the following:

You have just been released from the hospital and need to figure out how you are going to be able to pay the bill. You want to calculate, given a particular monthly payment how many payments will be required to pay off the bill (we are ignoring interest here). Since you're not sure exactly how much you want to pay each month or how long you are willing to take to pay it off, you want to be able to keep the program running with different options until you have all the information you need to make your decision.

Notes:

  • Be sure to indent your COBOL code nicely for readability.
  • If you run into problems, use the DISPLAY statement to debug your program.
  • Remember, if you have a logic error, you must have a program walkthrough before obtaining help on your program.

Here is some pseudo-code that may help you determine how this program can be written.

  1. Input the total bill amount
  2. Input the suggested monthly payment
  3. Calculate the number of months to pay off the bill
    1. total bill amount / suggested monthly payment stored as a real value (has a decimal part)
    2. move the real value into an integer variable name (no decimal part)
  4. Compare the real and integer values
    1. if they are not equal then add 1 to the months to pay off the bill
  5. Output number of months to pay off the bill
  6. Repeat steps 2-5 until the user decides to stop
  7. Output a “program complete” message

Some questions to consider and assumptions you have to make

  1. How large can total bill amount be? (Have prompt indicate allowable size)
  2. How large can the monthly payment be? (Have prompt indicate allowable size) Since we are assuming all input data will be correct for this lab, we can also assume that the monthly payment will not be larger than the total bill amount.
  3. Is there a maximum timeframe (number of monthly payments) that the bill has to be paid by?
  4. Should I be using edited input and/or output?
    • 1 Bonus point for edited input (How? Nose around on our web site)
    • Your prompts have to indicate whether or not you are accepting edited input. For example:
      • For edited input: Enter a monthly bill amount (ZZZZ9.99):
      • For unedited input: Enter a monthly bill amount (9999999):

After you have completed writing the lab2c.cob program, answer the following question:

  1. At the UNIX prompt, type ls lab2*.* What is the result of this command?

Submitting Lab 2

Remember, the general command to submit is submit classname labname list-of-files-to-submit where classname is c314aa or c314ab (depending on which section you are in) and labname is the lab#; in this case lab2. The files to submit are:

  • lab2a.cob
  • genprog.cob
  • lab2c.cob
  • lab2ques.txt - which has the answers to all of the QUESTIONs given above

Deleting Unnecessary Files

As you work you create disk files, most of which do not need to be kept. These unnecessary files occupy disk space and, if not erased, will eventually fill your disk quota. When this happens you can not save any other files, no matter how important they may be.

To help prevent this from occurring, there is a utility called clean in the class directory (/usr/class/cis314/). Copy it in to your home directory using the UNIX cp command (see the tutorial) and run it every so often. Simply type clean at the prompt and press 'Enter'