Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Module 2 Programing

The document provides an overview of programming concepts, focusing on algorithms and flowcharts. It explains flowchart symbols and their meanings, including terminal, process, input/output, decision, and initialization blocks. Additionally, it includes examples of flowcharts for various algorithms and references for further reading.

Uploaded by

Hacchi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Module 2 Programing

The document provides an overview of programming concepts, focusing on algorithms and flowcharts. It explains flowchart symbols and their meanings, including terminal, process, input/output, decision, and initialization blocks. Additionally, it includes examples of flowcharts for various algorithms and references for further reading.

Uploaded by

Hacchi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Previously…

Programming.
Elements of programming.
✔ Syntax
✔ Variables
✔ Functions
✔ Arithmetic/Logic Operations
✔ Loop
Programming tools
Previously…
Programming tools
✔ Algorithm
▪ Characteristics
• Clarity and unambiguous
• Well defined input/output
• Finiteness
• Feasible
• Language independent
Previously…
Programming tools
✔ Algorithm
▪ Characteristics of Algorithm
▪ Advantages / disadvantages
▪ How to design an algorithm.
▪ Qualities of a good algorithm
✔ Pseudocode
✔ Flowchart – next discussion…
Flowchart
Is a graphical representation of an algorithm.
Symbols such as squares, diamonds, and ovals
represent various operations.
These symbols are connected by lines and arrows
to indicate the flow of data or control from one
point to another.
Flowchart Symbols

Terminal block
Decision block

Process block
Initialization block

Input/Output block Connector

Flow Lines
Terminal / Terminator Block
Ovals or rounded rectangles are used to
indicate the start and the end of a module
or program
START
An oval is labeled with the name of the
module at the start ; the end is indicated by
the word end or stop for the top or Control
Module END
A start has flow lines entering it and only
one exiting it; an end or exit has one flow
line entering it but none exiting it.
Process Block
The rectangle indicates a processing block, for
such things as calculations, opening and closing
files, and so forth.
A processing block has one entrance and one
exit. Sum=Num1+Num2
Input / Output Block Output
Input
The parallelogram indicates input to and
output operations
An I/O block has one entrance and only one
exit
Display
Get X
X
Decision Block
The diamond indicates a decision.
It has one entrance and exactly two exits from
the block. T Con F
ditio
One exit is the action when the resultant is n
TRUE and the other exit is the action when
resultant is FALSE. Action Action
when when
TRUE FALSE
Initialization Block
used for declaring / initializing variables
needed to solve a certain process.

Num
Declaration 1
❑ stating a variable name to be use Num
2
Num
Initialization 1=5
❑ to set (a starting value of a variable) Num
2=3
On-Page Connectors
The circle is used as a connection point
between two sections of a flowchart that are A
not adjacent or closely located to each other

Note: These connectors should be used as little as


possible. They should only be used to enhance
readability. Overuse, however, decreases
readability and produces a cluttered effect.
A
Flow Lines
Indicated by straight lines with arrows to
show the direction of data flow.
The arrowhead is sometimes not shown
when the direction of flow is clear
Used to connect blocks by exiting from one
and entering another.
Example 1
Create a flowchart that displays your age five years from now. The algorithm should have
a variable that is initialized to your current age.
Algorithm:
Start
1. Get user’s age
2. Compute age 5yrs from now
age=age + 5 Age

3. Print age.

Get Age Age = Age + 5 Display Stop


Age
Example 2
Create a flowchart that will compute for the Average score of a student based on three
quizzes. The quiz scores are entered by the user. The scores are integers and may range from 0
to 100, inclusive. However, the Average may have a value having decimal places.
Algorithm: Start

1. Get scores from the three average=(Q1+Q2+Q3)/3

quizzes (q1, q2, q3)


Q1, Q2, Q3
2. Compute for the average. average-=0 Display
Ave
average=(q1 + q2 + q3)/3
3. Print average Get Q1, Q2, Q3 Stop
Example 3
Create a flowchart that ask the user to enter two number. Compute and display their sum.
Algorithm:
1. Enter 1st number (num1). Start

2. Enter 2nd number (num2). sum=num1+num2

3. Compute for the sum of num1 sum=0;


Num1, num2

and num2. Print Sum

sum=num1+num2 Enter num1;


Enter num2; Stop
4. Print sum
More on Decision Box
It should be noted that what you place inside the diamond box are
conditions that either results to TRUE or FALSE
Note: You don’t place conditions that are in essay form, you must be able
to represent it in a mathematical form.

Is
variable
X< X
20? less than
20?
Conditional Statements
✔ Statements that result to TRUE or FALSE.
T F
✔ More on decision block.

Single Alternative Selection Structure


A decision box may not necessarily have to do something for
both the TRUE path and the FALSE path.
Dual Alternative Selection Structure
Performs two different things when the
condition is TRUE or FALSE
T F
Exercise 3:
1. Draw a flowchart that will ask the user to enter a character indicating the user’s gender. If
the user enters ‘M’ display “You’re a Male”.
2. Draw a flowchart that will ask the user to enter a character indicating the user’s gender. If
the user enters ‘M’ display “You’re a Male”. If not assume that the user is a female thus
display “You’re a Female”.
REFERENCES
Website:
✔ Fungsi Motherboard Processor Memori Dan Harddisk | Computer hardware, Computer hardware store,
Computer Pinterest. https://www.pinterest.ph/pin/88594317657692933/?mt=login
✔ Unit 4 - Hardware & Ergo - Davids BTA30 Portfolio 2016 Sites.google.com.
https://sites.google.com/site/davidsbtaportfolio/unit-4---hardware-ergo.
✔ Computer Software Icon #229946 - Free Icons Library. Icon-library.com.
https://icon-library.com/icon/computer-software-icon-14.html
✔ https://www.programiz.com/cpp-programming
✔ https://www.rapidtables.com/code/text/ascii-table.html
✔ https://www.lucidchart.com/pages/what-is-a-flowchart-tutorial#section_6
REFERENCES
Textbooks:
✔ Zak, Diane, Introduction to Programming with C++, C & E Publishing c2011
✔ Bronson, Gary J., C++ for Engineers and Scientists, Course Tech c2010
✔ Lambert, Kenneth, Fundamentals of C++ and data structures, 2009, Cengage
✔ Bronson, Gary J, C++ for engineers and scientists, 2010, Course Technology
✔ Deitel, PJ, C : how to program, 2009, Pearson Education, G,
--- END ---

You might also like