bien 001 introduction to biomedical engineering methods module 1:introduction to computers,

24
IEN 001 Introduction to Biomedical Engineering Meth odule 1: Introduction to Computers, Flowcharting and Programming in C oger H. Johnson, [email protected] eptember 5, 2000 ves: oduction to Computers nd Computing Environment at Marquette. lop problem-solving strategies through flow ch oduction to program development environment. oduction to C language programming. lop two real C programs and run them. ctures 1-2: Computing History Computer Constituents Evolution of Programming Essential Programming Steps Syntax Develop Two Programs in C

Upload: vin

Post on 05-Feb-2016

24 views

Category:

Documents


0 download

DESCRIPTION

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 Computers and Computing Environment at Marquette. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

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

Page 2: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

• • 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.

Page 3: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

• 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.

Page 4: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

• 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.

Page 5: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

• 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.

Page 6: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

• Essential Programming Steps1) A clear statement of the problem:

Decide what it is you really want to do. Helps todecide 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.

Page 7: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

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.

Page 8: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

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.

Page 9: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

Flowchart Symbols:

Page 10: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

Casanova Flowchart Example:

Page 11: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

Meal-ordering Flowchart:

Page 12: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

Flowchart for Tuition Computation:

Page 13: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

Tuition Computation Flowchart with Nested Decision Loops:

Page 14: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

Tuition Computation Flowchart with Termination:

Page 15: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

Tuition Computation with Termination:

Page 16: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

Decision with a Three-way Branch:

Page 17: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

Balance Computation with Termination:

Counter for Loop Termination:

Page 18: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

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 23 11 25 1

5 6 1 10

11 11

1

y

1 55 3

1 25 1

3 25 1 10

22 11

2

Page 19: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

For the general case:Ax + By = CDx + Ey = F

x

C BF EA BD E

CE BFAE BD

y

A CD FA BD E

AF DCAE BD

Page 20: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

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 210 61 23 6

30 - 20

0

y

1 53 101 23 6

10 - 150

Page 21: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

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

00

Page 22: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

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.

Page 23: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

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.

Page 24: BIEN 001 Introduction to Biomedical Engineering Methods Module 1:Introduction to Computers,

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.