Assignment 1: Line Drawing in Fortran and COBOL solution

In this assignment, you will implement a program to raster segments of straight lines to output. The program reads a sequence of data points in 2-D space, connects the points one by one with straight lines, and then output the lines. You will write the program once using Fortran and once using COBOL. You also need to submit a simple report (less than one page) to tell us your experience in
using the two languages. The aim of this assignment is to let you have a taste of some old fashioned languages and have an understanding of what problems programmers encountered in the past.
Digital Differential Analyzer (DDA)
The straight line connecting two distinct points 𝑝𝑖 = (π‘₯𝑖, 𝑦𝑗) and 𝑝𝑗 = (π‘₯𝑗, 𝑦𝑗) can be represented using the equation 𝑦 βˆ’ 𝑦𝑖 = π‘š(π‘₯ βˆ’ π‘₯𝑖), where π‘š = π‘¦π‘—βˆ’π‘¦π‘–
π‘₯π‘—βˆ’π‘₯𝑖 is the slope of the line. Suppose 𝑝𝑖 and 𝑝𝑗
contain integer coordinates only, in order to raster the straight line between 𝑝𝑖 and 𝑝𝑗 to a matrix (like a picture of pixels, the console, a text file, etc.), we need to approximate the straight line by interpolating the points between 𝑝𝑖 and 𝑝𝑗 with integer coordinates also. The digital differential analyzer (DDA) is an algorithm for such purpose. It considers two cases depending on the slope π‘š.
Case 1: |π‘š| ≀ 1
Assume without loss of generality that π‘₯𝑖 < π‘₯𝑗. We sample the integer x-coordinates in the interval [π‘₯𝑖, π‘₯𝑗] in steps of 1, that is, π‘₯𝑖, π‘₯𝑖 + 1, π‘₯𝑖 + 2, π‘₯𝑖 + 3, … , π‘₯𝑗. Then, the y-coordinates are interpolated as: (π‘₯𝑖, 𝑦𝑖), (π‘₯𝑖 + 1, π‘Ÿπ‘‘(𝑦𝑖 + π‘š)), (π‘₯𝑖 + 2, π‘Ÿπ‘‘(𝑦𝑖 + 2π‘š)), (π‘₯𝑖 + 3, π‘Ÿπ‘‘(𝑦𝑖 + 3π‘š)), … , (π‘₯𝑗, 𝑦𝑗) , where π‘Ÿπ‘‘(π‘˜) means the round-off of π‘˜ to the nearest integer (四捨五ε…₯; 5 or above is rounded up, 4 or below is truncated).
Case 2: |π‘š| 1
Assume without loss of generality that 𝑦𝑖 < 𝑦𝑗. We sample the integer y-coordinates in the interval [𝑦𝑖, 𝑦𝑗] in steps of 1, that is, 𝑦𝑖, 𝑦𝑖 + 1, 𝑦𝑖 + 2, 𝑦𝑖 + 3, … , 𝑦𝑗. Then, the x-coordinates are interpolated
as: (π‘₯𝑖, 𝑦𝑖), (π‘Ÿπ‘‘(π‘₯𝑖 + 1
π‘š), 𝑦𝑖 + 1), (π‘Ÿπ‘‘(π‘₯𝑖 + 2
π‘š), 𝑦𝑖 + 2), (π‘Ÿπ‘‘(π‘₯𝑖 + 3
π‘š), 𝑦𝑖 + 3), … , (π‘₯𝑗, 𝑦𝑗).
Example 1. Two points (4,2) and (9,6). Slope π‘š = 6βˆ’2
9βˆ’4 = 0.8. (Case 1)
The interpolated points would be (4,2), (5, π‘Ÿπ‘‘(2.8)), (6, π‘Ÿπ‘‘(3.6)), (7, π‘Ÿπ‘‘(4.4)), (8, π‘Ÿπ‘‘(5.2)), (9,6).
That is, (4,2), (5,3), (6,4), (7,4), (8,5), (9,6). The following shows a plot of the points.
6 *
5 *
4 * *
3 *
2 *
y x 4 5 6 7 8 9

Example 2. Two points (7,5) and (6,9). Slope π‘š = 9βˆ’5
6βˆ’7 = βˆ’4. (Case 2)
The interpolated points would be (7,5), (π‘Ÿπ‘‘(6.75), 6), (π‘Ÿπ‘‘(6.5), 7), (π‘Ÿπ‘‘(6.25), 8), (6,9). That is, (7,5), (7,6), (7,7), (6,8), (6,9). The following shows a plot of the points.
9 *
8 *
7 *
6 *
5 *
y x 6 7
Program Specification
You are required to write two programs, one in Fortran (file name dda.for) and the other in COBOL (file name dda.cob). The program flow and other requirements are specified below.
Program Flow
τ€‚Ύ The programs read 𝑛 points 𝑝1, 𝑝2, 𝑝3, … , 𝑝𝑛 from an input file which must be named input.txt.
You can assume that the input file always has the following format:
The first line contains an integer specifying the number of data points. Then in each of the subsequent <n lines, there are two integers <x_i and <y_i, separated by a space character
␣, specifying the x-coordinate and y-coordinate of data point 𝑝𝑖. Besides, all integers in the input file must have a fixed width of 2. The following shows an example input file specifying five data points (3,2), (40,22), (32,5), (28,12), and (0,15):
3 2
40 22
32 5
28 12
0 15
􀂾 You can assume that <n must be at least 2, and all points must have x-coordinates in the range [0,78] and y-coordinates in the range [0,22]. With the standard 2-D coordinate system, i.e., x-axis being the horizontal axis and y-axis being the vertical axis, the origin (0,0) is in the lower left corner.
τ€‚Ύ The programs then use the DDA algorithm to plot 𝑛 βˆ’ 1 lines 𝑝1 ↔ 𝑝2, 𝑝2 ↔ 𝑝3, 𝑝3 ↔ 𝑝4, …, π‘π‘›βˆ’1 ↔ 𝑝𝑛. Your Fortran program should plot the lines to the standard output (console), while your COBOL program should plot the lines to an output file named output.txt.
τ€‚Ύ In the output, you should print out 23 lines, each line of which contains 79 characters. This corresponds to the 2-D plane spanning the space between (0,0) and (78,22). The origin (0,0) is in the lower left corner of your output and is printed as a β€˜+’. The positive x-axis is printed as β€˜-β€˜.

The positive y-axis is printed as β€˜|β€˜. A point which is part of any of the 𝑛 βˆ’ 1 lines is printed as β€˜*’.
A point which is neither a part of any of the 𝑛 βˆ’ 1 lines nor the axes is printed as a space β€˜β£β€˜.
Note that if a β€˜*’ has to be plotted at some point on the axes, then β€˜+’, β€˜-β€˜, or β€˜|’ would not be printed at that point. (That is, β€˜*’ has higher priority than β€˜+’, β€˜-β€˜, and β€˜|’.)
􀂾 The following shows an example output using the five data points (3,2), (40,22), (32,5), (28,12), and (0,15) in the example input file above:
| *
| ***
| ** *
| ** *
| ** *
| ** *
| ** *
***** * *
| ********** ** *
| ********** *
| ** ***** *
| ** * *
| ** * *
| * * *
| ** * *
| ** * *
| ** **
| ** *
| **
| **
| *
Other requirements
􀂾 The only control flow construct that you can use in your programs is IF-GOTO. All other selection and repetition constructs are not allowed (such as DO, WHILE, UNTIL, ELSE, ELSEIF in Fortran and similar constructs in COBOL). The purpose of this restriction is to let you understand the difficulties that programmers encountered in the past.
􀂾 In case of any file opening error, you have to print an error message to standard output (console) and terminate the program.
􀂾 You cannot write your programs in other languages and then initiate system calls or external library calls in Fortran and COBOL.
􀂾 Your program should include suitable comments as documentation. Failure to do so will suffer from mark deduction.
􀂾 You should decompose your programs into subroutines. Do not clog the main programs.
Your written report (report.pdf) should answer the following questions within one A4 page.

1. Compare the conveniences and difficulties in implementing the program in Fortran and COBOL.
You can divide your comparison into specific tasks such as β€œfile I/O”, β€œDDA implementation”, etc.
2. Compare Fortran and COBOL with a modern programming language (e.g., C/C++/Java/…) in different aspects (e.g., data types, parameter passing, paradigm, paradigm, etc.). You are free to pick your favorite modern programming language.
Submission and Marking
􀂾 Your program file names should be dda.for and dda.cob. Name your report as report.pdf.
Powered by