close

Se connecter

Se connecter avec OpenID

Chapter 2

IntégréTéléchargement
Chapter 2:
Input, Processing, and Output
Starting Out with Programming Logic & Design
Second Edition
by Tony Gaddis
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter Topics
2.1
2.2
2.3
2.4
2.5
2.6
2.7
Designing a Program
Output, Input, and Variables
Variable Assignment and Calculations
Variable Declarations and Data Types
Named Constants
Hand Tracing a Program
Documenting a Program
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-2
2.1 Designing a Program
1. The first step in programming is designing –
flowcharts and pseudocode help with this
process.
2. Next, the code is written.
3. All code must be cleared of all syntax errors.
4. After the executable is created, it can be
checked for logic errors.
5. If logic errors exist, the program must be
debugged.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-3
2.1 Designing a Program
The purpose of Programming Logic and Design is
to focus on Flowcharts and Pseudocode.
The design is the foundation of a good program.
Figure 2-1 The program development cycle
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-4
2.1 Designing a Program
Two steps in designing a program
1. Understand the tasks that the program is to
perform.
•
Learning what the customer wants.
2. Determine the steps that must be taken to
perform the task.
•
•
Create an algorithm, or step-by-step directions, to
solve the problem.
Use flowcharts and/or pseudocode to solve.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-5
Class Research:
15 minutes for each team to research
5 minutes for each team to present
• Use your books, the
internet and the ITT
Tech Virtual Library
to determine:
• What is pseudocode?
• What is a flowchart?
• What are each used
for?
• Discuss pros and cons
of each
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-6
2.1 Designing a Program
Pseudocode
• Fake code used as a model for programs
• No syntax rules
• Well written pseudocode can be easily translated to
actual code
Display “Enter the number of hours”
Input hours
Display “Enter the hourly pay rate”
Input payRate
Set grossPay = hours * payRate
Display “The gross pay is $”, grossPay
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-7
2.1 Designing a Program
Flowcharts
• A diagram that graphically
depicts the steps that take
place in a program
Figure 2.2 Flowchart for the
pay calculating program
Terminator used for
start and stop
Parallelogram used
for input and output
Rectangle used for
processes
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-8
2.2 Output, Input, and Variables
Output – data that is generated and displayed
Input – data that a program receives
Variables – storage locations in memory for data
Computer programs typically follow 3 steps
1. Input is received
2. Some process is performed on the input
3. Output is produced
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-9
2.2 Output, Input, and Variables
Display is the keyword to show output to the
screen
Sequence – lines execute in the order they appear
String Literals – a sequence of characters
Figure 2-4 The statements
execute in order
Figure 2-5 Output of
Program 2-1
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-10
2.2 Output, Input, and Variables
Input is the keyword to take values from the user
of the program
It is usually stored in variables
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-11
BREAK
• 10 minutes
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-12
2.2 Output, Input, and Variables
Programmers can define variable names
following certain rules
–
–
–
–
Must be one word, no spaces
Generally, punctuation characters are avoided
Generally, the first character cannot be a number
Name a variable something that indicates what
may be stored in it
camelCase is popular naming convention
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-13
2.3 Variable Assignment & Calculations
Variable assignment does not always have to
come from user input, it can also be set
through an assignment statement
Set price = 20
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-14
2.3 Variable Assignment & Calculations
Calculations are performed using math operators
The expression is normally stored in variables
Set sale = price – discount
Table 2-1 Common math operators
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-15
BREAK
• 10 minutes
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-16
Multiple Choice Review Questions 1 - 10
• Take good notes. Some of these questions
might show up on the mid-term.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-17
Question 1
A ______ error does not prevent the program
from running, but causes it to produce incorrect
results.
a.syntax
b.hardware
c.logic
d.fatal
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-18
Question 1
A ______ error does not prevent the program
from running, but causes it to produce incorrect
results.
a.syntax
b.hardware
c.logic
d.fatal
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-19
Question 2
A ______ is a single function that the program
must perform in order to satisfy the customer.
a.task
b.software requirement
c.prerequisite
d.predicate
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-20
Question 2
A ______ is a single function that the program
must perform in order to satisfy the customer.
a.task
b.software requirement
c.prerequisite
d.predicate
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-21
Question 3
A(n) ______ is a set of well-defined logical steps
that must be taken to perform a task.
a.logarithm
b.plan of action
c.logic schedule
d.algorithm
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-22
Question 3
A(n) ______ is a set of well-defined logical steps
that must be taken to perform a task.
a.logarithm
b.plan of action
c.logic schedule
d.algorithm
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-23
Question 4
An informal language that has no syntax rules,
and is not meant to be compiled or executed is
called ______.
a.faux code
b.pseudocode
c.java
d.a flowchart
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-24
Question 4
An informal language that has no syntax rules,
and is not meant to be compiled or executed is
called ______.
a.faux code
b.pseudocode
c.java
d.a flowchart
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-25
Question 5
A ______ is a diagram that graphically depicts the
steps that take place in a program.
a.flowchart
b.step chart
c.code graph
d.program graph
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-26
Question 5
A ______ is a diagram that graphically depicts the
steps that take place in a program.
a.flowchart
b.step chart
c.code graph
d.program graph
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-27
Question 6
A(n) ______ is a set of statements that execute in
the order that they appear.
a.serial program
b.sorted code
c.sequence structure
d.ordered structure
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-28
Question 6
A(n) ______ is a set of statements that execute in
the order that they appear.
a.serial program
b.sorted code
c.sequence structure
d.ordered structure
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-29
Question 7
A ______ is a sequence of characters that is used
as data.
a.sequence structure
b.character collection
c.string
d.text block
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-30
Question 7
A ______ is a sequence of characters that is used
as data.
a.sequence structure
b.character collection
c.string
d.text block
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-31
Question 8
A ______ is a storage location in memory that is
represented by a name.
a.variable
b.register
c.ram slot
d.byte
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-32
Question 8
A ______ is a storage location in memory that is
represented by a name.
a.variable
b.register
c.ram slot
d.byte
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-33
Question 9
A ______ is any hypothetical person that is using
a program and providing input to it.
a.designer
b.user
c.guinea pig
d.test subject
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-34
Question 9
A ______ is any hypothetical person that is using
a program and providing input to it.
a.designer
b.user
c.guinea pig
d.test subject
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-35
Question 10
A(n) ______ is a message that tells (or asks) the
user to enter a specific value.
a.inquiry
b.input statement
c.directive
d.prompt
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-36
Question 10
A(n) ______ is a message that tells (or asks) the
user to enter a specific value.
a.inquiry
b.input statement
c.directive
d.prompt
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-37
Unit 2 Homework
• Short Answer Review Questions 1-4 on page 71
of the textbook
• Algorithm Workbench Review Questions 1 & 2
on page 71 of the textbook
• Programming Exercises Questions 1 & 4
starting on page 72 of the textbook
• DUE NEXT WEEK
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-38
BREAK
• 10 minutes
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-39
Preparing Your Laptop for the Course
• Passport device should be divided into 4
partitions for:
–
–
–
–
Your own files (200GB)
Windows (100GB)
Linux (100GB)
Windows 2008 Server (100GB)
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-40
Preparing Your Laptop for the Course
(cont)
• Copy VMPlayer files to Passport devices
• See VM Player instruction sheet
(PT1420.U1.TS1)
• Download vbsetup.exe from Wikispace web
site
• Download Raptor files from Wikispace web site
 Autorun.inf
 Raptor_Setup.msi
 Start_Here.html
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-41
BREAK
• 10 minutes
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-42
Labs
• See Lab Manual Handout 2.1 Pseudocode
• See Lab Manual Handout 2.2 Flowchart
• See Lab Manual Handout 2.3 Visual Basic
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-43
Due Next Week vs Today
Due Next Week
• Unit 2 Research Assignment: Researching
Variable Naming Rules (see handout)
• Unit 2 Homework (see handout)
• Read the rest of Chapter 2 (pp. 56-68)
Due today
• Lab 2.1, Lab 2.2, and Lab 2.3
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1-44
Auteur
Document
Catégorie
Uncategorized
Affichages
5
Taille du fichier
572 KB
Étiquettes
1/--Pages
signaler