Introduction to Programming
END
Enter
Created by N. Nembhard
Main Menu
What is a Computer Program?
Basic Elements of Any Program
The Main Steps in Developing a Program
Basic Control Structures
Types of Errors
EndPrevious Page Next PageHome Page
Created by N. Nembhard
Pseudocode
Pseudocode consists of English like statements that describe the processing steps of a program in paragraph form. It is an informal language that is easy and user friendly to use. It is not an actual programming language and are not executed on computers. They can help you “think out” a program before attempting to write it in a programming language.
EndNext
Previous
Home
Created by N. Nembhard
HomeAlgorithms
A computer is only a tool that can do what it is specifically told to do. We can direct the computer to do what we want by specifying our needs in a discrete step-by-step manner.
An algorithm must be developed, which is a step-by-step procedure to solve a problem.
EndNext
Previous
Created by N. Nembhard
An algorithm must meet the following requirements:– Use operations from only a given set of basic
operations– Produce the problem solution, or answer, in
a finite number of such operations.
AlgorithmsHome
EndNext
Previous
Created by N. Nembhard
High Level Languages
There are many programming languages –some examples are Basic, c, c++, Visual Basic, Java, Pascal. These are high level languages which are closer to human languages. Programs can also be written in low level languages such as assembly language and is closer to the language of the computer.
EndNext
Previous
Home
Created by N. Nembhard
Exit
Home
NextPrevious
What is a computer Program?
A program is an organized list of instructions that when executed causes the computer to behave in a predetermined manner. It is a step-by-step list of instructions written in a particular computer programming language.
Without programs, computers are useless.
Created by N. Nembhard
End
Home
NextPrevious
Main Steps in Developing a Program
1. Define the problem
2. Outline the solution
3. Develop the outline into an algorithm
4. Test the algorithm for correctness
5. Code the algorithm into a specific
programming language
6. Run the program on the computer
7. Document and maintain
the program
Created by N. Nembhard
Exit
Home
NextPrevious
The Basic Elements of any Program
Input
Processing
Output
The basic elements of any program are:
Created by N. Nembhard
End
Home
NextPrevious
Input
This is entering or sending data to the computer. The most frequent way of entering data is by using the keyboard.
Created by N. Nembhard
End
Home
NextPrevious
Processing
The processor or microprocessor is the part of the computer that reads, interprets and executes the program instructions. Processors are integrated circuits that contain transistors and other electronic components. It is a small chip that functions as the “brain” of the computer. The processor is also called the Central Processing Unit (C.P.U)
Created by N. Nembhard
End
Home
NextPrevious
Output
Sending or displaying data to the user. Common output devices includes the monitor and the printer.
Created by N. Nembhard
What Have You Learnt?
Previous Page Home Page Next Page End
Created by N. Nembhard
QuizClick on the correct answer:
A set of English like statements that is used as an informal language is called:
Algorithm
Psuedocode
Computer program
A
B
C
Previous Page Home Page Next Page end
Created by N. Nembhard
QuizClick on the correct answer:
Which of the following is NOT a high level language?
Basic
Assembly
C++
A
B
C
Previous Page Home Page Next Page end
QuizClick on the correct answer:
The basic elements of any program are:
Input, storing, processing
Input, storing,output
Input, processing, output
A
C
B
Previous Page Home Page Next Page end
Created by N. Nembhard
QuizIs the following statement true or false?
Click on true if the statement is correct or false if it is incorrect.
A computer program is a step-by-step list of instructions written in a particular computer programming language.
Previous Page Home Page Next Page end
True FalseCreated by N. Nembhard
End of Quiz!
Previous Page Home Page Next Page end
Created by N. Nembhard
Errors that programmers usually make includes:
Semantic Errors
Syntax Errors
Logic Errors
EndNext PageHome PagePrevious Page
Types of Errors
Created by N. Nembhard
Semantic Errors
This is where meaning of the language is not obeyed. For example, what the words really say or what functions are requested in the command.
Previous Page Home Page Next Page End
Created by N. Nembhard
Syntax ErrorsViolations of the language. Syntax error refers to the spelling and grammar of a programming language. The particular programming language used expects words entered in a specific form. The expected form is called the syntax.
Each program defines its own syntactical rules that control which words the computer understands, which combinations of words are meaningful and what punctuation is necessary.
Previous Page Home Page Next Page End
Created by N. Nembhard
Logic Errors
A logic error occurs when a step in the program logic is incorrect e.g. an average program will produce a wrong answer if the sum of the numbers is divided by a number other than the total count of the numbers.
Previous Page Home Page Next Page End
Created by N. Nembhard
Basic Control StructuresThe basic control structures are:
Simple Sequence
If-Then-Else
Do While
The ability to express a problem solution using only three basic patterns of control is called structured programming.
Previous Page Home Page Next Page End
Created by N. Nembhard
Simple Sequence Programs
Previous Page Home Page Next Page End
Created by N. Nembhard
Simple Sequence Control Structure
Represents the computer’s ability to execute instructions in step-by-step, sequential manner.It is the simplest and most frequently used of the three basic control structures.Previous Page Home Page Next Page End
Created by N. Nembhard
FLOWCHARTS
Previous Page Home Page Next Page End
Simple Sequence
An example of a simple sequence set of instructions not involving the use of a computer is the steps you might give a friend to get to a store. The steps must be followed in a sequential manner otherwise your friend may get lost and never find the store.
1. Proceed down Orange Street for two miles.
2. Turn right on Duke Street.3. Proceed on Duke Street.4. At fork, take Main Street to
the left.5. Proceed two blocks.6. Store is on the left (77 Main
Street.
Previous Page Home Page Next Page End
Created by N. Nembhard
Flowchart
Start
Proceed down orange street for two miles
Turn right on duke street
At fork, take main street to the left
Proceed two blocks
Store is on the left (77 Main Street)
Stop
A program flowchart is a pictorial representation of an algorithm.
Previous Page Home Page Next Page End
Created by N. Nembhard
Simple Sequence
A simple wake up algorithm:
1. Get out of bed
2. Brush teeth
3. Eat breakfast
4. Take shower
5. Get dressed
Start
Brush teeth
Eat Breakfast
Take shower
Get dressed Stop
Program
Flowchart
Previous Page Home Page Next PageEnd
Created by N. Nembhard
Flowchart Symbols
Start – Every algorithm must have one entry point (Start) and one exit point (stop).
These are indicated by the ellipsis symbols, called terminal interrupt symbols. Start
Stop
Previous Page Home Page Next Page End
Created by N. Nembhard
Flowchart Symbols
Input/output Symbol – Reading data from an input medium or writing data to an output medium.
Previous Page Home Page Next Page End
Created by N. Nembhard
Flowchart Symbols
Process symbol – Shows any processing steps. It represents an operation or group of operations causing change in value, form or location of data.
Previous Page Home Page Next Page End
Created by N. Nembhard
Flowchart Symbols
Flow Line - shows sequence of operations arrowheads are required if linkage is not top-to-bottom or left-to-right.
Previous Page Home Page Next Page End
Created by N. Nembhard
Flowchart Symbols
Decision Symbol – shows decision-making operation, usually based on a comparison, that determines which of two or more alternative paths should be followed.
Previous Page Home Page Next Page End
Created by N. Nembhard
Flowchart Symbols
Connector - Shows exit to, or entry from, another part of the flowchart; if the to or from step is another page, a page reference should be stated.
B3 c2
FROM PAGE 3
Previous Page Home Page Next PageEnd
Created by N. Nembhard
Flowchart Symbols
Annotation symbol – Gives additional explanation; comments.
-------
Previous Page Home Page Next Page End
Created by N. Nembhard
Flowchart Symbols
Preparation symbol – An operation performed on the program itself for control, initialization, overhead, or cleanup. E.g. to set a switch, to place a limit value in the loop control variable and to initialize an accumulator.
Previous Page Home Page Next Page End
Created by N. Nembhard
Flowchart Symbols
Predefined Process – Used to identify a series of steps shown another flowchart.
Previous Page Home Page Next Page End
Created by N. Nembhard
Variables
Variables are data items whose values may change, or vary, during processing.
Variable names are created to represent, or refer to, these data items. They are used to give names to lactations where data should be stored.
Click for Hint
Previous Page Home Page Next PageEnd
Created by N. Nembhard
Variable Names
Choose variable names that are appropriate and gives an indication of what will be stored. Shorten names where possible.
Home Page Next PageEnd
Previous Page
Created by N. Nembhard
Simple Sequence Structure
The Simple Sequence Structure represents the computer’s ability to execute instructions in a step-by-step, sequential manner.
Home Page Next Page EndPrevious Page
Created by N. Nembhard
Solution – Example 1
Pseudocode
Start
Print “Enter FARENHEIT value”
Read farenht
celsius = (fareneht – 32) * 5/9
Print farenht, celsius
stop
Start
Print “Enter FARENHEIT value”
Program Flowchart
Read farenht
Print farenht, celsius
Stop
celsius = fareneht – 32) * 5/9
Home Page Next PageEnd
Previous Page
Example 1 – In Basic Language
Print “Enter FARENHEIT value”
input farenht
celsius = (fareneht – 32) * 5/9
Print “The farenheit temperature is: “; farenht
Print “The celsius temperature is: “; celsius
End
Click to
Run Program
Home Page Next PageEnd
Previous Page
Created by N. Nembhard
Problem- Using Simple Sequence
Example 2
A store needs a computer program to prepare a monthly bill for each customer. For simplicity, assume that each customer purchases (at most) one type of item each month. For each purchase, there will be four inputs: customer name, item, quantity purchased, and price. The output will be the customer’s monthly bill after a 10 per cent discount is taken before taxes and a 5 % sales tax is added.
Home Page Next PageEnd
Previous Page
Created by N. Nembhard
Solution – Example 2
Pseudocode
Start
Print “Enter name, item, quantity, and price”
Read name, item, qty, price
amtod = qty * price
discount = amtod * 0.10
subbill = amtod – discount
taxes = subbill * 0.05
bill = subbill * taxes
Print name, item, bill
stop
Home Page Next PageEnd
Previous Page
Created by N. Nembhard
Solution – Example 2
Start
Print “Enter name item, quantity and price”
Read name item, qty, price
discount = amtod * 0.10
amtod = qty * price
Program Flowchart
subbill = amtod - discount
taxes = subbill * 0.05
bill =subbill + taxes
Print name, item, bill
Stop
Home Page Next PageEnd
Previous Page
Program in Basic
Print “Enter name, item, quantity, and price”
Input name, item, qty, price
amtod = qty * price
discount = amtod * 0.10
subbill = amtod – discount
taxes = subbill * 0.05
bill = subbill * taxes
Print name, item, bill
endClick to
Run Program
Home Page Next PageEnd
Previous Page
Created by N. Nembhard
Selection Control Structure
If-Then- Else
Previous Page Home Page Next Page End
Previous Page Home Page Next Page End
The IF-THEN- ELSE control structure indicates that at a particular time in processing, a choice between alternative paths, or sequence of instructions is to be made.
It is a conditional statement that causes execution of some statement depending on the truth value of a certain condition. If the condition is true, then the statement (s) after “then” are executed. If the statement is false then the statement (s) after “else” are executed provided that the else clause is present.
IF-THEN-ELSE CONTROL STRUCTURE
Created by N. Nembhard
Previous Page Home Page Next Page End
Example 1 - PseudocodeIf rain is falling then take umbrellaEndif
IF-THEN-ELSE CONTROL STRUCTURE
Rain is falling?
Take Umbrella
Start
Stop
Example 1 - Flowchart
Yes
No
Created by N. Nembhard
Previous Page Home Page Next Page End
Example 2 - Pseudocode
If rain is falling then take umbrellaElse don’t take umbrellaEndif
IF-THEN-ELSE CONTROL STRUCTURE
Rain is falling?
Take Umbrella
Start
Yes
No
Don’t take Umbrella
Stop
Example 2 - Flowchart
Created by N. Nembhard
Selection Control Structure
Do while Control Structure Else
Previous Page Home Page Next Page End
Created by N. Nembhard
Do While Control Structure
The “Do While” structure is a repetition statement that allows you to specify that an action is to be repeated while some condition remains true.
For example:
while there are more items on my shopping list
Purchase next item and cross it off my list.
Previous Page Home Page Next Page End
Created by N. Nembhard
Previous Page Home Page Next Page End
StartPrint “Enter two
numbers, (Enter 999 to end program):
Read xRead y
X = 999 ? Yes
No
X > y ?
Print “The first number
is greater”
Yes NoPrint “The
second number is greater”
Print x, y
StopDo While
Control Structure
Print “Enter next two numbers, (Enter 999 to
end program):
Read xRead y
Created by N. Nembhard
Do While Control StructureStart
Print “Enter two numbers, (Enter 999 to end program):”
Read x
Read y
do while x not equal to 999
if x > y then
print “The first number is greater”
else
print “The second number is greater”
endif
Print x, y
Print “Enter next two numbers, (Enter 999 to end program):”
Read x
Read y
Enddo
Stop
Previous Page Home Page Next Page End
Click toRun Program
in Basic
Created by N. Nembhard
Created By:Natalee N. Nembhard
Thanks for Using the Program!
© Copyright 2010Home PagePrevious Page
EXIT
Top Related