## Homework 2, due September 18, 2008.

Due Thursday, September 18, 2008.
goodwine
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

### Homework 2, due September 18, 2008.

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.
I provide the answer for question 1 as an illustration.
1. 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
2. What happens when a real number is divided by an integer?
3. What happens when an integer is divided by a real number?
4. Do the same results hold for the previous three questions if the computations are done with variables instead of numbers? For example

Code: Select all

integer x,y
print *, 'x/y =', x/y
Instead of using the code written right above this, write a program that demonstrates all three and correctly uses implicit data typing.
5. Repeat the previous problem, but put IMPLICIT NONE as the first statement and properly declare all the variables.
6. 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

Code: Select all

variable1=3.0
variable2=2.0
do what you expect?
7. 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?
8. Can you compile a program with a variable that starts with a symbol such as "@"?
9. Print out or copy the following arithmetic expressions.

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)
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.
Individual Problems:
1. 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.
2. 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.
mnguye10

### Re: Homework 2, due September 18, 2008.

On problem 9 in your third assignment of x, your sample code has unbalanced parenthesis. Where should the parenthesis close?
goodwine
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

### Re: Homework 2, due September 18, 2008.

mnguye10 wrote:On problem 9 in your third assignment of x, your sample code has unbalanced parenthesis. Where should the parenthesis close?
Bill Goodwine, 376 Fitzpatrick
eguilbea

### Re: Homework 2, due September 18, 2008.

Does the first individual problem need to work for lines with a slope that is undefined?
goodwine
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

### Re: Homework 2, due September 18, 2008.

eguilbea wrote:Does the first individual problem need to work for lines with a slope that is undefined?
No, you may exclude that case if you want.
Bill Goodwine, 376 Fitzpatrick
enoel

### Re: Homework 2, due September 18, 2008.

Homeworktwo.f by Eras Noel III is attached. To run the program you will have to uncomment each problem individually.
Sincerely,
Eras Noel III
You do not have the required permissions to view the files attached to this post.
bdentino

### Re: Homework 2, due September 18, 2008.

Brian Dentino - Individual Problem 2
You do not have the required permissions to view the files attached to this post.