Class Exercises and Assignments:
Class 2:
- simple.f - the most basic
F77 program possible
- helloworld.f - prints
hello world to the screen
- Assignment: write a program that read in three integers from the keyboard
and the prints them to the screen in a differnt order than how they
were read in. Modify program for real versus integer datat types
Class 3:
Write a program that reads in a temperature in Celsius and converts
it to Fahrenheit, then prints result to the screen. (solution: tempconvert.f)
Write a program that reads in a length in inches and prints out the
same length in centimeters, meters, and miles. (solution: conversion.f)
Class 4:
1. Write a program to read the lengths of the two legs of a right triangle
and to calculate and print the area of the triangle (one-half the product
of the legs) and the length of the hypotenuse (square root of the sum
of the squares of the legs). (solution:
rttriangle.f)
2. Write a program to read values for the three sides a, b, and c of
a triangle and then calculate its perimeter and its area. These should
be printed together with the values of a, b, and c using appropriate labels.
(For the area, you might use Heros formula for the area of a triangle:
(see handout)
where s is one-half the perimeter.).(solution:
regtriangle.f)
3. The minimum velocity V with which a space ship to the moon must be
launched from the earth to escape the earths gravitational field
is called the escape velocity and can be calculated by
(see handout)
where E is the radius of the earth, M is the radius of the moon, D is
the distance between the earth and moon, and g is the acceleration due
to gravity on earth. If there is no attraction of the space ship by the
moon or any other celestial body, the escape velocity is given by
(see handout)
Write a program that reads values for D, E, and M (e.g., D=240000, E=4000,
and M=1000), calculates the escape velocity using each of these two formulas,
and then displays each and the difference between them. (solution:
escape.f)
4. The speed in miles per hour of a satellite moving in a circular orbit
about a celestial body is given approximately by
(see handout)
where C is a constant depending on the celestial body and D is the distance
from the center of the celestial body to the satellite (in miles). Write
a program that reads the value of the constant C for a celestial body
and a value for D and that then displays the speed of the satellite. Run
the program with the following values: (earth) C=1.2E12; (moon) C=1.5E10;
(Mars) C=1.3E11. (solution: satellite.f)
Class 5:
1. Continually prompt for an integer. Stop the prompting if they enter
-99. Once the prompting has stopped, print to screen the largest
and smallest number entered. (solution:
maxmin.f)
2. Compute and print gross pay and net pay given an hourly rate and number
of hours worked. Deduct a tax of 10% if gross salary exceeds $100; otherwise,
deduct no tax.(solution: salary.f)
3. Write a program that reads values for the coefficients A, B, C, D,
E, and F of the equations Ax+By=C and Dx+Ey=F of two straight lines. Then
determine whether the lines are parallel (slopes are equal) or intersect
and, if they intersect, whether the lines are perpendicular (product of
slopes = -1). (solution: twolines.f)
Class 6:
1. List the x,y coordinates in a table for a line defined by:
y=e-x*sin(x)
Have the user define the upper and lower x limits and step size. (solution:
curvepts.f)
2. Integrals - Area under the curve
Compute the area under the curve y=x2+1 for limits defined by user input
(solution: area.f )
3. Write a program that will help you determine the maximum number of
traffic lights that can be purchased for $150,000. Assume that the purchase
cost of each light is $5,000 and the installation cost is $1,000. Each
light uses 420 kW-hrs of electricity a year and kW are charged at $0.047
per kW-hr. Enter a guess as to how many lights can be purchased and keep
rerunning program until the best answer is printed. (solution: lights.f)
Class 7:
1. Update maxmin.f program to use DO WHILEs instead of GOTOs (solution:
maxminwhile.f)
2. Compute average temperature from read in numbers (solution: avetemp.f)
3. Calculate the time it will take for an object to reach the ground
from a given height, h. Give height at each second. Once that distance
is met, print SPLAT!
Use dist = 1/2(g)(t)2 where g=9.80665 m/s (solution: splat.f)
4. Suppose that a ball dropped from a building bounces off the pavement
and that on each bounce it returns to a certain constant percentage of
its previous height. Write a program to read the height from which the
ball was dropped, the percentage rebound, and the number of bounces. Then
for the given number of bounces, print the height of the ball at the top
of each bounce, the distance traveled during that bounce, and the total
distance traveled thus far. The ball is at rest when the height
is less than 1/2 an inch. (solution: bounceball.f)
Class 8:
1. Write a program that creates a multiplication table for numbers 1
through 12.(solution: multtable.f)
2. Write a program that converts a read in temperature in Fahrenheit
to Celcius using a function.(solution: F2Cfunc.f)
3. Write a program that converts a read in month, day, and year and returns
the Julian Day using functions. (solution: mondayconvert.f)
4. Write a program that creates a table of distance in miles and kilometers
for each degree of latitude (-90 to 90) and longitude (0 to 360) from
the point where the Prime Meridian intersects with the Equator. Assume
the earth is a perfect sphere where 1 degree of latitude equals 111km
(69 statue miles).[handout explaining mathematical method -- see me or
website].
(solution: latlon.f)
Class 9:
- Write a program that converts decimal degrees into degrees, minutes
and seconds. (solution: deg2dms.f)
- Write a program to convert polar coordinates (R, THETA) to rectangular
coordinates (X, Y). (solution: pol2rec.f)
- Write a program that has a starting unit table and a resulting unit
table. In the starting unit table, provide an option to quit program.
Based on the selection, either quit or display a table asking them to
choose the conversion unit result (e.g., feet, kilometers, inches, meters,
etc.). Based upon their choices, compute the result. Use subroutines,
functions, IF statements, do whiles. (solution [abridged]:conversion.f)
Class 10:
- Find the cube and square of numbers 1 through 10 and store into separate
arrays (solution: cubesquare.f)
- Read 10 numbers into an array and find the largest and smallest numbers.
Compute the sum of the numbers (solution: array10.f)
- Convert your program that finds the Julian day from the month, day
and year by replacing the Ifs with an array of how many days are in
each month (solution: mondayconvertarray.f)
- Write a program that computes the average and standard deviation of
an inputted list of unknown size (max of 100). The user will say how
many items are in the list and the user will then enter the values.
Modularize your program and use ample comments. (solution: avestdev.f)
Standard deviation = sqrt(sum (difference between value and average
squared) divided by the total number of values minus 1)
- Write a program that sorts of list of numbers (size determined by
user). Use the bubble sort method. (solution: bubbsort.f)
Compute the median. [Helpful website discussing algorithm: http://www.cs.ust.hk/faculty/tcpong/cs102/summer96/aids/bubble.html
or
http://www-ee.eng.hawaii.edu/Courses/EE150/Book/chap10/subsection2.1.2.2.html]
Class 11:
1. Create two 5x3 matrices, A and B. Fill matrix A with number of the
following series: 1, 2, 3, 5, 8, etc. Fill matrix B with the following
series:n+0.3(n*2) starting with 1.
Find the sum of the matrices (solution: matrix.f)
2. Calculate the average amperage of the lightning strike data in /data2/fortran_class/transfer/lightning.sm.txt
(solution: aveamp.f)
3. Using /data2/fortran_class/transfer/drd964x.pdsi.txt (monthly pdsi
data for a particular climate division), find the following: (solution:
pdsi.f)
Worst drought month on average
Worst drought year and month
Worst drought year
4. Using data from /data2/fortran_class/transfer/wx.260203.fwx, answer
the following questions:
What is the average August temperature?
What month has the most precip amount?
Which year was driest?
Class 12:
1. Using data from /data2/fortran_class/transfer/wx.260203.fwx, answer
the following questions:
What is the average August temperature?
What month has the most precip amount?
Which year was driest?
2. The Game of Life
Create a 25x25 grid. Fill the grid with random binary values (e.g., 1
or 0, X or ). Each square has 8 neighbors with
exception to border (which is infertile). Run generations
with following rules:
Birth: Organism will be born in each empty cell that has exactly 3 neighbors
Death: Organism with 4+ neighbors will die from overcrowding. Organism
with fewer than 2 will die of loneliness
Survival: An organism with 2 or 3 neighbors will survive to next generation
|