Chapter 1

advertisement
Chapter 1 – pg. 1
Chapter 1
OVERVIEW OF PROGRAMMING
AND PROBLEM SOLVING
Pre-chapter Outline
I)
Computer Programming: An Overview
A) Types of Computer Programs
1) A program is a set of instructions, written according to a precise set of rules, that enable a
computer to process data to get information – data to information.
(a) Computer - perform useful work - translation process - translation from one level of detail
to another - need - request - generally stated in a high level of abstraction or low level of
detail - actual computer actions or instructions - very specific or a high level of detail – very
primitive
(b) Primary role of software - translating general needs and requests stated in general terms into
a sequence of primitive instructions for a computer - produce a result satisfying the need or
request – could be very
(c) Programs - computer system - -perform many simple or primitive or general purpose tasks recalled as needed, used for tasks performed frequently and that require very little from user
to user - application program or software - a stored set of instructions responding to a very
specific request – like child – has the capability to do very simple instructions, but can not
put them together for a more complex task
2) The three types of computer programs are: operating systems or programs called system
software – control overall operations of computers, application programs – particular tasks, and
utility programs – convenience facilities.
3) Software is the term used to describe all types of programs. – instructions
4) Hardware - physical
5) Data vs. Information
B) Applications Programs
1.
The job of creating application programs is performed by a programmer. A programmer who
participates in designing a system is sometimes called a Programmer/Analyst.
2) One purpose of application programs is to read input, process it, and produce information that is
requested by the users – performed by applications programmer.
3) Application programs are generally used to computerize business procedures. A set of
computerized business procedures in an application area is called an information system.
4) Packaged software and customized software differ as follows:
(a) Packaged programs- are written by commercial software vendors to meet the needs of a
wide range of users.
(b) Customized software is specially tailored and written to meet the unique needs and
specifications of a company – purchase or outsource.
(c) Horizontal market software – off the shelf – standard, generic; vertical market software –
customized for an industry; value added retailer (VAR) – customized off the shelf software.
(d) Interactive/Batch
C) Machine language programs
1.
All programs to be executed by the computer must be in machine language.
2.
Machine Language is very difficult to learn and use.
Chapter 1 – pg. 2
D) Symbolic Programs
1. Programming languages using English-like or symbolic instructions were developed to make
the programming task easier.
2. A symbolic program must be- translated into machine language prior to execution – 2 steps:
translated and run or (compiled and executed).
3. The programmer writes symbolic instructions in a high-level programming language which
resembles the English language. The symbolic program is called the source program.
4. Symbolic programming languages must be translated into machine language before they can be
executed on the computer. A special program called a compiler is used to translate the
symbolic (source program) into a machine program (object).
CHAPTER OUTLINE
I. Overview of Programming – how to program computers.
A. What is Programming?
a. Logical sequence
b. Create order – programming – computer
c. Computer program is a sequence of steps that the computer performs more
efficiently, effectively, quickly, and accurately than humans.
B. Object oriented programming – analysis of data and related functions into abstract
classifications or classes. Programming uses classes in an attempt to model the way in which
items in general are broken down into classifications.
C. How Do We Write a Program?
a. The computer is not intelligent. It cannot analyze the problem and come up with a
solution, also called an algorithm. A human must analyze the problem, develop a
sequence of instructions for solving the problem and get it into the computer for the
computer to solve. This is the heart of the programming process. The computer can
perform the solution program, including the repetitive and boring tasks, for the
human. All programs are algorithms.
b. Two-phase process: problem solving and implementation.
i. Problem Solving Phase
1. Analysis and specification – understand the problem and what the
solution should be. Heart of the programming process.
2. General solution (algorithm) – logical sequence of steps to solve
the problem. An algorithm is a verbal or written description of a
logical sequence of actions.
3. Verify – solution does really solve the problem.
ii. Implementation Phase
1. Concrete solution (program) – get into the programming language.
2. Test – thoroughly test to make sure the computer does follow the
instructions.
iii. Maintenance Phase
1. Use the program.
2. Maintain or modify for changing requirements.
c. A programming language is a simplified form of English that adheres to a strict set
of grammatical rules.
d. Translating an algorithm into a programming language is called coding. The
program is tested by executing it on the computer. If it fails in any way, we debug
the program. The combination of coding and testing is implementation.
e. Planning is very important in programming. Shortcuts usually take more time in the
long run.
f. Together the problem solving, implementation, and maintenance makes up the life
cycle of the program.
Chapter 1 – pg. 3
g.
Documentation is the written explanations included with the program to help if
different people work on a program or if there is a time lapse in the usage of the
program.
h. Data vs. Information. vs. knowledge
Theoretical Foundations: Binary Representation of Data
II. What is a Programming Language?
 Machine language
 Assembly language
 Symbolic language
 Assembler
 Structured
 Object-oriented
 Natural
 Interpreter
 Compiler
 Source program/ object program
A. Operations of a computer.
 Control structures – sequentially, conditionally, repetitively, and with subprograms.
B. In order to run a C++ program it is necessary to have a text editor, a compiler, and a linker.
 The text editor is used to enter the program into the machine and should provide the ability
to easily edit your programming code (source code).
 The compiler translates your source code into object code (machine instructions). It should
locate any syntax errors which consist of punctuation or spelling errors.
 The linker will combine all necessary object files and data files. This step is automatic for
the programmer.
Background Information: Compilers and Interpreters
III. What Is a Computer?
A.
Components of a computer:
a. Memory unit – ordered sequence of storage cells, distinct address
b. Arithmetic/logic unit – performs mathematical and logical operations
c. Control unit – controls the actions of the other components
d. Input devices
e. Output devices
f. Fetch-execute cycle
g. Peripheral devices
h. Auxiliary storage devices
i. Hardware/software
j. User interface
k. Interactive system – allows direct entry of programs and data and provides immediate
feedback to the user
l. Batch system – program is run on all the data
m. Operating system – manages all of the computer’s resources
n. Editor – interactive program used to create and modify source programs or data
Background Information: PCs, Workstations, and Mainframes
Background Information: The Origins of C++/Advantages
 Portability – the syntax and functions remain the same from machine to machine.
 C++s ability to manipulate data addresses allows programs to be written at almost any
assembly level.
IV. Ethics and Responsibilities in the Computing Profession
 The computer gives us a vast array of new capabilities that can affect people and the
environment in dramatic ways, giving us many new ethical issues. A professional in the
computing industry has knowledge that will allow them to do certain things that others cannot
do.
 Software Piracy – easy to copy – profit from the effort and money spent developing software.
Chapter 1 – pg. 4
 Privacy of Data – a computer enables the accumulation of massive amounts of information
about people, companies, etc. A computing professional has the responsibility of avoiding the
abuse of special access to confidential data.
 Use of Computer Resources – the computer is a resource that justifies its own expense, but it is
valuable only when the software is running.
 Software Engineering – computers work correctly most of the time. The reliability of a
computer depends on the care taken when writing the software. Errors in programs can have
disastrous results. Programmers that have the responsibility of developing correct software are
known as software engineers.
V. Problem-Solving Techniques – understand and analyze a problem to come up with the solution or
algorithm. In the problem solving phase of designing algorithms, we should be conscious of the
strategies available to help solve the problem effectively and efficiently.
A. Ask Questions – understand exactly what is needed.
B. Look for Things That Are Familiar – never reinvent the wheel – there is probably a similar
problem that can be applied in some way. A good programmer immediately recognizes a
subtask they designed before and plugs in the solution.
a. The accumulation of subprograms is called a library.
C. Solve by Analogy – similar problem. An analogy is a broader application of the strategy of
looking for things that are familiar. The best programmers are those who have broad experience
solving all kinds of problems.
D. Means-Ends Analysis – the beginning state and the ending state are usually known – the
problem is the set of actions to get from one to the other.
E. Divide and Conquer – large problems into smaller units.
F. The Building-Block Approach – it may be possible to put some of the smaller solutions together
to solve the big problem. The solutions for the small problems may already exist, so it is just a
matter of putting the smaller solutions together to solve the big problem.
G. Merging Solutions – combining existing solutions.
H. Mental Blocks: The Fear of Starting – the big problem might be overwhelming. Try to look at
the problem in your own words and focus on the subparts individually. This will give you a
clearer picture of the overall problem. Some of the small parts may look familiar. Most mental
blocks are caused by not really understanding the problem.
I. Algorithmic Problem Solving – step by step process is sometimes a trial and error process. The
computer can only do certain things – we try to get the computer to transform, manipulate,
calculate, or process the input data to produce the desired output information.
VI. Problem-Solving Case Study: An Algorithm for a Company Payroll
VII. Summary
Download