Professional Documents
Culture Documents
Handout - C++ - 1st Week
Handout - C++ - 1st Week
Handout - C++ - 1st Week
• The students should be able to understand the Program Development Cyle and Programming Tools.
• Writing a Pseudocode, Algorithm and Flowchart
Program Planning
Programming Tools
1. Algorithms
2. Pseudocode
3. Flowchart
WHAT IS AN ALGORITHM?
Examples:
Examples:
• An algorithm must be specific enough so that it can be conveniently translated into a computer program
(using C++, for example). An algorithm can be specified:
• Textually
For example, using pseudocode.
• Graphically
For example, using flowcharts or UML activity charts
PSEUDOCODE
• An outline of a program, written in a form that can easily be converted into real programming statements. It
resembles the actual program that will be implemented later. However, it cannot be compiled nor executed.
• The idea is to represent the algorithm in a form that is in between pure English and actual Running code
• Actually, it’s one of the ways for expression of Algorithm.
• Pseudo means “pretended” / “not real”
• Code refers to a computer programming language
Pseudocode - format
Special Keywords
1. Input/output
2. Iteration
3. Selection/Decision
4. Processing
Computer Programming 1 Prepared by: Prof. Marvin Ramos
Pseudocode – Example
1. Write a program that obtains two numbers from the user. It will print out the sum of those numbers.
Pseudocode
Example 1: Write an algorithm and pseudocode to determine a student’s final grade and indicate whether it is
passing or failing. The final grade is calculated as the average of four marks.
Comparison Operators
• Comparison operators are used to compare two values (or variables). This is important in programming,
because it helps us to find answers and make decisions. The return value of a comparison is either 1 or 0,
which means true (1) or false (0).
Example
(5==3) False
(5!=3) True
(5>3) True
(5<3) False
Computer Programming 1 Prepared by: Prof. Marvin Ramos
(5>=3) True
(5<=3) False
FLOWCHARTS
• Information system flowcharts show how data flows from source documents through the computer
to final distribution to users.
• Program flowcharts show the sequence of instructions in a single program or subroutine. Different
symbols are used to draw each type of flowchart.
• An algorithm can be represented graphically using a flowchart.
FLOWCHART SYMBOLS
Purpose of Flowcharting
Pseudocode Flowchart
- READ X, Y, Z
- COMPUTE SUM (S) As X + Y + Z
- COMPUTE Average (A) As S / 3
- COMPUTE Product (P) As X * Y * Z
- WRITE (Display) the Sum, Average,
and Product
Pseudocode Flowchart
- READ Name, Balance, Rate
- COMPUTE Interest as balance x Rate
- WRITE (DISPLAY) Name And Interest
Algorithm
Pseudocode Algorithm
• Input the length in feet (Lft) Step 1: Input Lft
• Calculate the length in cm (Lcm) by multiplying Lft with 30 Step 2: Lcm
• Print length in cm (LCM) Lft x 30
Step 3: Print Lcm
Example 3: Write an algorithm, pseudocode and draw a flowchart that will read the two
sides of a rectangle and calculate its area.
Flowchart
Pseudocode
• Input the width (W) and Length (L) of a rectangle
• Calculate the area (A) by multiplying L with W
• Print A
Algorithm
Step 1: Input W,L
Step 2: A L x W
Step 3: Print A
Example 4: Write the pseudocode, algorithm and flowchart to check the two numbers. Display the output if the
number is greater than or less than.