CS208 Software Programming 7/11/2016 1

advertisement
CS208
Software Programming
7/11/2016
1
Introduction
Software

Instructions that tell the computer
what to do (ie. a program)

Instructions are written in a
programming language
2
Language Levels

Each type of CPU has its own specific
machine language

Other language levels were created to
make it easier for a human being to write
programs



machine language
assembly language
high-level language
3
Languages


Machine Language
 Zeros and Ones
 Bit representations are specific to a
particular hardware architecture
Assembly Languages
 Use mnemonics for operations and
sometimes also for memory locations
 Each assembly language is specific to a
particular hardware architecture
 Translated by an Assembler
4
Languages

High Level Languages –




Use English-like statements to instruct the
computer what to do
Are more portable (will run on different
kinds of hardware)
Are easier for humans to understand and
program with
Translated by a Compiler
5
Programming Language
Capability Requirements

Representation & Storage (of both the Data and the
program Instructions)

Data Processing (Interprets the program instructions
and carries out the operations defined by these
instructions on the Data)

Data Input and Data Output

Input Data - data that is provided (is not computed)
to the program as it runs

Output Data - data that the program ultimately
produces (output data = solution of the
computational problem)
6
Example Languages

High Level Languages






FORTRAN
COBOL
BASIC
Pascal
C/C++
Java
- scientific/engineering, math
- business
- education and PCs
- education
- application development
- application development
7
Program Development

Program development consists
of:
 Discovering the underlying
algorithm
 Representing that algorithm as
a program using a
programming language
8
Programs


What is a program?

A collection of statements

Written in a programming language

Specify the steps taken to solve a problem
Each programming language has grammar
rules that specify:

How the statements are formed

How the statements are combined
9
High-Level Language
Programming

Programming requires:

A programming language (e.g. C++) to
express your ideas

A set of tools to edit and debug your code

A compiler to translate your programs to
machine code

A machine to run the executable code on
10
Types of Code

Source code (source file)


Object Code (object file)


Typed into the editor by the programmer using
a programming language
Translated from the source code by the
compiler
Executable Code

Created by the linker - links the object code
and any necessary library object code files
together
11
Program Development
Computational Problem
develop
An Algorithm
encode
Source code Program in a High-Level Language
(e.g. C++)
Source
Code
High-Level
Language
Program
Development
Compiler
Linker
Object
Code
A machine Language
Program
12
Creating Computer Programs






Analyze the problem
Plan an algorithm
Hand check the algorithm
Code the algorithm (or write program)
Hand check (trace through) the
program
Evaluate and modify program as
necessary
13
Structured Programming


Structured Programming is a technique used
to create well-formed programs
Uses top-down design with stepwise
refinement


Larger pieces of code are broken into shorter
pieces of code that encompass a single task
Task are repeatedly broken down into smaller
tasks, until they are small enough to be
understood easily
14
Structured Programming
Concepts
 Final program is created via top-down design.
 Main code starts with empty modules, and is slowly
refined to lowest level
 Program is subdivided into modules (one
logical task, generally no more than one page
long)
 Keeps programmer from being overwhelmed by the
size of the job
 Allows easy division of work (modules assigned to
different programmers)
15
Structured Programming
Concepts (continued)
 Each module is organized into recognizable
paragraphs, using indentation to show
nesting and subordinate clauses.
 Code structures should have only one entry
point and one point of exit (no GOTO).
 Embedded comments describe the function of
each data item and purpose of each module.
 Straightforward, easily readable code is
preferred over slightly more efficient, but
obtuse, code.
16
Benefits of Structured
Programming
 More readable
 Easier to maintain
 More flexible
 More likely to be correct on first run
 Easier to "prove" by systematic program
verification
17
Download