Programming Fundamentals II
Programming Fundamentals II
PROGRAMMING
FUNDAMENTALS II
DR. F. O. BOATENG
Contents 1-2
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.
2.1 Designing a 1-4
Program
The purpose of Programming Logic and
Design is to focus on Flowcharts and
Pseudocode.
The design is the foundation of a good
program.
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.
2.1 Designing a 1-6
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
2.1 Designing a 1-7
Program
Flowcharts Figure 2.2 Flowchart for the
stop
Parallelogram used for
processes
2.2 Output, Input, and 1-8
Variables
Output – data that is generated and
displayed
Input – data that a program receives
Variables– named storage locations in
memory for data
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
Variables
Input is the keyword to take values from
the user of the program
It is usually stored in variables
2.2 Output, Input, and 1-11
Variables
Programmers can define variable names
following certain rules
1. Must be one word, no spaces
2. Generally, punctuation characters are
avoided
3. Generally, the first character cannot be a
number
4. Name a variable something that
indicates what may be stored in it
camelCase is popular naming convention
2.3 Variable Assignment & 1-12
Calculations
Variable
assignment does not always have to
come from user input, it can also be set
through an assignment statement
Set price = 20
2.3 Variable Assignment & 1-13
Calculations
Calculations are performed using math
operators
The expression is normally stored in variables
Set sale = price – discount
Data Types
A variable declaration includes a variable’s
name and a variable’s data type
Data Type – defines the type of data you
intend to store in a variable
• Integer – stores only whole numbers
• Real – stores whole or decimal numbers
• String – any series of characters
Declare Real grossPay
2.4 Variable Declarations & 1-15
Data Types
Forsafety and to avoid logic errors,
variables should be initialized to 0 or some
other value
2.5 Named Constants 1-16
Program
Calculate the batting average for any
player
Program
1. Input is received.
• The number of hits
• The number of times at bat
2. Some process is performed on the input.
• Calculate the batting average
• Divide the number of hits by the number
of times at bat
3. Output is produced.
• The player’s batting average
2.8 Designing Your First 1-21
Program
2.8 Designing Your First 1-22
Program
Figure 2-17 Flowchart for program 2-15
2.8 Designing Your First
Program
1-23
Summary
Input
• Determine data needed for input
• Choose variables to store the input
Process
• Determine calculations to be performed
• Choose variables to store the calculations
Output
• Determine what output the program will
display
• Usually the results of the program’s
calculations
1-24
THANK
YOU