FCP 1 - Programming Logic
FCP 1 - Programming Logic
Engineering
CSE4002 : Fundamentals in Programming
Level: 4
Credit Value: 15
2
Module Delivery and Evaluation
Learning Hours : 150
Lectures 30 hours
Practical 30 hours
Student Centered Learning 90 hours
Teaching : Lecture and practical session (20 Sessions)
3
Understanding Computer Components and
Operations
Hardware: equipment, or devices, associated with a
computer
For a computer to be useful, it needs more than
equipment; a computer needs to be given
instructions
The instructions that tell the computer what to do
are called software, or programs, and are written by
programmers
4
Understanding Computer Components and
Operations (continued)
Hardware devices that perform input include keyboards
and mice
Through input devices,
data, or facts, enter the computer system
Processing data items may involve
organizing them,
checking them for accuracy, or
performing mathematical operations on them
5
Understanding Computer Components and
Operations (continued)
The hardware that performs these sorts of tasks is the
central processing unit, or CPU
After data items have been processed, the resulting
information is sent to a printer, monitor, or some other
output device so people can view, interpret, and use the
results
6
The Language of a Computer
Digital signals are sequences of 0s and 1s
Machine language: language of a computer
Binary digit (bit):
The digit 0 or 1
Binary code:
A sequence of 0s and 1s
Byte:
A sequence of eight bits
7
Programming Language Evolution
Early computers were programmed in machine language
8
Assembly Language
Assembly language instruction are mnemonic
Assembler: translates a program written in assembly
language into machine language
9
Program Example
Using the assembly language instructions, the equation
wages = rates * hours can be written as follows:
LOAD rate
MULT hour
STOR wages
10
High-Level Languages
High-level languages include Basic, FORTRAN, COBOL,
Pascal, C++, C, and Java
11
Language Style
Every language has rules governing its word usage and
punctuation
Programming rules are called the language’s syntax
Each programming language uses a piece of software
to translate the specific programming language into
the computer’s on-off circuitry, or machine language
12
Language Style (continued)
The language translation software, known as a compiler
or interpreter, tells you if you have used a programming
language incorrectly
For a program to work properly, you must give the
computer exact instructions in a specific sequence
By doing this, you are developing the logic of the
computer program
Once instructions have been inputted to the computer
and translated into machine language, a program can be
run, or executed
13
Understanding the Programming Process
The programmer’s job can be broken down into six
programming steps:
15
2. Plan the Logic
Programmer plans the steps to the program, deciding
what steps to include and how to order them
The two most common tools are flowcharts and
pseudocode
Both tools involve writing the steps of the program in
English
16
3. Code the Problem
Some very experienced programmers can successfully
combine the logic planning and the actual instruction
writing, or coding of the program, in one step
17
4. Translate the Program into Machine Language
Languages such as Java or Visual Basic translate the
programmer’s English-like high-level programming language into
the low-level machine language that the computer understands
18
4. Translate the Program into Machine Language
(continued)
All syntax errors are caught by the compiler or interpreter
19
Creating an Executable Program
20
5. Test the Program
A program that is free of syntax errors is not
necessarily free of logical errors
21
6. Put the Program into Production
Putting a program into production might mean simply
running the program once, if it was written to satisfy a
user’s request for a special list
The process might take months if the program will be
run on a regular basis, or it is one of a large system of
programs being developed
Conversion, the entire set of actions an organization
must take to switch over to using a new program or set
of programs, can sometimes take months or years to
22
accomplish
Let’s start with Logical Planning
With FLOW CHARTS and PSEUDO CODES
23 1/13/2021
Using Flowchart Symbols and Pseudocode
Statements
Flowcharts (pictorial representations) and pseudocode
(English-like representations) are used by programmers to
plan the logical steps for solving a programming problem
Some professional programmers prefer writing pseudocode
to drawing flowcharts, because using pseudocode is more
similar to writing final statements in programming language
Almost every program involves the steps of input,
processing, and output, necessitating some graphical way to
separate them
24
Flow Chart symbols
25 1/13/2021
Flow Chart symbols - Terminal
START
STOP
BEGIN
26 1/13/2021
Flow Chart symbols - Terminal
In flowcharts:
A terminal symbol, or start/stop symbol, should be included at
each end
Often, “start” or “begin” is used as the first terminal symbol and
“end” or “stop” is used in the other
The standard terminal symbol is shaped like a racetrack; often
called a lozenge, because it resembles the shape of a medicated
candy lozenge you might use to soothe a sore throat
27
Flow Chart symbols - process
Indicates any internal operation inside the process/memory
Rate = 10.2
Amount = Price x Quantity
Sum = Mark1 + Mark2
28 1/13/2021
Using Flowchart Symbols
Arithmetic operation statements are examples of
processing in a flowchart, where you use a rectangle as
the processing symbol containing a processing
statement
29
Flow Chart symbols - Input or Output
Used for any input or output (I/O) operation. Indicates that the
computer is to obtain data or output result.
Input Output
30 1/13/2021
Using Flowchart Symbols
To represent an output statement, you use the
parallelogram, which is also the same symbol used for
input statements
31
Flow Chart symbols - Decision
Used to ask a question that can be answered in a binary format.
Example : (Yes or No), (True or False)
32 1/13/2021
Flow Chart symbols - Decision
Example:
False if True
Score > 50
33 1/13/2021
Flow Chart symbols - Flow Lines
Arrows, or flowlines, connect and show the appropriate sequence
of steps
Important to Show the direction of flow
34 1/13/2021
Flow Chart symbols – Module / Predefined Process
Used to invoke a Module / subroutine / unit / function or an interrupt
program.
Modularization helps you to simplify logical diagrams
ModuleName()
• or ModuleName()
35 1/13/2021
Flow Chart symbols – Module /Predefined Process
Modularized example:
36 1/13/2021
Flow Chart symbols - Connector
37 1/13/2021
Using the Connector
You can use a connector when limited page size forces
you to continue a flowchart in an unconnected location
or on another page
By convention, programmers use a circle as an on-page
connector symbol, and a symbol that looks like a square
with a pointed bottom as an off-page connector symbol
38
Using a Connector (continued)
If a flowchart has six processing steps and a page provides room
for only three, you might represent the logic as shown below:
39
Using Flowchart Symbols and Pseudocode
Statements
Figure shows a complete flowchart for the program that doubles a
number, and the pseudocode for the same problem
calculatedAnswer
= inputNumber x 2
40
Activity time
Designing Sequential Flow charts
Q1). Draw a flow chart and write the pseudocode for a program,
To input length and width of a rectangle and output area and perimeter of the
rectangle.
Area = length * width
Perimeter = 2 * (length + width)
Q2). Draw a flow chart and write the pseudocode for a program,
which input marks of 3 modules, Calculate and output Total and average marks
of the student.
41 1/13/2021