Lecture 11: 10/1/2002CS149D Fall 20021 CS149D Elements of Computer Science Ayman Abdel-Hamid...
-
Upload
lauren-davidson -
Category
Documents
-
view
214 -
download
0
Transcript of Lecture 11: 10/1/2002CS149D Fall 20021 CS149D Elements of Computer Science Ayman Abdel-Hamid...
Lecture 11: 10/1/2002 CS149D Fall 2002 1
CS149D Elements of Computer Science
Ayman Abdel-Hamid
Department of Computer Science
Old Dominion University
Lecture 11: 10/1/2002
Lecture 11: 10/1/2002 CS149D Fall 2002 2
Outline•Skip section 3.6 and 3.7
•Overview of Computer Programming Process
•Overview of algorithms and programming languages
Should cover section 4.1 from Brookshear Text, and sections 1.1-1.2 from Etter Text
Lecture 11: 10/1/2002 CS149D Fall 2002 3
Computer Programming
Computer program
A sequence of instructions to be performed by a computer
Computer programming
The process of planning a sequence of steps for a computer to follow
Programming Process
•Problem-solving phase
•Implementation phase
•Maintenance phase
Lecture 11: 10/1/2002 CS149D Fall 2002 4
Programming Process1/3
Problem-solving phase
•Analysis and specification ( understand and define problem, and what is expected of solution)
•General solution (algorithm: a logical sequence of steps that solves the problem)
•Verification (Follow steps to make sure solution solves the problem)
Implementation phase
•Concrete solution (Program in a Programming language)
•Testing (make sure the program produces the desired results)
Maintenance phase
•Use Program
•Maintain Program (meet changing requirements)
Lecture 11: 10/1/2002 CS149D Fall 2002 5
Programming Process2/3
Analysis and Specification
General solution (algorithm)
Verification
Concrete solution
(Program)
Testing
Maintenance Phase
In “Programming and Problem Solving with C++”, 3rd Edition, Jones and Bartlett Publishers, 2002
Documentation: writing program documentation, and user manuals
Lecture 11: 10/1/2002 CS149D Fall 2002 6
Programming Process3/3
How about we take a shortcut and start the programming process by the implementation phase?
Costly shortcut
Develop a general solution (algorithm) first
Think first and code later!
Lecture 11: 10/1/2002 CS149D Fall 2002 7
Algorithm1/3
Algorithm
•An ordered set of unambiguous executable steps, defining a terminating process
•A step-by-step procedure for solving a problem in a finite amount of time
1. Make a list of all positive integers
2. Arrange the list in descending order (from largest to smallest)
3. Extract the first integer from the list
What are the problems with these instructions?
Lecture 11: 10/1/2002 CS149D Fall 2002 8
Algorithm2/3
•Difference between an algorithm and its representation
Analogous to difference between a story and a book
•An algorithm is abstract and can be represented in many ways
Algorithm for converting from Celsius to Fahrenheit can be represented as
1. F = (9/5) C + 32 (algebraic equation)
2. “ Multiply the temperature reading in Celsius by 9/5 and then add 32 to the product”
An algorithm can be represented using some sort of language
1950s, 1960s represented using flowcharts
pseudocode (precisely defined textual structures)
Lecture 11: 10/1/2002 CS149D Fall 2002 9
Algorithm3/3
An algorithm for starting the car
1. Insert the key in ignition
2. Make sure transmission is in Park (or Neutral)
3. Depress the gas pedal
4. Turn key to start position
5. If engine starts within six seconds, release key to ignition position
6. If engine does not start in six seconds, release key and gas pedal, wait ten seconds, and repeat steps 3 through 6, but not more than five times
7. If the car does not start, call the garage
Lecture 11: 10/1/2002 CS149D Fall 2002 10
Programming Language1/3
A set of rules, symbols, and special words used to construct a computer program. There are rules for syntax (grammar) and semantics (meaning)
Machine language
•Binary-coded instructions
•Closely coupled with design of computer hardware
Assembly language
•Low-level programming language in which a mnemonic is used to represent each of the machine language instructions
•We have seen an example in chapter 2 from Brookshear Text
•We need an assembler
Translate an assembly language program into machine code
Lecture 11: 10/1/2002 CS149D Fall 2002 11
Programming Language2/3
High-level language
•closer to English and other natural languages
•C++, Java, C, Fortran, Ada, Pascal, COBOL, BASIC
•We need a compiler
Translate a high-level language program into machine code
•Source program
Program written in a high-level language
•Object program
Machine language version of a source program
•Difference between compilation and execution of a program
Lecture 11: 10/1/2002 CS149D Fall 2002 12
Programming Language3/3
•Some programming languages are translated by an interpreter (some versions of BASIC)
•Interpreter translates and executes each instruction in the source program
•Java uses both a compiler and interpreter