How Are Computers Programmed?

Download Report

Transcript How Are Computers Programmed?

How Are Computers Programmed?
CPS120: Introduction to
Computer Science
Lecture 5
Problem Solving
Is an art, not a science
It must be experienced, it can't be taught
– Guidelines can be provided
• Based on experience
• Sound like platitudes
• Are internalized as we learn to solve problems
It requires patience
Problem Solving Tasks
Establish the context of the problem
– Understand the problem
– Determine the primary goals of the solution
– Create a solution
Problem Solving Guidelines
One big problem is unsolvable
– Many small problems can be managed
Understand the problem: What is needed?
– Write on paper what results are expected
– What functions (procedures) will be required to
generate these results
– What information will need to be given to these
functions
– Describe what the functions do before you write a
single line of code
Programs
A program is a set of
step-by-step
instructions that directs
the computer to do the
tasks you want it to do
and produce the results
you want.
The Program Development Cycle
Understand the problem
Plan the program's logic
Code the program
Get the program into machine-readable form
Translate the program
Test and debug the program
Document the program
Understand the problem
Become familiar with what the program is
trying to accomplish
– Read the specifications
– Ask questions
– Understand the specifications
Eliminate extraneous information
Analyze
Determine inputs
– · Variable NAMES
– · Variable TYPES
– · Ranges of VALUES
Names and types of OBJECTS in appropriate.
Determine outputs
– · Output Values
– · Indicate VARIABLE NAMES to store output values
– · Determine VARIABLE TYPE of output variables
Plan the Program’s Logic
Decide how to best meet the program’s
specifications
Often uses a flowchart or pseudocode
Divide the program into subroutines, functions
or modules
– Subroutines cost less and take less time to
maintain
– Can be used in other programs
– Several programmers can work on the same
project
Develop a Solution
Create a FLOW CHART based on
mapping
Test flow chart for RELIABILITY - all
inputs produce proper output
Write PSEUDO CODE based on flow
chart
– Test flow chart for reliability.
Code the Program
Put the solution, generally documented
with pseudocode or a flowchart into a
programming language
CODE the solution
– Select an appropriate language (C++)
– Code the pseudo code
– Create a user interface if required
Machine-Readable Form
Key the program into a computer
Translate the program
Translated into machine language
using an assembler, a compiler or an
interpreter
Includes the elimination of syntax
errors
Generate executable file
Test the Program
Logic errors are not listed during the
translation projects
Only way to find logic errors is to do
program testing
– Involves using sample data as input
– Executing the program
– Checking the results manually
Know as debugging
Planning Your Tests
Create an input file that tests all input ranges
– If there are independent input values, test all values
– If there are ranges of input values, test the middle of each
range, and the upper and lower bounds on each range break
– For example, of the range is integers from 1 to 10, check:
•
•
•
•
•
5
1
0
10
11
Document the Program
Internal Documentation
– Comments
External Documentation
–
–
–
–
–
–
Program specification
Layout chart
Hierarchy chart
Program flowchart
Pseudo-code
Data Dictionary
• Input, Output, Work Area
• Name, description, type, initial value, calculation
– Source listing
– Test Plan
Programming Languages
A programming language
is a set of rules that
provides a way of telling
a computer what
operations to perform.
Levels of Programming Languages
Machine language
Assembly Language
High Level Languages
Fourth Generation Languages (4GL)
Fundamental Programming Concepts
Assignment of values to a variable
Iteration (Looping)
– Over a set of set of statements
– With respect to a logical expressions
(conditions)
Delegation of sub-tasks to functions /
procedures