Chapter2 1
Chapter2 1
Chapter 2
To be discussed in this chapter:
•Programs and Programming Languages
•The programming process
•(Complie Link and Run process)
•Source code , Object code, and Executable
code
•The integrated development environment
(IDE)
•Program Design
•Algorithms
•Flowcharting (Starting out with C++,
appendix O)
The Basics
• Program: a list of instructions that tells the
computer how to solve a problem or perform
a task.
• Programming: the act of defining these
instructions.
• Programmer: the person doing the defining.
• User: the person who ultimately makes use of
the program. (Examples??)
Remember
• Computers are digital devices that simply do
what they are told.
• We must speak their language to tell them
what to do. ??
• Does this mean, we should
speak binary? ( 0’s and 1’s)??
Programming Languages
Very High Level
Languages
(SQL, Prolog, …)
Libraries,
Other Object RUN
Code
How exactly do we program?
1. Using a text editor, write the program
2. Save it as a file (.cpp extension)
3. Fix any errors that you might have
4.Compile your program into object code. If there are errors, go back
to step 3
5.Run the linker to generate executable code. If there are errors, go
back to step 3
6. Run (execute) your program and test it. If there are errors, go back
to step 3.
• Source Code: The instructions written in C++. This is the only part
that we can understand.
• Compiler: Translates the source code into some intermediate form
IDE
• IDE stands for Integrated Development
Environment
– Includes the compiler and the linker
– Has tools to assist the programmer
– Automates and simplifies the programming
process
• For this course, we will be using the visual
studio IDE.
2.2
PROGRAM DESIGN
The Basics
PROGRAMS = ALGORITHMS + Data Structures
Niklaus Wirth
• Algorithm??
An effective procedure for
solving a problem in a finite
number of steps.
Program Development Algorithm
1. Using a text editor, write the program
2. Save it as a file (.cpp extension)
3. Fix any errors that you might have
4. Compile your program into object code.
5. If compilation is successful, continue to step 6. If it fails, go
back to step 3.
6. Run the linker to generate executable code.
7. If linking is successful, continue to step 8. Otherwise, go back
to step 3.
8. Run (execute) your program and test it.
9. If there are errors, go back to step 3. Otherwise finish.
The Blueprint
• You can think of an algorithm as the blueprint
(plan) of your program.
• Before you begin writing a program, you first
have to understand the problem and then
develop a step-by-step solution (the
algorithm).
• Developing an algorithm to solve a problem is
usually more difficult than writing the code.
Characteristics of Algorithms
• An algorithm for a computer program must
– Have precisely defined steps
– Not be ambiguous
– Terminate after a finite number of steps
• An algorithm exhibits
– Sequence (Process)
– Decision (Selection)
– Repetition (Iteration/Looping)
Sequence
• Each task follows the previous one without
altering the order of the tasks. Each task is
executed once.
Decision
• Allows only one of two tasks to be carried out,
depending on a controlling logical condition.
The selected task is executed only once.
If…then…, If… then… else…
If today is Sunday then don’t go to school
If today is Saturday or today is Sunday then
don’t go to school, else go to school
• The outcome of a decision is either true or
false.
Repetition
• Enables a task to be repeated until a
controlling condition no longer holds.
Keep going to school until you graduate.
Repeat this example until the students
understand and go to the next example when
they do.
• What if it loops infinitely???
More Concepts – Input/Output
• Your algorithm usually needs a set of inputs
from the user and may give outputs to the
user.
• Examples
More Concepts - Variables
• Variables are a way of representing data in
your programs. You can think of them as
containers for a value.
• Examples
Expressing Algorithms
1. Plain English (the step-by-step way)
2. Pseudocode (False code)
– Uses much restricted vocabulary
– Closer to a Programming Language
– Uses variables and symbols
– There are different types available
3. Flowchart
– Graphical method
– Uses various symbols for various actions
– Very easy to draw
– Very easy to read and understand
Flowchart Basics
• A flowchart represents an algorithm or
process, showing the steps as various symbols
and showing their order by connecting them
with arrows.
• The basic symbols are used in flowcharts are
discussed here
Terminal Points
• Rounded rectangles, or terminal points,
indicate the starting and ending points of the
flowchart.
Input/Output Operations
• Parallelograms designate input or output
operations.
Processing
• A rectangle depicts a process such as a
mathematical computation or a variable
assignment.
Connectors
• A connector symbol, which is a circle, is used
to break flowchart into multiple parts.
Example Flowcharts
The Decision Structure
• With decisions, the path to follow is
determined by the outcome of a test. The
diamond symbol is used to represent the test
to be performed.
Program Development Cycle