Chapter 9 DESIGN OF PROGRAMS
STEP-BY-STEP REFINEMENT Most of the examples of programming so far have been short examples. Nevertheless we have emphasized some of the aspects of good programming. These were: 1. choosing meaningful words as identifiers,
January February March April May June July August September October November December
31 29 31 30 31 30 31 31 30 31 30 31
19 18 20 19 20 20 22 22 22 22 21 21
Capricorn Aquarius Pisces Aries Taurus Gemini Cancer Leo Virgo Libra Scorpio Sagittarius
March 20, 2013
subroutine checkValue (day, month, year, d, m, y, ok)
day, month, year
d, m, y
i, j, s2n_
Implementation of checkValue along with isDigits and s2n_.
ok = isDigit
Write a Fortran program that keeps reading integers from the user until a negative number
(acting as a sentinel) is entered. These numbers represent the marks that a group of students
obtained on a test.
The program must output the number of students who
February 27, 2013
real sum, term, x
print*, "Enter x."
Google: "Taylor Series" (see Wikipedia entry)
Consider the following series:
e x 1 x
x 2 x3
March 6, 2013
Given an array of integers, remove duplicate values but leave
remaining unique values in increasing order.
subroutine removeDups (n, m, ar)
Given an array of integers, remove duplicate values.
March 4, 2013
integer fcn, a, b, c, d, e
a = 5
b = 10
c = 15
d = 2
e = a + fcn(b,c)*2
print*, a + fcn(b,c)*2
Program Building Blocks
- main program
- subprograms: 1)
February 4, 2013
Write a program to input a sequence of real numbers and compute the
Write a program to input a sequence of positive real numbers and
compute the average.
January 28, 2013
1. while loop
do while (condition)
2. loop with exit
if (condition) exit
3. counted do loop
do variable = start, finish [,increment]
January 16, 2013
Arithmetic Expressions in Fortran
- Convert two-dimensional mathematical notation to
one-dimensional computer notation
variable = expression
b b 2 4ac
i = 1
i = i + 1
January 7, 2013
Computer-based problem solving in Science and
Why learn Computer Programming?
why learn to play a musical instrument vs. playing a CD or ipod?
why learn to cook vs. eating at a restaurant?
why learn to sew
WHAT ARE COMPUTERS?
Computers are devices consisting of electric circuits with
electronic elements that act as switches and gates in the circuits.
When computers were first built starting about 1945 the electronic
elements were vacu
We have said that computers can handle character information
as well as perform numerical calculations. But most of the
emphasis so far, except for labeling our tables of numerical output,
has had very little to do with
INPUT AND OUTPUT
So far we have had one statement for input, the read statement,
and one statement for output, the print statement.
statements were list-directed, or format-free, read and print
statements. These allowed us to
In this chapter we will introduce the idea of subprograms. The
purpose of having subsidiary programs or subprograms is so that a
larger program can be divided into parts. In this way we can divide
and conquer a complicated problem.
Most of the examples of programming so far have been short
examples. Nevertheless we have emphasized some of the aspects
of good programming. These were:
1. choosing meaningful words as identifiers,
So far in our programming, each memory location for data had
its own special name; each variable had a unique identifier. In this
chapter we will introduce the idea that groups of data will share a
common name and be differentiated from e
In the last chapter we introduced the two kinds of statements
that cause an alteration from the linear flow of control in a program.
One type caused looping, the counted loop or the conditional loop;
the other caused s
A computer is a complex object composed of wires, silicon chips
with electronic circuits on them, and so on, but we will not be trying
to follow circuit diagrams and worrying about how to build a
computer. What we will
In this chapter we will introduce the minimum number of
elements of programming that you need in order to begin to
program. Nothing very important will be programmed but you will
be able to go through the motions of writing a
In order to read numerical information into the computer, to
perform arithmetic calculations on the numbers you read in, and to
output the answers we must look at the concepts of: variable, data
type, declaration, a
In all programs we have examined so far the statements were
executed in sequence until the stop was reached, at which time the
program execution was terminated. In this chapter we will learn
two ways in which the sequence of s
January 21, 2013
Question: Validate and handle linear case
You can measure a programmer's perspective by noting his (or her)
attitude to the continuing vitality of FORTRAN
It is easier to write an incorrect program tha
January 14, 2013
Chapter 3 and 4 of the textbook.
the game of "musical buckets"
Prerequisite for success in Computer Programming:
Donald Knuth (perhaps the world's foremost Computer Scientist) put it
best in a keynote address f
January 21, 2013
Cascaded if-then-else (special variation of if-then-else)
if (condition #1) then
statements alternative #1
else if (condition #2) then
statements alternative #2
else if (condition #n) then
statements alternative #n
CSE 1540.03 January 4, 2012
Why learn Computer Programming?
why learn to play a musical instrument vs. playing a CD or ipod? why learn to cook vs. eating at a restaurant? why learn to sew vs. buying clothes?
Computer-based problem solving in Sci
Chapter 8 ARRAYS
So far in our programming, each memory location for data had its own special name; each variable had a unique identifier. In this chapter we will introduce the idea that groups of data will share a common name and be differentiated from e