Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Module 1 Notes

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Introduction to Programming Characteristics of an Algorithm

• Specify each step or instruction


Module #1 exactly.
-What is Programming? –The instructions must be clear.
• There must be a finite number of
 Programming is the process of steps.
creating a set of instructions that –The algorithm must terminate.
tell a computer how to perform a –There must be a stopping point.
task. • There must be an output.
–The algorithm must produce
• Programming can be done using a the correct
programming language such as C+
+, Java and Python. What is Programming Language?

-Who provides the instructions that the • Programming Language is a set of


computer will perform? commands, instructions and syntax
use to create a program that
• Computer programmer is the implement a specific algorithm.
person who writes the instructions
to make computer perform a task. Types of Programming Languages

-What is a Program? • Machine Language


• Assembly Language
• A program is a set of instructions • High-level Language
that tells the computer how to solve
a problem or perform a task. Machine Language

-What is an Algorithm? • Machine language – provides


program instructions in bits.
• Algorithm is the step-by-step • A sequence of 0s and 1s.
sequence of instructions that • Early computers were programmed
describe how data is to be in machine language.
manipulated to generate a specific
output. Assembly Language
• Once coded into a computer-
• Assembly language instructions are
language it would transform into a
written in mnemonics.
computer program.
• Assembler translates a program
Examples of Algorithm written in assembly language into
machine language.
• directions for going to a certain
place High-Level Language
• baking a chocolate cake
• High-level languages allow
• computing income tax
programmer to use English-like
• searching for a name in a telephone
instructions.
Directory • Compiler translates high-level
instructions into 0s and 1s or
machine language.
Popular Programming Languages Input, Processing, and Output

• BASIC Input
• C#
•FORTRAN • is information a program collects
• Java
from the outside world. It can be
• COBOL • JavaScript sent to the program from the user,
who is entering data at the
• Pascal • Python keyboard.
•C • Ruby • Ex: cin >> hours;
cin >> rate;
• C++ • Visual Basics
Processing

• Once information is gathered from


-What is a Program Made of?
the outside world, a program
1. Keywords usually processes it in some
manner.
2.Programmer-Defined Identifiers • Ex: grosspay = hours * rate
3. Operators Output
4. Punctuation • is information that a program
sends to the outside world. It can
5. Syntax
be words, or graphics displayed on
Programming Language Elements a screen, a report sent to the
printer, data stored in a file, or
1. Keywords - words that have information sent to any device.
special meaning. Keywords are also • Ex: cout<< “How many hours
known as reserved words. did you work? “;

2. Identifiers - words or names


defined by the programmer. They Steps in Developing a Program
are symbolic names that refer to
1. Defining and analyzing the problem
variables or programming routines.
2. Planning and designing the solution
3. Coding the solution
3. Operators – perform operations on
4. Testing and debugging the solution
one or more operands. An operand
5. Implementation
is usually a piece of data, like a
6. Maintenance and documentation
number.
4. Punctuation – characters that 1. Defining and Analyzing the Problem
mark the beginning or ending of a
statement, or separate items in a Understand the Problem
list. • Before writing the program the
5. Syntax – rules that must be
programmer must first understand
followed when constructing a
the problem.
program. Syntax dictates how
• Satisfy the user’s need.
keywords and operators may be
used, and where punctuation
symbols must appear.
2. Planning and Designing the Solution Popular Modeling Tools in Algorithm

Plan the Logic – Pseudo-Coding


– Flowcharting
• Involves writing down steps in
English. • Pseudocode is a non-standard English-
• The programmer doesn’t worry like statements between human language
about syntax at this point, just the and a programming language.
sequence of events that will lead
from available input to the desired • Example of Pseudocode:
output (algorithm). Get payroll data.
Calculate gross pay.
3. Coding the Solution Display gross pay.
Code the Program • Flowchart or program flowchart is a
graphical representation of the logic in
• The part in which the programmer
solving a problem.
worries about the correct syntax,
command, punctuation, spelling, • It provides detail steps and the sequence
etc. in which those steps are executed to
• The actual construction of the generate meaningful Results.
source code.
Program Flowchart’s Symbols
4. Testing and Debugging the Solution
Program Flowchart’s Symbols Purpose
Compile and test the program into
Terminal Block Used to signify the beginning and end of a
Machine Language START flowchart. It is represented by an oval.

• Testing and debugging are the Process symbol Used to represent arithmetic operations or
method of validating the program perform any calculations that are to be
to ensure that it will correctly work Sum = A+B
done. It is represented by a rectangle.
on the required task. Input-output block Shows input and output operations. Data
• Compiler catches all syntax errors. are to be read into the computer memory

from an input device or data are to be


5. Implementation Input A
passed from the memory to an output

Put the Program into Production device. It is represented by a

parallelogram.
• The organization can now use the Decision symbol Used to evaluate conditional statements
program. and branch out to the required process
• Running the program using the depending on the outcome of the test
T F
actual data. x>0
which could either be true or false. It is

represented by a diamond.
6. Maintenance and Documentation
On-page connector Used to show a jump from one point to

Maintenance and Documentation is another within the same page to show

mandatory. matching jump points, connectors are


A
labeled with a unique upper-case
• There might be new changes in the alphabet. It is represented by a circle.
organization that affects the
program.
• Provides back-ups and stores data
files on safe places.
Off-page connector Sometimes a flowchart will not fit on one

page, hence, this is used to show


B flowcharting jump from one page to the

next. It is represented by a pentagon.

Initialization symbol Signifies the initialization or preparation of

SUM data and is used to define a set of


PRODUCT
NAME
variables. It is represented by a hexagon.

Flowlines Used to show the directional flow of the

process in the flowchart. It is represented

by a directional arrow.
Sample flow chart
Example 1: Draw a flowchart that will input two numbers. Then calculate and display the
sum and product of these numbers. Write its equivalent pseudocode.

Start Pseudocode:

Step 1: Initialize variable Sum,


Product, A, B
Sum, product, A, Step 2: Input the values of A and B
B
Step 3: Calculate the sum of A+B,
and calculate the product of A*B

Step 4: Display the computed


Input A, B value of the Sum and Product of
Variables A and B

Sum = A+B
Product= A*B

Display Sum,
Product

End
Example 2: Draw a flowchart and write the equivalent pseudocode that will compute and
display the circumference of a circle. Given the formula: Circumference= 2 * 3.1416 *
radius

START

Circumference, 2,
3.1416, radius

Input
radius

Circumference= 2 *
3.1416 * radius

Display
circumference

END
Example 3: Draw a flowchart that will input the student’s ID number and name and
calculate the student’s final grade. The final grade is calculated as the average of four
quizzes. Display the student’s number, name and the equivalent final grade.

• Also, determine if the student “Passed” or “Failed” the final grade.

* Passing grade is 75.

Pseudocode:

Step 1: Initialize variables ID number, Name, FG, A,


B, C, D,
Start
Step 2: Input ID number, Name, A, B, C, D

Step 3: Calculate FG= A + B + C + D/4


ID number, Name, Step 4: Test if FG is greater than or equal to 75.
FG, A, C, D, E
Step 5: if final grade is greater than or equal to 75,
display passed, otherwise display failed.

Step 6: Display the number, name, the final grade


Input ID number, and the result of the decision on Step 5.
Name, A, C, D, E

FG= A + B + C + D / 4

If FG T Display ID number,
> 75 name, Passed

Display ID Number,
name, Failed End

You might also like