Upload
hortense-george
View
221
Download
0
Embed Size (px)
Citation preview
BIEN 001 Introduction to Biomedical Engineering Methods
Module 1: Introduction to Computers,Flowcharting and Programming in C
Roger H. Johnson, [email protected]
September 5, 2000
Objectives:
• Introduction to Computersand Computing Environment at Marquette.
• Develop problem-solving strategies through flow charting.
• Introduction to program development environment.
• Introduction to C language programming.
• Develop two real C programs and run them.
Lectures 1-2:
• Computing History• Computer Constituents• Evolution of Programming• Essential Programming Steps• Syntax• Develop Two Programs in C
• • Computing History
• Blaise Pascal and the mechanical adderPascal was a French genius and mathematician who died young after religious mania.In 1642 he invented a mechanical calculator to assist in the adding of long columns of numbers in his father’s tax office.His most important writing is Thoughts on Religion.
• Gottfried Wilhelm Leibnitz’ adder/multiplierGerman invention of 1673 (or1694) which used stepped-gear-wheels.
• Joseph Jacquard and his pasteboard loom cards1812: Pasteboard card read by the loom. Hole pattern determined thread combinations.
• Charles Babbage and his analytical engine1830’s: First the Difference Engine, which would have been two tons of brass, steel and pewter clockwork.1840: Then the Analytical Engine which could decide between two courses of action. Steam-engine-powered, would read punched cards, compute, request cards with bell.
• Herman Hollerith and the census device1890: Used punched cards to process census information and speed tabulation.
• Howard Aikens and the Mark I1944: Harvard Mark I. Used mechanical counters and electromagnetic relays to control its operation.
• John Mauchly and John Eckert and the Eniac1946: Huge vacuum-tube computer; part of the war effort. Ballistic computations and code-breaking.
• John Backus and FORTRAN1954: First inovation to translate human-intelligible language into machine language.
• Kernighan and Ritchie and C1970’s: Dominant language in scientific programming today. FORTRAN 77 persists and other language, such as Pascal, Basic, and Cobol are used in niches.
• Computer ConstituentsCPU = central processing unit = control unit + arithmetic and logical unitMemoryInputOutput
CPUArithmetic andlogical unit
Controlunit
MemoryInput Output
Control Unit: Controls timing and directs allcomputer operations.
Arithmetic Logic Unit: Makes all decisionsand performs calculations.
Memory: Stores instructions and data livewithin the computer.
Input: Devices which input information into memory.Output: Devices which print or display data from
memory.
• Evolution of Programming
Machine language: sequence of zero’s and one’s= “binary string”.
(refer to handout on binary number system)
Assembly language: uses keywords to stand forsequences of zero’s and one’s:
“ADD” = 0010001110001111One keyword is one line of code
is one binary string is one instruction.
Compiler level: (“high-level” resembles English)e.g. C = A + B for(i=1;i<5000;i++)
{.....One line of code can contain several words and
require many machine language instructions.
Object oriented: New “pictorial” method wewon’t get into.
• Essential Programming Steps
1) A clear statement of the problem:Decide what it is you really want to do. Helps to
decide if computer is really the way to do it.
2) A rough or general solution algorithm:Write down in brief format the steps required
to solve the problem.
3) A refined algorithm of the solution:More detailed sequence of steps.
4) A flowchart of the full solution process:Draw a block diagram or “flow diagram”
of the computer program.
5) Computer language coding + documentation:A line-by-line written version of computer code.
6) Creation of a computer file of the coding:Type in the code using a text editor.
7) Compile and run the file:Type a command which creates the object fileand the machine language version of code.
8) Obtain sufficient output to test the fullsolution algorithm for generality.
An algorithm is a description of a solution method. Synonyms are “procedure”, “method”, “technique” or “(set of) rule(s)”.
In the programming context, an algorithm must possess these characteristics:
• It must end after a finite number of steps.
• It must be describable by a finite sequence of steps or instructions.
• It must be capable of dealing with all members of a particular class of problem.
A flowchart is a pictorial representation of an algorithm.
Flowcharts are sometimes called “block diagrams” or “flow diagrams”.
A flowchart is a schematic of the logic used in problem solution and, properly used, should aid in the development of a sound logical approach.
A completed flowchart should exactly represent the sequence of steps coded into the program, and can help avoid a number of common programming errors.
Example used in Lab 1:
C program to solve two linear equationswith two unknowns.
Of the several methods to solve this problem,we choose to solve for x and yby the use of determinants.
e.g.
x + 2y = 55x - y = 3
x
5 2
3 11 2
5 1
5 6
1 10
11
111
y
1 5
5 31 2
5 1
3 25 1 10
22 11
2
For the general case:
Ax + By = CDx + Ey = F
x
C B
F EA B
D E
CE BF
AE BD
y
A C
D FA B
D E
AF DCAE BD
It must be borne in mind that division by zerois not allowed. This would happen with parallel lines:
x + 2y = 53x + 6y = 10
x
5 2
10 61 2
3 6
30 - 20
0
y
1 5
3 101 2
3 6
10 - 150
and would also occur with coincident lines:
x + 2y = 5-2x -4y = -10
x
5 2
-10 -41 2
-2 -4
-20 + 20
-4 + 4
0
0
Steps Required in Writing the Program:
Steps 1 through 4 should be donebefore you come in to lab:
1) Statement of the problem.What we just did.
2) General Algorithm:an overall solution processwhich should consist of numbered steps.
3) Refined Algorithm:expand the general algorithm;add major variable names or formulas;add solution detail to the plan.
4) Flow Chart: give complete control process;supply minor control variables;use algorithm-defined variables and formulas;think through “what will happen if?”.
5) Program Coding: uses all of the above;supplies the input and output
detail and documentation;provides adequate comments.
Step 2) Example of General Algorithm:
1) Open data file.2) Repeatedly
3) read coefficients4) write system5) calculate determinants6) test for output case, process and output
7) End.
Example of refined algorithm:
1.1 Query for input filename1.2 Open input file2.1 For all data 3.1 Read coefficients A, B, C, D, E, F 3.2 If end of data, go to 6.9. 4.1 Write system: Ax + By = C
Dx + Ey = F 5.1 Den = AE-DB 5.2 Xnum = CE-FB 5.3 Ynum = AF-DC 6.1 If Den !=0, go to 6.5 6.2 If Xnum=0, write “no unique solution” 6.3 If Ynum !=0, write “no solution” 6.4 Go to 3.1 6.5 X = Xnum/Den 6.6 Y = Ynum/Den 6.7 Write “‘x =‘ X; ‘y=‘ Y.” 6.8 Go to 3.1 6.9 End.