Chapter 2-Introduction to Computer Program
Chapter 2-Introduction to Computer Program
Programming
Presentation by: Jullie Ann M. Ocampo
Table of contents
01 Computer Program
Interpreter vs Compiler
Interpreter Compiler
execute a program sequentially, transforms an entire program
translating at each step; and from one language to
debuggers, which execute a another
program piecemeal and monitor
various circumstances, enabling
the programmer to check
whether the operation of the
program is correct or not
Difference of Compiler and Interpreter!
Basis of
Compiler Interpreter
difference
• Compile will parse or analyses all
of the language statements for
its correctness. If incorrect, • No linking of files or
throws an error machine code generation
• If no error, the compiler will • Source statements
Programming Steps convert source code to machine executed line by line
code. DURING Execution
• It links different code files into a • Create the program
runnable program (known as exe)
• Create and Run the Program
Basis of
Compiler Interpreter
difference
The program code is already
Interpreters are easier to
translated into machine code.
Advantage use, especially for
Thus, it’s code execution time
beginners.
is less.
Interpreted programs can
You can't change the program
run on computers that
Disadvantage without going back to the
have the corresponding
source code.
interpreter.
Pertaining
C, C++, C#, Scala, Java all use PHP, Perl, Ruby uses an
Programming
complier. interpreter.
languages
Role of a Compiler
▪ Compilers reads the source code, outputs executable code
▪ Translates software written in a higher-level language into instructions
that computer can understand. It converts the text that a programmer
writes into a format the CPU can understand.
▪ The process of compilation is relatively complicated. It spends a lot of
time analyzing and processing the program.
▪ The executable result is some form of machine-specific binary code.
Role of Interpreter
▪ The interpreter converts the source code line-by-line during RUN
Time.
▪ Interpret completely translates a program written in a high-level
language into machine level language.
▪ Interpreter allows evaluation and modification of the program while it
is executing.
▪ Relatively less time spent for analyzing and processing the program
▪ Program execution is relatively slow compared to compiler
03
Software Development Life
Cycle (SDLC)
Software
Development
Life Cycle
Illustration
*image © cseworld.com
Software Development Life Cycle
01 Problem Definition
The first step in the process of program development is the thorough
understanding and identification of the problem for which is the program
or software is to be developed. In this step the problem has to be defined
formally. All the factors like Input/output, processing requirement,
memory requirements, error handling, interfacing with other programs
must be taken into consideration in this stage.
Software Development Life Cycle
02 Program Design
The next stage is the program design. The software developer makes use
of tools like algorithms and flowcharts to develop the design of the
program.
● Algorithm
● Flowchart
Software Development Life Cycle
03 Coding
Once the design process is complete, the actual computer program is
written, i.e. the instructions are written in a computer language. Coding is
generally a very small part of the entire program development process
and also a less time-consuming activity in reality. In this process all the
syntax errors i.e. errors related to spelling, missing commas, undefined
labels etc. are eliminated.
Software Development Life Cycle
04 Debugging
At this stage, the errors in the programs are detected and corrected. This
stage of program development is an important process. Debugging is also
known as program validation. Some common errors which might occur in
the programs include:
• Un-initialization of variables.
• Reversing of order of operands.
• Confusion of numbers and characters.
• Inverting of conditions
Software Development Life Cycle
05 Testing
The program is tested on several suitable test cases. A test plan of the
program must be done at the stage of the program design itself. This
ensures a thorough understanding of the specifications. The most trivial
and the most special cases should be identified and tested. It is always
useful to include the maximum and minimum values of all variables as
test data.
Software Development Life Cycle
06 Documentation
Documentation is a very essential step in the program development.
Documentation helps the users and the people who maintain the
software.
This ensures that future modification if required can be done easily. Also,
it is required during redesigning and maintenance.
Software Development Life Cycle
07 Maintenance
Updating and correction of the program for changed conditions and field
experience is accounted for in maintenance. Maintenance becomes
essential in following situations:
• Change in specification,
• Change in equipment,
• Errors which are found during the actual execution of the
program.
04
Program Design
(Algorithm, Pseudocode and Flowchart)
What is an algorithm?
▪ is a procedure or formula for solving a problem,
based on conducting a sequence of specified
actions
▪ A computer program can be viewed as an
elaborate algorithm
▪ In mathematics and computer science, an algorithm
usually means a small procedure that solves a
recurrent problem
Algorithm
Sample 1:
Step 1: Start
Problem: Write an
Step 2: Declare a variable and initialize
algorithm that display the
its value.
content of a variable.
Step 3: Display the value of the variable.
Step 4: Exit
Algorithm
Sample 2: Step 1: Start
Step 2: Declare an integer variable. Let
Problem: Write an the variable be num.
algorithm that display the Step 3: Ask the user to input a number
inputted value of a and store it to num.
variable. Step 4: Display the value of the variable
num.
Step 5: Exit
Algorithm
Sample 3: Step 1. Start
Step 2. Declare integer variables (ex. A
Problem: Write an and B) that will hold the 2 inputted
algorithm that display the numbers and the sum, difference,
SUM, DIFFERENCE, product and quotient. Let the variables
PRODUCT and be SUM, DIFF, PROD and QUO.
QUOTIENT of two Step 3. Ask the user to input the first
inputted numbers. number. Let variable A hold the input.
Algorithm
Sample 3: Step 4. Ask the user to input the second
number. Let variable B hold the input.
Problem: Write an
Step 5. Compute: SUM=num1+num2;
algorithm that display the
DIFF=A-B; PROD=A*B; QUO=A/B.
SUM, DIFFERENCE,
Step 5. Display SUM, DIFF, PROD and
PRODUCT and
QUO.
QUOTIENT of two
Step 6. Exit.
inputted numbers.
Algorithm Step 1: Start
Step 2: Declare an integer variable that will
Sample 4: hold the grade of the student. Assume
grade as the variable.
Problem: Write an
Step 3: Ask the user to enter a grade and
algorithm that will ask the
store it to variable grade.
user to enter a grade and
Step 4: Check if the grade is greater than
determine and display if
or equal to 75.
the student’s grade is Step 5: Display “Passed” if grade is greater
passed or failed. Given than or equal to 75, otherwise “Failed”
that 75 is the passing Step 6: End
grade.
Algorithm
Step 1: Start
Sample 5: Step 2: Declare an integer variable that
will hold student age. (age)
Problem: Write an algorithm
Step 3: Ask the user to enter age and
that will ask the user to
store it to variable age.
enter age and determine the
Step 4: Check if the age is less than or
grade level depending on
equal to 12, or if age is less than to equal
the age.
to 16, or if age is less than or equal to
<= 12 -> Elementary
18.
<= 16 -> Junior High School
<= 18 -> Senior High School
Algorithm
Sample 5:
Step 5: Display “Elementary” if age is
Problem: Write an algorithm less than or equal to 12; Display “Junior
that will ask the user to High School” if age is less than or equal
enter age and determine the to 16; and Display “Senior High School”
grade level depending on if age is less than or equal to 18;
the age. Step 6: End
<= 12 -> Elementary
<= 16 -> Junior High School
<= 18 -> Senior High School
Algorithm Step 1: Start
Sample 6: Step 2: Declare variable that will hold
name and initialize its value. Also,
Problem: Write an algorithm initialize variable counter to 0.
that will print your name Step 3: Check if counter is less than 10.
ten times. Step 4: If true, display contents of
variable name otherwise go to Step 6.
Step 5: Add 1 to counter and repeat
Step 3.
Step 6: End
Algorithm
Sample 7: Step 1: Start
Step 2: Initialize integer variable that will
Problem: Write an algorithm hold the inputted number, sum and
that will display the sum of counter to 0. (num, sum and ctr)
five (5) inputted numbers Step 3: Check if counter is less than 5.
(using counter). Step 4: If true, Ask the user to enter a
number and store is to variable num.
otherwise go to Step 7.
Algorithm
Sample 7:
Step 5: Add num to sum and store it to
Problem: Write an algorithm sum.
that will display the sum of Step 6: Add 1 to ctr and store it to ctr
five (5) inputted numbers and repeat Step 3.
(using counter). Step 7: Display sum.
Step 8: End
What is a pseudocode?
▪ is a simple way of writing programming code in
English.
▪ is not actual programming language
▪ it uses short phrases to write code for programs
before you create it in a specific language
Basic Java Syntax and it’s functions
Syntax Function
Use to define variables that has integer
int
value
Use to define variables that has
double
decimal point values
System.out.print Use to display text in the screen
Use to display text in the screen
System.out.println
followed by a new line
Basic Java Syntax and it’s functions
Syntax Function
Scanner scan = new Instantiation that will be necessary for
Scanner(System.in); the user to input values.
for(initialization;
Use for iteration.
condition; increment)
Mathematical Operators
Example
Operator Description Result
(a=5, b=4)
+ Addition a+b 9
- Subtraction a-b 1
* Multiplication a*b 20
The flowlines show the order or sequence and direction of the flow of
the program. It is used to guide the viewer along their flowcharting path.
And while there are many different types of arrow tips to choose from,
we recommend sticking with one or two for your entire flowchart. This
keeps your diagram looking clean, but also allows you to emphasize
certain steps in your process.
Flowchat
Sample 1: Start
End
Flowchart
Sample 2:
Problem: Draw a flowchart
that display the inputted
value of a variable.
Flowchart
Sample 3:
Problem: Draw a flowchart
that display the SUM,
DIFFERENCE, PRODUCT
and QUOTIENT of two
inputted numbers.
Flowchart
Sample 4:
Problem: Draw a flowchart
that will ask the user to
enter a grade and
determine and display if
the student’s grade is
passed or failed. Given
that 75 is the passing
grade.
Flowchart
Sample 5:
Problem: Draw a flowchart
that will ask the user to
enter name and print name
ten times.
References
➢ Airth, M., & Perry, A. (1970, January 1). Pseudocode: Definition & Examples - Video & Lesson
Transcript | Study.com. Study.Com.
https://study.com/academy/lesson/pseudocode-definition-examples-quiz.html
➢ Farrell, J. (2011). Java Programming. Cengage Learning. https://doi.org/9781111529444
➢ https://www.facebook.com/BrainKart-678754188988648/. (n.d.-a). Algorithm, Pseudocode
And Flowchart. Russia Today International. Retrieved from
https://www.brainkart.com/article/Algorithm,-Pseudocode-and-Flowchart_6945/
➢ Design Tools | Encyclopedia.com. (n.d.). Retrieved October 14, 2020, from https://www.
encyclopedia.com/computing/news-wires-white-papers-and-books/design-tools
➢ Java Conditional Or Relational Operators - W3resource. (n.d.). W3resource. Retrieved from
https://www.w3resource.com/java-tutorial/java-conditional-operators.php#:~:
text=The% 20conditional%20operator%20is%20a,a%20value%20to
%20a%20variable.
➢ Program Design Tools | Notes, Videos, QA And Tests | Grade 11›Computer Science›
Programming Concepts & Logics | Kullabs. (n.d.). Retrieved from
https://kullabs.com/class-11/computer-science-1/programming-concepts-
logics/program-design-tools
Thank You
for Listening!
CREDITS: This presentation template was created by Slidesgo, and includes icons by
Flaticon, and infographics & images by Freepik