Collaborative Problems:

This homework will ask you to intentionally make a lot of programming mistakes, which will hopefully help you avoid the most common pitfalls. You can combine as many of the questions as possible into single programs, but make sure that whatever you submit addresses each problem. You may exercise your own judgment in this regard, but I would observe that it will usually make it easier for a TA to grade the homeworks if the programs are organized in a manner (with comments) that indicate where exercise is being addressed.

For each question and/or problem, you must both

- write the general answer; and,
- illustrate it in a program.

- What happens in an algebraic computation when the quotient of two integers is computed?
- Answer: the quotient is computed and then truncated and the value returned is an integer.

Part of a complete program that you upload should contain:Code: Select all

`c Problem 1 print *, 'The quotient 10/3 is ', 10/3`

- Answer: the quotient is computed and then truncated and the value returned is an integer.
- What happens when a real number is divided by an integer?
- What happens when an integer is divided by a real number?
- Do the same results hold for the previous three questions if the computations are done with
*variables*instead of*numbers*? For exampleInstead of using the code written right above this, write a program that demonstrates all three and correctly usesCode: Select all

`integer x,y print *, 'x/y =', x/y`

*implicit data typing.* - Repeat the previous problem, but put IMPLICIT NONE as the first statement and properly declare all the variables.
- As pointed out in class, programs with variables with names longer than six characters will compile and run. Can a program distinguish between variables that have more than six characters, e.g., will
do what you expect?
Code: Select all

`variable1=3.0 variable2=2.0`

- What happens when you try to compile a program with variables that are not properly named, e.g., if a variable starts with a number?
- Can you compile a program with a variable that starts with a symbol such as "@"?
- Print out or copy the following arithmetic expressions.
Construct a diagram for each expression like the following figure that indicates the order in which the operations will be performed. Unlike the diagram below, write next to each number that indicates the order in which the computations are performed, what the value is that results from the computation. For example, if A=2, then next to the 2 for the second computation, put a 4.1. Verify the final answer you compute by copying the expressions into a program and printing the answer.
Code: Select all

`x = 16.0**4.0*2.0 x = (2**4/12+3)*(18/(2+4))**5/4 x = 2/3/4/5*4*3*2+4+3+9/(3+5)**2 x = 2+3+4**(5/2+3)`

- Write a FORTRAN program that allows a user to input the x and y values of two points in the plane and the x value for a third point. Have the program compute and then print out to the screen the y value for the third point if it is on the line that connects the first two points.
- Repeat the individual programming problem for the first homework. Fix any mistakes that you may have made (even if they were inconsequential) based on what you have learned from this homework assignment and from reading chapter 2 in the course text.