0% found this document useful (0 votes)
24 views33 pages

Lesson 1 and 2 Computer Programming 1

Programming lecture

Uploaded by

ssamdogss
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
24 views33 pages

Lesson 1 and 2 Computer Programming 1

Programming lecture

Uploaded by

ssamdogss
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 33

Lesson 1

Cycle/Programming
ConceptProgrammin
g
1. Defining the problem (planning)
. The first step in defining a problem begins with
recognizing the need for information. The problem is
thoroughly analyze in order to determine what is required for
its solution. To understand and analysing the problem we
must conduct a study to the nature of the problem and must
define what are necessary outputs required of the program.
2. Designing a Solution
When the problem is defined properly, we can
start designing the solution to the
problem. In designing the solution, we must be able
to breakdown the problem into
several steps so that it is easier for us to solve the
problem in small pieces. This
sequence of steps for the solution to the problem is
called an Algorithm.
3. Writing the Program
After the programmer has defined the problem and
designed a solution, the next step is to write the program
in a specific programming language.
4.Compiling the Program
The instructions written in a programming
language such as C must be translated into machine
language before they can be executed.
5. Debugging the Program
In computers, debugging is the process of locating
and fixing or bypassing bugs (errors) in computer
program code or the engineering of a hardware device.
6. Testing the Program
It is the process of checking if a program actually
performs its functions as planned
7. Documentation of the program
Documentation consists of written descriptions and
explanations of programs and other materials
associated with an organization’s data processing system.
Documentation of a system and a program designs are
one of the most important requirements for success in data
Input- Process-Output
There are three veryCycle
common terms that are linked to
each other. They describe particular stages in
information handling. They are:

1. Input
Data has to flow into the system in some form.
Input is the data flowing into the system from outside

Example:
 A thermometer linked to the system provides data on
raw temperatures
 A financial service provider sends a stream of current
share prices to your computer
 A newspaper takes a news feed from a news wire
2. Processing
This will be the second stage where the information
flow is the input data being manipulated in some way. It is
the action of manipulating the input into a more useful form.

Example:
 The newspaper takes the pure text obtained from the news
wire service and creates a front page layout using pictures
and formatted text.
 The keystrokes being entered by the typist is converted into
ASCII format that the computer can understand.

3. Output is the information flowing out of the system. The


final stage in the information flow is normally to present the
information in a user-friendly way.
Example:
FLOWCHART
It is a tool for analyzing processes. It shows
arithmetic and logical or procedures required in solving a
computer problem. Special symbols are used to show
procedures. Symbols are connected to each other by
directional arrows that indicate the sequence of operations
as they are to be performed by the computer. Each
symbol represents a particular function and English terms
that shows the operation or activity represented by the
symbol.

PSEUDO-CODE
It is the art of expressing a program in a
short English phrases that is used to explain specific tasks
within a program’s algorithm. It should be written as a list
of consecutive phrases and indentation can be used to
show the logic in pseudo-code or the looping process.
Sample using flowcharting symbols
BASIC SYMBOLS USED IN
FLOWCHARTING
Terminal Symbol/Block
The terminator symbol marks the staring or
ending point of the system. It usually contains
the work “start” or “end”.

Preparation/Initialization/Housekeeping Block
It is used to select condition to be initialize.

Input/output Block
It represents material or information entering or
leaving the system.

Action/Process/Sequence Block
A box can represent a single step, or and entire
sub-process within a larger process. It can
perform also any calculations to be done.

Flowlines
It signifies the process that is to be executed
next.
On Page Connector

It shows the entry or the exit point of the


flowchart
Decision Block
It signifies any decisions that are to be done.

Off page connector


It designates entry to or exit from one page when
a flowchart requires more than one page
Showing the flowchart and pseudo-
code in a borrowing a book
Elements of Style in Programming
The elements of style are much essential in the world of programming.
As a rules
in programming style, first understand clearly the problem then paraphrase
it like those
English statements and mathematical problems that were broken into
parts. Try to
identify what the problem is asking for then provide possible solutions.
Make use of what
you have listed then decide what key you will use to work your program
out.

The following is the sample outline.


Guidelines for a Well – Drawn Flowcharts

 Every flowchart has a Start and a Stop symbol.


 The flow of sequence is generally from the top of the
page to the bottom of the page. This can vary loops
which need to flow back to an entry point.
 Use arrow-heads on connectors where flow direction may
not be obvious.
 There is only one flowchart per page.
 A page should have a page number and a title
 A flowchart on one page should not break and jump to
another page
 The flowchart should be clear, neat and easy to follow
 The usual direction of the flow of a procedure or system
is from left to right or top to bottom
BASIC CONTROL STRUCTURES /
FORMS OF PROGRAM FLOW

Program Flow refers to the order in which


the individual statements, instructions or
function calls of an imperative or
functional program are executed or
evaluated. There are :
3 types of forms of program flow

1. Sequence – process is executed from


one to another in a straightforward manner.
https://www.youtube.com/watch?v=_1xT4zV8mKQ
2. Selection (branching) a choice is
provided between two alternatives. Using
a test to decide between alternative
sequences.

The logical expression is evaluated as


True or False. If the expression is
TRUE, a statement is executed. Then
the next statement in the program
sequence is executed unless
statement transfers control. If the
expression is FALSE, statement is not
executed. The next statement in the
program is executed.
https://www.youtube.com/watch?v=vOEN65
nm4YU
https://www.youtube.com/watch?v=AlEBMhx
reo0
https://www.youtube.com/watch?
v=r1BpraNa2Zc
3. Repetition ( looping) –
Repeating a sequence of
statements until some
condition is met.

https://www.youtube.com/watch?v=_1xT4zV8mKQ
1. Draw a flowchart that compute the grade of the student based on three grading system prelim is 20%, Midterm is 30% and final is 50%
Average grade = ( prelim + midterm + final))/3
Limit 8 detail lines per page
Test the average grade to get the Remark
Grade Remark
<= 3.0 Passed
<= 3.5 Incomplete
<=5.0 Failed

Output: should be like this

ABC University
Philippines

Student Name Prelim Midterm Final Average Grade Remark


_________ ____ ______ _____ ___________ ________
_________ ____ _____ _____ ___________ ________
2. Draw a flowchart that print the account name, class code, old balance, deposit, withdrawal and new balance
Compute new balance =( old balance+deposit) - withdrawal
Limit 10 detail lines per page
Test the Classification Code
Class Code Classification
1 Preferred Client
2 Regular Client
3 Walk in Client

PSV Bank of Commerce


Philippines

Account Name Classification Old Balance Deposit Withdrawal New Balance


___________ _________ _____ ________ __________ __________
___________ _________ _____ ________ __________ __________
Lesson 2
COMPUTER

• The meaning of computer derived from Latin


word “computare” which means to calculate. It
is an electronic device capable of performing
arithmetic or making logical operation in
accordance with a procedural
instructions(program) to produce a meaningful
information (output).

• It is a machine or device that performs


processes, calculations and operations based
on instructions provided by a software or
hardware program. It has the ability to accept
COMPUTER PROGRAMMING
It is often called coding. It is the
process of writing, testing, debugging and
maintaining the source code of computer
programs.

COMPUTER PROGRAM
Known as software program. It is a
structured collection of instruction to the
computer.

COMPUTER PROGRAMMER
A professional/ individual who writes
program.
BRIEF HISTORY OF TURBO C
LANGUAGE
C is a general-purpose computer
programming language developed in 1972 by
Dennis Ritchie at the Bell Telephone Laboratories
to implement the UNIX operating system. Although
C was designed for writing architecturally
independent system
software, it is also widely used for developing
application software.

C is the first or second most


popular language, behind Java, in terms of
number of developer positions or publicly available
code. It is widely used on many different software
Data Types of C program

1. char – character used to hold characters


2. float – used to hold real numbers (32)
3. double – used to hold real numbers (64)
4. void –value less
5. int – whole numbers

Terminologies
Keywords are reserved words that have special meaning
ex.
Auto, break, double, int, case
•Identifiers- are composed of a sequence of letters, digits and
the special character _ (underscore). Limit the identifiers from
8 to 15 characters long.
Rules for defining variables

1. It must consist only letters, digits and underscore.


2. It should not begin with a digit.
3. An identifier defined in the c standard library
should not be redefined.
4. It is case sensitive, meaning uppercase is not
equal to the lowercase
5. Do not include embedded blanks.
6. Do not use any of the C language keywords as
your variable/identifier.
Variable Declaration all variables
must be declared first before they
may be used.

Types of variables declaration


1. Local variable declaration are
declared inside a function.
EX.
#include <stdio.h>
int main
{
int a,b,c; local variables
_________;
_________;
}
2. Global variables – are declaring them
outside of any function.
EX.
#include <stdio.h>
int a,b,c; global variables

int main
{
_________;
_________;
_________;
}
Constants – are
identifiers/variables that can store
a value that cannot be changed
during program execution.

Operator is a symbol that tells


the compiler to perform specific
mathematical or logical
manipulations.
1. arithmetic operators like + , -,
*, /, ++,--
Here is a table which illustrates the use of escape sequences in C:
•\n (New line) – We use it to shift the cursor control to the new line
•\t (Horizontal tab) – We use it to shift the cursor to a couple of spaces
to the right in the same line.
•\a (Audible bell) – A beep is generated indicating the execution of the
program to alert the user.
•\r (Carriage Return) – We use it to position the cursor to the beginning
of the current line.
•\\ (Backslash) – We use it to display the backslash character.
•\’ (Apostrophe or single quotation mark) – We use it to display the
single-quotation mark.
•\” (Double quotation mark)- We use it to display the double-quotation
mark.
•\0 (Null character) – We use it to represent the termination of the
string.
•\? (Question mark) – We use it to display the question mark. (?)
•\nnn (Octal number)- We use it to represent an octal number.
•\xhh (Hexadecimal number) – We use it to represent a hexadecimal
Important symbols

\n - is a line char used to move the cursor


to the next line.
‘ ‘ – is a single quote is used for single
character/letter.
“ “ double quote is used for two or more
character
{ - open curly brace signifies begin
} – close curly brace signifies end
& - address operator
Structure of a simple C program

1. #include directive – contains information


needed by the program to ensure the
correct operation of C standard library
functions.
2. #define directive – used to shorten the
keywords in the program.
3. Variable declaration section – it is the
place where you declare your variables.
4. Body of the program = starts by typing
main() and the { and } . All statements

You might also like