Computer Programming

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

COMPUTER PROGRAMMING 1.

Analyzing the problem


- Identify the problem specifications and define
Introduction to Computer Programming each program input, output and processing
components.
What is Computer?
2. Designing the program
An electronic device designed to manipulate data so that useful - Plan the solution to the problem; come up with
information can be generated. It is composed of hardware and logical sequence of precise steps that solve the
software: problem by applying programming tools such as
algorithm, pseudocode, decision tables, structures
Hardware – The tangible parts of computer. charts and flowchart.
3. Coding the program
Software – The non-tangible parts that are to be
- Translate the algorithm into specific
installed in the computer to command the hardware to
programming language.
function and to help the users accomplish their task
- Programmers must follow the language rules,
and can be categorized as:
violation of any rules causes errors. The errors
 System Software – e.g. Wndws 10, Android OS, IOS must be eliminated before going to the next step.
 Utility Software – e.g. Windows Defender, Norton 4. Testing and debugging the program
Anti-Virus etc. - After removal of syntax errors, the program will
 Application Software – e.g. MS Word, Information execute. However, the output of the program may
System, POS etc. not be correct.
5. Documenting the program
- This step is intended to allow another person or
What is a Computer Program? the programmer to understand the program at a
later date.
 It is collection of instructions or statements (also
- This can also include a detailed description of
called code) that tell the computer what to do.
what the programs does and how to use the
 It is written or programmed using a programming
program or what we all know as manual.
language.
6. Deploying and maintaining the program
“Without computer programs, computers are useless” - The program is deployed (installed) at the user’s
site and the program is kept under watch till user
gives a green signal to it.
What is Programming Language? - Even after the software is completed, it needs to
be maintained and evaluated regularly.
These are programs used by the programmers to create
programs or software. It allows you to design the Graphical In software maintenance, the programming team fixes
User Interface (GUI) of the program and add instructions program errors.
(codes) on it.
Coding: The technical word for writing the program.
A programming language will translate the human readable
code (English) into a machine-readable language (binary) and Testing: The process of finding errors in a program.
compile it for a single application.
Debugging: The process of correcting errors found.

What is Programming?
Types of Errors:
Designing or creating a set of instructions to ask the computer
1. Syntax errors – Occurs when the code violated the
to carry out certain jobs which normally are very much faster
syntax or the grammar of the programming language.
than human beings can do. The computer does what the
2. Logical errors – A mistake that the programmer made
program tells it to do.
while designing the solution to a problem.
It is the process of planning a sequence for a computer to
Syntax and logical errors are collectively known as bugs.
follow.

“A good programmer is a good planner”


Algorithm and Pseudocode
Program Development Life Cycle (PDLC) Programming Algorithm
 A set of steps that guides computer programmers A set of instructions or rules to be followed by a computer
through the development of a program. program which contains an Input, Process, and Output.
 A systematic way of developing quality software.
Variables Changing the value of a variable

In Programming - A letter or word that serve as a temporary In many programming languages, variables are statically
storage that can represent any value. typed, meaning they are declared with a specific type that can't
change during their lifetime.
Pseudocode In contrast, Python uses dynamic typing, allowing variables to
be assigned and reassigned to different data types without
A method that allows a programmer to represent the algorithm
restriction.
in a more programming related way.
Variables are used to store up data for later use.
It is also called as false codes because it tend to look like a
programming language but can still be understood by a person
that has little understanding in programming. Common Datatypes:
Examples:  String – Texts
 Integer – Positive and Negative Numbers (No
1. Let numOne = 0, numTwo = 0, and sum = 0
decimal)
Input numOne and numTwo
sum = numOne + numTwo  Float – Decimal numbers
Output sum  Character – Single letter or symbol
 Boolean – True/False
2. Let num = 0
Input num
Identifiers – The name of the variable which the user choose.
If num is an Even number
output “Even” Syntax:
If num is an Odd number (identifier = value)
output “Odd” firstName = “Computer”
LastName = “Programming”

Introduction to Python print() - Used to display something in the console.

Python Language Syntax:


print(variable)
 Developed by Guido van Rossum
 Easiest language to understand input() - Used to make the user input something in the console.
 Indentation is very important Syntax:
 Very short syntax variable = input()
 No semicolon needed variable = input(“Enter Something: ”)
Overview:
Casting Variables - A technique used to convert a datatype to
C#  Console.Wrtite(“Hello World”);
another datatype.
JAVA  System.out.print(“Hello World”); Syntax:
PHYTON  print(“Hello World”) Convert Numbers to String
 str(number)
Convert String to Numbers
Creating a Variable
 int(string)
Creating a variable and assigning a value  float(string)

 We can assign a value to the variable at that time


variable is created. We can use the assignment Arithmetic Operations - Used to perform mathematical
operator = to assign a value to a variable. operations inside our programming language.

Example:
Examples: Conditional Operators - Used to compare values inside of
conditional statements.
1. Create a program that will display the sum of 2
numbers inputted by the user.

num1 = float(input("Enter the first number: "))


num2 = float(input("Enter the second number: "))
sum = num1 + num2
print("The sum of two number is ", sum)

2. Create a program that will compute for the general


average of the four major exam of the student If Statement - Dealing with one condition.
prelim, midterm, semi and final. Display the name Example:
and general average of the student. if age >= 18:
print("Legal age")
p = float(input("Enter the average of prelim: "))
m = float(input("Enter the average of midterm: "))
If-Else Statement - Dealing with two conditions.
s = float(input("Enter the average of semi-final: "))
Example:
f = float(input("Enter the average of final: "))
if age >= 18:
ave = (p + m + s + f) / 4 print("Legal age")
name = input("Enter the student's name: ") else:
print("The general average of the student is ", ave) print("Minor")

3. Create a program that will compute for the gross If-Elif-Else Statement - Dealing with three or more conditions.
pay of employees. Input the rate per hour, number Example:
of hours worked, name and position of the if age >= 18:
employee. Display the name, position and gross print("Legal age")
pay. elif age >= 13:
print("Teenager")
name = input("Enter the employee's name: ") else:
pstn = input("Enter the position of the employee: ") print("Too young")
rph = float(input("Enter the rate per hour: "))
hw = float(input("Enter the number of hours worked: ")) Nested Conditional Statement – Dealing with conditions inside
gp = rph * hw a condition.
print(name) Example:
print(pstn) if age >= 18:
print("The gross pay of the employee is ", gp) if height >= 170:
print("Legal age and tall")
elif height >= 156:
Conditional Statements print("Legal age and average")
A statement that makes the program smarter, it makes the else:
program decides on what to do in certain condition. print("Legal age and short")

 IF statement (one condition)


 IF-ELSE statement (two conditions) Logical Operators - Used to include two or more conditions in
 IF ELIF-ELSE statement (three or more conditions) one line.
 Nested conditional statements (condition after a  AND - Both condition must be true.
condition)  OR - Either condition must be true.
Indentation
It is used to indicate what statements are included inside the
conditional statement.
Example: Flowchart - A method that allows a programmer to represent
1. Make a program that will determine whether the the Algorithm in a diagram or an illustration.
difference of two numbers is positive and negative.
Display the difference and remarks. It represents the sequence of a programming algorithm by using
standard graphic symbols that will represent the Input, Process
x = int(input("Enter the first number: ")) and the Output.
y = int(input("Enter the first number: "))
dif = x - y Advantages:
if dif < 0: 1. Since flowcharts are language independent, they
print(x, "-", y, "=", dif) can be learned and applied without formal
print("The result is negative.") knowledge of a programming language.
elif dif > 0: 2. It enforces users to give attention to significant
print(x, "-", y, "=", dif) matters over the less significant ones.
print("The result is positive.") 3. Flowcharts are easier to understand than a
else: program written in a particular programming
print(x, "-", y, "=", dif) language.
print("The result is zero.") Limitations:
1. Flowcharts do not represent a programming
2. Create a program that makes the user input 3 language and are more of a person-to-person than
grades, so that the system could average it then person-to-computers means of communication. A
check if the grade is: computer cannot accept a program describe in
>100 or <=50 - Invalid Grade flowcharting form.
98-100 – With Highest Honor 2. Certain details often require along sequence of
95-97 – With High Honors interconnected symbol which could easily be
90-94 – With Honors described in just a few lines of explanations.
75-89 – Passed 3. It does not convey why a given set of operation is
74-51 – Failed made.

g1 = float(input("Enter the first grade: ")) Type of Flowcharts


g2 = float(input("Enter the second grade: "))
1. Program Flowchart
g3 = float(input("Enter the third grade: "))
A program flowchart visually details the logical steps
ave = (g1 + g2 + g3) / 3
and sequence of operations needed to transform data
print(ave)
into the desired output.
if ave >100 or ave <=50:
print("Invalid Grade.") 2. System Flowchart
elif ave >=98 or ave == 100: A system flowchart shows how data moves through a
print("With Highest Honors!") system, highlighting the media, hardware, and
elif ave >=95 or ave == 97: personnel involved. It focuses on the flow of data
print("With High Honors!") between components rather than the specific
processing steps.
elif ave >=90 or ave == 94:
print("With Honors!")
Basic Symbols of Flowchart
elif ave >=75 or ave == 89:
print("Passed!")
else:
print("Failed.")

Algorithm and Flowchart


Programming Algorithm - Set of instructions or rules to be
followed by a computer program. Which should contain an
Input, Process and an Output. Depending on the problem to
be solved.
 Ellipse – Terminal Symbol
Used to designate the beginning and the end of a
program, or a point of interruption.
 Circle – On-Page Connector Symbol
Non-processing symbol which is used to connect one
part of a flowchart to another without drawing
flowlines.
 Diamond – Decision Symbol
Denotes a point in the program where more than one
path can be taken.
 Parallelogram – Input or Output Symbol
Represents an instruction to an input or an output
operation.
 ----- - Off-Page Connector Symbol
Used to connect flowchart portion on different page.
 Rectangle – Processing Symbol
Represents a group of program instructions that
perform a processing function of the program such as
to perform arithmetic operations, or to compare, sort,
etc.
 Arrows – Flowlines Symbol
Used to show reading order or sequence in which
flowchart symbols are to be read.

Example of Flowchart:

Notations used in Flowcharting

You might also like