Module 1 Introduction to Programming
Module 1 Introduction to Programming
Learning Objectives:
Lesson Proper
The Association for Computing Machinery (ACM) is the world’s largest educational and
scientific computing society. It has its own Code of Ethics and another set of ethical
principles that were also approved by the IEEE as the standard for teaching and practicing
software engineering. These codes are Code of Ethics and Professional Conduct and the
Software Engineering Code of Ethics and Professional Practice, respectively, and some
of their guidelines are presented below:
1
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
that can protect users’ private information and that can avoid other undesired
people to have unauthorized access to it (Code of Ethics and Professional
Conduct).
Honor confidentiality. Unless required by law or any other ethical guideline, a
programmer must keep secret any additional information related to his or her
employer that arises from working in a project.
From Software Engineering Code of Ethics and Professional Practice (IEEE, AMC):
Approve software only if they have a well-founded belief it is safe and meets
specifications. Programmers cannot assume that a system is ready to use only
because it performs the tasks needed. They should make sure these systems are
also safe and meet every specification required by the user. If programs are not
safe, users are unprotected from hackers that could steal important information or
money. Therefore, several tests should be performed in order to ensure a system’s
security before approving it.
Accept full responsibility for their own work. If a program presents errors, the
software developer should accept full responsibility for his or her work, and should
work on revising, correcting, modifying, and testing it.
Not knowingly use software that is obtained or retained either illegally or
unethically. If a computer system will be used as a base for the creation of
another, then permission to do so should be asked by the programmer. This
principle prohibits using any other software for any purpose if the way it was gotten
is not clear or is known to be illegal or unethical.
Identify, define, and address ethical, economic, cultural, legal and
environmental issues related to work projects. If a programmer notices and
identifies that working on a project will lead to any kind of problems, then the
programmer should report it to his or her employer before continuing.
Ensure that specifications for software on which they work satisfy the users’
requirements and they have the appropriate approvals. Software developers
should come to their employers to ask for the correspondent approval to the
system they are creating before continuing working on the next part. If it doesn’t
meet the requirements, then a modification to the source code of the system
should be made.
Ensure adequate testing, debugging and review of software. Programmers
should perform the appropriate tests to the pieces of software they work with, and
should check for errors and system security holes to make sure that the programs
are well implemented.
Not engage in deceptive financial practices such as bribery, double billing,
or other improper financial practices. Programmers are exposed to be
participants on illegal activities to get money. They get involved in them due to
threats, economic issues, or simply because they want to obtain easy money
taking advantage of their knowledge about how computer systems work. This
guideline prohibits programmer to form part of such unlawful actions.
2
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Improve their ability to create safe, reliable, and useful quality software.
Since technology advances faster year by year, and so does virtual criminality, the
need of well-structured and designed programs is increasing. Computer systems
get old and limited by new ones and new devices. Programmers should “further
their knowledge of developments in the analysis, specification, design,
development, maintenance, and testing software and related documents”
(Software Engineering Code of Ethics and Professional Practice) in order to create
better pieces of software.
Activity
Choose 3 code of ethics mentioned above. For each code of ethics site a
scenario where these are properly applied and where violated. Submit it to your
teacher. This is can be encoded or hand written (then take a photo), upload to
online submission folder assigned by your teacher.
Summary
From Software Engineering Code of Ethics and Professional Practice (IEEE, AMC):
Approve software only if they have a well-founded belief it is safe and meets
specifications.
Accept full responsibility for their own work.
Not knowingly use software that is obtained or retained either illegally or
unethically.
Identify, define, and address ethical, economic, cultural, legal and environmental
issues related to work projects.
Ensure that specifications for software on which they work satisfy the users’
requirements and they have the appropriate approvals.
Ensure adequate testing, debugging and review of software.
Not engage in deceptive financial practices such as bribery, double billing, or other
improper financial practices.
Improve their ability to create safe, reliable, and useful quality software.
3
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Learning Objectives:
Lesson Proper
Software refers to any computer program or instructions that cause the hardware to
work.
Classification of Software
Application Software – is a computer program people use to get their work done.
Example: Word Processors, Spreadsheets
System Software – is a program needed to keep all the hardware and software
systems running together smoothly.
Example: Operating Systems (Microsoft, Unix), Language Processors
4
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
implementation of the build system and management of derived artifacts such as machine
code of computer programs.
5
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Types of errors:
Clerical Error – occurs in the coding or data entry process
Logical Error – occurs when the program runs well but the output is erroneous.
Checking the
program
Activity
Think of a real-life scenario where you can apply the concept of programming life
cycle. Submit it to your teacher. This is can be encoded or hand written (then
take a photo), upload to online submission folder assigned by your teacher.
6
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Summary
Software refers to any computer program or instructions that cause the hardware
to work.
Classification of software: Application and System software
Language Processors – is part of the system software that converts computer
Languages into machine readable form.
Steps of Programming Life Cycle
o Defining the Problem
o Planning the Solution
o Coding the Solution
o Checking the Program
o Implementation and Feedback
7
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Learning Objectives
At the end of this lesson students will be able to
understand programming algorithm
identify flowcharting symbols and their functions
learn how to convert mathematical
Lesson Proper
3.1 Algorithm
Algorithm is a finite set of instructions that specify a sequence of operations to be
carried out in order to solve a specific problem or class of problems.
It is called a “recipe for solving problem”.
It can be in a form of
1. Human language (English, Tagalog)
2. Pseudocode - which is a cross between human language and a programming
language. We will do this when we discuss JavaScript programming.
3. Flowchart - A diagram representing the logical sequence in which a combination
of steps or operations is to be performed.
8
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
3.3 Flowchart
A flowchart is a diagram representing the logical sequence in which a combination of
steps or operations is to be performed. It is a 2-dimensional representation of an
algorithm.
Flowcharting Symbol
1. Terminal Symbol (oval) – used to designate the beginning and the end of a
program.
STAR END
9
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
6. Decision Symbol (diamond) – a point in the program where more than one path
can be taken.
Y If N
x=
A A
3.4 Operators
There are 3 basic types of operators in programming.
Arithmetic Operator
These are the operators used in performing simple mathematical operations.
Relational Operator
These are operators used to compare relative values. These are commonly used
in the IF statement and loop statement.
10
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Logical Operator
These are operators used to show how two or more quantities are connected
together using the rules of logic.
Truth Table
AND OR
x y Result X y Result
F F F F F F
F T F F T T
T F F T F T
T T T T T T
Example:
1. AxC A*C
2. ab+2y a*b+2*y
3. X+Y (X + Y) / Z
Z
4. a2 + b3 a*a+b*b*b
Activity
1. Think of 2 house tasks that you are doing and create an algorithm on how you do
it using human language.
11
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
b. a=2L + 2W
c. A= b + c
d
d. X = 2 3 +y
2
e. X = a – bc3
Summary
Algorithm is a finite set of instructions that specify a sequence of operations to be
carried out in order to solve a specific problem or class of problems. It can be in in
a form of human language, pseudocode, or flowchart.
There are 3 types of operators that includes Arithmetic, Relational, and Logical.
Mathematical equation must be written in linear form or programming notation
using programming operators.
12
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Learning Objectives
At the end of this lesson students will be able to
identify basic logic structure
apply Input-Process-Output Model in problem solving
apply proper mathematical operators
create problem solution using flowcharts
Lesson Proper
Basically, computer programming requires us to define the problem first before we even
try to create a solution. Usually, this step involves breaking up of the problem into
smaller and simpler sub-problems through identifying the INPUT, PROCESS, AND
OUTPUT.
A computer program or any other sort of process using the input-process-output model
receives inputs from a user or other source, does some computations on the inputs, and
returns the results of the computations. The system divides the work into three categories:
13
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Now we are ready to solve problem sets and apply the solution using flowchart.
Sample Problem:
Create a flowchart that will ask for two numbers. Compute and display the sum.
Solution:
Based on the given problem we will identify the Input, Process and Output
needed.
Input – 2 numbers; let x represent the first number and y represents the second
number
Process – Add the values of x and y then store the result to variable sum;
sum = x + y
Output – display the value of sum
To create a flowchart, we start with the terminal symbol to start the flowchart
input symbol for the needed input process symbol for the operation or formula
display symbol to display the value of sum terminal symbol with Stop label to
end the flowchart
14
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Final answer
START
Input x, y
sum = x + y
Display sum
END
Tip: You may write your solution first in a sentence case format to fully
understand the problem and your solution before creating the actual flowchart.
15
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Activity
Summary
Basic logic structure: sequential, branching, and looping.
Input–Process–Output (IPO) model is a widely used approach in systems analysis
and software engineering for describing the structure of an information processing
program or another process.
Computer Programming requires us to define the problem first before we even try
to create a solution. Breaking up a problem into smaller subproblem by identifying
the input, process, and output requirements.
16
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Learning Objectives
At the end of this lesson students will be able to
apply appropriate control structure to a problem set
apply Input-Process-Output Model in problem solving
apply proper mathematical operators
create problem solution using flowcharts
Lesson Proper
Examples:
Verifying whether username and password is correct or wrong. If username and
password is correct then you can proceed to your account otherwise it will display
an error message and/or the program will ask you to input again your username
and password.
In online exam, it can automatically tell you if you pass or fail the exam based on
the given condition or passing score.
In an elevator, if passengers reached the limit weight it will automatically alarm.
Discounts for senior citizen and PWD in different stores, if you present an ID or
you qualify as Senior Citizen or PWD you get a discount otherwise you will be
charged with regular price.
Sample Problem 1:
Create a flowchart that will ask for two numbers and display the larger number.
Solution:
Based on the given problem we will identify the Input, Process and Output
needed.
Input – 2 numbers; let x represent the first number and y represents the second
number
Process – verify/evaluate which is greater; x > y or y > x this may result to either
True or False depending on the given value
Output – display either the value of x or the value of y
17
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
To create a flowchart, we start with the terminal symbol to start the flowchart
input symbol for the needed input instead of process symbol, since we are
comparing values we will use the decision symbol (diamond) then write the
identified condition inside ( if x > y ); this will let us create a path depending on the
possible result (True or False) we create a path for the True result and False
result for True result (label with Y for yes), we will use display symbol to
display the value of x as the greater number for the False result (label with N
for no), we will use display symbol to display the value of y as the greater number
both path will connect to terminal symbol with Stop label to end the flowchart.
Final flowchart
START
Input x, y
N
If
x>y Display y
Display x
END
Sample Problem 2:
Create a flowchart that will ask for a number then determine if the number is Positive,
Negative or Zero.
Solution:
Based on the given problem we will identify the Input, Process and Output
needed.
Input –a numbers; let n represent the number
Process – verify/evaluate if n is positive, negative or zero;
if n > 0 the number is Positive; if n < 0 the number is negative; if n = 0 the
number is Zero
Output – either Positive, Negative, or Zero
To create a flowchart for this problem we need to consider that we already have
3 possible results.
18
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Logic:
if n > 0
for Y path Display “Positive” Stop
for N path we still have 2 options left for Negative or Zero
if n < 0 (you can also choose if n = 0 then apply
correct path)
for Y path Display “Negative” Stop
for N path this path means the number is
not Positive and not Negative meaning the number is Zero, Display “Zero”
Stop
Final solution
The results can be rearrange depending on the order of condition. Like you can start
with n < 0 then n = 0.
Activity
19
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
2. Create a flowchart will ask for an age then evaluate the age if it is a qualifying
age to vote or not.
3. Create a flowchart that will ask for two numbers. If the first number is greater
than the second number compute and display the sum otherwise compute and
display the product of the numbers.
4. Create a flowchart that will ask for a number then determine if the number is Odd
or Even number.
5. Create a flowchart that will ask for a grade then display the equivalent remarks
Grade Remarks
100-91 Excellent
90-81 Very Good
80-71 Good
70-51 Fair
50-0 Poor
Out of range Invalid
Summary
Branching structure is when an "Algorithm" makes a choice to do one of two (or
more things)
We use decision symbol to apply branching structure.
We use comparison statement inside decision symbol.
Decision symbol has Y and N path to take based on the result of the condition.
20
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Learning Objectives
At the end of this lesson students will be able to
apply appropriate control structure to a problem set
apply Input-Process-Output Model in problem solving
apply proper mathematical operators
create problem solution using flowcharts
Lesson Proper
6.1 Loop / Iteration
In cases that certain instructions or processes are repeated the programming language
has a way through that by making use of loops. Loops allow you to run one or more set
of instructions repetitively.
Sample Problem
Create a flowchart that will display numbers form 1 - 10.
Solution:
Based on the given problem we will identify the Input, Process and Output
needed.
Input – no input needed instead we will define a variable that will represent the
number to be displayed. Let c represent numbers 1 to 10 and will start to 1, c = 1
Process – counting numbers 1 - 10
Output – display numbers from 1 to 10
To created a flowchart, we start with a terminal symbol with Start label process
symbol to define the value of c, c = 1
we set up a series of processes that will be executed again and again
until we achieve our goal, in this case we will have a decision symbol to check if
the value of c in the range of 1 to 10 since c will represent numbers 1 to 10
if c <= (less than or equal) 10, our goal is for our c to reach 10
for Y path Display c, since we want to display numbers 1-
10 process symbol to add 1 to c, c = c + 1 (this will
increase the value of c by 1 then go back to decision
symbol if c <= 10 repeat process
for N path this path means the value of c exceeds to 10
already and this ends the flowchart
21
Multiple Income Creating Project (MIC P) on ICT
MODULE 1: INTRODUCTION TO PROGRAMMING
Final solution
START
c=1
Y
If
c <= 10 Display c c=c+1
END
Activity
Create a flowchart for each of the problem sets.
1. Create a flowchart that will display the numbers from 1-20.
2. Create a flowchart that will display the numbers from 20-1.
3. Create a flowchart that will ask for 10 numbers then compute and display the
sum and average of the inputted numbers.
4. Create a flowchart that will ask for numbers until a negative number is inputted.
5. Create a flowchart that will ask for N number then display the numbers from 1 to
N.
6. Create a flowchart that will ask for 20 numbers then count the Positive, negative
and zero inputted values.
Summary
Loops allow you to run one or more set of instructions repetitively.
We use decision symbol to go back to a path already executed.
In looping problems, we really need to know the requirements needed and
identify processes that will be repeated multiple times.
22
Multiple Income Creating Project (MIC P) on ICT