0% found this document useful (0 votes)
33 views

Chapter 2-Introduction to Computer Program

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

Chapter 2-Introduction to Computer Program

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

Introduction to Computer

Programming
Presentation by: Jullie Ann M. Ocampo
Table of contents
01 Computer Program

02 Interpreter and Compiler

03 Program Development Cycle

04 Design Tools in Developing Program


01
Introduction to Computer
Program
What is a program?
▪ is a specific set of ordered operations for a computer to perform
▪ contains a one-at-a-time sequence of instructions that the
computer follows in the modern computer that John von
Neumann outlined in 1945
▪ can be characterized as interactive or batch in terms of what
drives them and how continuously they run
▪ Interactive program – receives data from an interactive user
▪ Batch program - runs and does its work, and then stops and
can be started by interactive users who request their
interactive program to run the batch program
What is a computer program?
▪ is a sequence of instructions written using a Computer
Programming Language to perform a specified task by the
computer
▪ is also called a computer software, which can range from two lines
to millions of lines of instructions
▪ Computer program instructions are also called program source
code and computer programming is also called program coding

Remember: A computer without a computer program is just a dump


box; it is programs that make computers active.
02

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.

Store machine language as Not saving machine code


Machine code
machine code on the disk at all.
Basis of
Compiler Interpreter
difference
Running time Compiled code run faster Interpreted code run slower

It is based on language translation It is based on Interpretation


Model
linking-loading model. Method.
Generates output program (in the Do not generate output
Program form of exe) which can be run program. So they evaluate
generation independently from the original the source program at every
program. time during execution.
Program execution is separate from
Program Execution is a part
the compilation. It performed only
Execution of Interpretation process, so
after the entire output program is
it is performed line by line.
compiled.
Basis of
Compiler Interpreter
difference
Target program execute The interpreter exists in the
Memory
independently and do not require memory during
requirement
the compiler in the memory. interpretation.
For web environments,
where load times are
Bounded to the specific target important. Due to all the
machine and cannot be ported. C exhaustive analysis is done,
Best suited for and C++ are a most popular a compiles take relatively
programming language which uses larger time to compile even
compilation model. small code that may not be
run multiple times. In such
cases, interpreters are better.
Basis of
Compiler Interpreter
difference
The compiler sees the entire code
Interpreters see code line by
Code upfront. Hence, they perform lots
line, and thus optimizations are
Optimization of optimizations that make code
not as robust as compilers
run faster
Difficult to implement as
Interpreted languages support
Dynamic Typing compilers cannot predict what
Dynamic Typing
happens at turn time.
It is best suited for the
It is best suited for the
Usage program and development
Production Environment
environment.
Compiler displays all errors and The interpreter reads a single
warning at the compilation time. statement and shows the error
Error execution
Therefore, you can't run the if any. You must correct the
program without fixing errors error to interpret next line.
Basis of
Compiler Interpreter
difference
Input It takes an entire program It takes a single line of code.

Compliers generates intermediate Interpreter never generate any


Output
machine code. intermediate machine code.

Display all errors after, Displays all errors of each line


Errors
compilation, all at the same time. one by one.

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.

nextInt() Use to read integer values

nextDouble() Use to read decimal point values


Basic Java Syntax and it’s functions
Syntax Function

if(condition) - else Use in making decisions

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

/ Division a/b 1.25


Modulus (returns the
% a%b 1
remainder)
Relational Operators
Example
Operator Description Result
(a=10, b=15)
== Equality operator a==b false
!= Not Equal to operator a!=b true
> Greater than a>b false
< Less than a<b true
Greater than or equal
>= a>=b false
to
<= Less than or equal to a<=b true
Pseudocode
Sample 1:
1. start
Problem: Write a
2. int x=5;
pseudocode that display
3. System.out.println (“The
the content of a variable.
integer is: “ + x);
4. end
Pseudocode 1. start
Sample 2: 2. int x; Scanner scan = new
Scanner(System.in);
Problem: Write a
3. System.out.print (“Input an
pseudocode that will allow
integer”);
input of any integer and
display it 4. x = scan.nextInt();
5. System.out.println (“The
inputted integer is “ + x);
6. end
Pseudocode 1. start
Sample 3: 2. int x, y, sum, diff, prod,
quo; Scanner scan = new
Problem: Write a
Scanner(System.in);
pseudocode that display
3. System.out.print (“Input
the SUM, DIFFERENCE,
PRODUCT and the first integer”);
QUOTIENT of two 4. x = scan.nextInt();
inputted numbers. 5. System.out.print (“Input
the second integer”);
Pseudocode 6. y = scan.nextInt();
Sample 3: 7. compute:
a. Sum = x+y;
Problem: Write a
b. Diff = x-y;
pseudocode that display
c. Prod = x*y;
the SUM, DIFFERENCE,
PRODUCT and d. Quo = x/y;
QUOTIENT of two 6. System.out.println (“The
inputted numbers. sum of the two integers
is: ” + sum);
Pseudocode 9. System.out.println (“The
Sample 3: difference of the two
integers is: ” + diff);
Problem: Write a 10. System.out.println (“The
pseudocode that display product of the two integers
the SUM, DIFFERENCE, is: ” + prod);
PRODUCT and 11. System.out.println (“The
QUOTIENT of two quotient of the two
inputted numbers. integers is: ” + quo);
12. end
Pseudocode
Sample 4:
1. start
Problem: Write a 2. int grade; Scanner scan =
pseudocode that will ask new Scanner(System.in);
the user to enter a grade 3. System.out.print (“Enter
and determine and display grade: ”);
if the student’s grade is 4. grade = scan.nextInt();
passed or failed. Given
that 75 is the passing
grade.
Pseudocode
Sample 4: 5. If (grade <= 75)
a.System.out.println(“Pas
Problem: Write a
sed”);
pseudocode that will ask
b. else
the user to enter a grade
and determine and display i. System.out.println
if the student’s grade is (“Failed”);
passed or failed. Given 6. end
that 75 is the passing
grade.
Pseudocode Sample 5:
Problem: Write a pseudocode that will ask the user to enter
age and determine the grade level depending on the age.
0 - 12 -> Elementary
13 - 16 -> Junior High School
17 - 18 -> Senior High School
1. start
2. int age; Scanner scan = new Scanner(System.in);
3. System.out.print (“Input your age: ”);
4. age = scan.nextInt();
5. if (age <=12)
a. System.out.print (“Elementary Level”);
b. if (age <=16)
i. System.out.println(“Junior High School Level”);
c. else
i. System.out.println (“Senior High School
Level”);
6. end
Pseudocode
Sample 6: 1. start
2. int ctr;
Problem: Write a 3. for (ctr=1; ctr<=10; ctr++)
pseudocode that will print a. {
your name ten times. i. System.out.print
(“Luffy”);
b. }
4. end
Pseudocode Sample 7:
Problem: Write a pseudocode that will display the sum of five (5)
inputted numbers (using counter).
1. start
2. int x, ctr, sum; Scanner scan = new Scanner(System.in);
3. for (ctr=1; ctr<=5; ctr++)
a. {
i. System.out.print (“Input an integer: ”);
ii. x = scan.nextInt();
iii. sum = sum + x;
b. }
4. end
What is a flowchart?
▪ is a schematic representation of an algorithm or a
stepwise process, showing the steps as boxes of various
kinds, and their order by connecting these with arrows.
▪ used in designing or documenting a process or program
▪ Also know as flow diagram
▪ a graphical representation of a process or system that
details the sequencing of steps required to create output
▪ is a picture of the separate steps of a process in
sequential order.
Flowchart Symbols
Terminals

The terminal is used to


represent the start and end of
a process.
Flowchart Symbols
Preparation Symbol

The preparation symbol


represents the variables that
will be altered or modified
such as counter.
Flowchart Symbols
Input / Output Symbol

The input / output symbol


indicates an input and output
operation
Flowchart Symbols
Process Symbol

The process symbol represents any step


in the process you’re diagramming and
is the workhorse of the flowchart
diagram. Use rectangles to capture
process steps like basic tasks or actions
in your process. It also indicates a
process such as mathematical
computation or variable assignment.
Flowchart Symbols
Decision Symbol

The decision symbol


represents a decision in the
logic involving the comparison
of two values. Make sure that
you capture each possible
choice within your diagram.
Flowchart Symbols
On-Page Connector Symbol

The on-page connector allows you to


connect two flowchart segments within
the same page
Flowchart Symbols
Off-Page Connector

The off-page connector allows


you to connect two flowchart
segments from one page to
another
Flowchart Symbols
Flowlines

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

Problem: Draw a flowchart


int num = 19;
that display the content of
a variable.
Display num

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

You might also like