Unit-1 Intro To Programming - Edited PDF

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

UNIT 1: Basic Programming Concepts

UNIT

1 Introduction to
Programming

The nature of computer programming shall be


defined, as well as the different terminologies
related to it. The various programming languages
used in computer programs, skills required for
programming, and tips on choosing a
programming language will be presented.

An understanding of the algorithm as the basis for


the program flow will be introduced. Also, there
will be a basic introduction to common program
errors.

The programming processes and methodologies


are being presented straightforwardly to prepare
the students in understanding the programming
concepts.

1
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

PRETEST FOR UNIT 1

WHAT DO YOU ALREADY KNOW?

Name: __________________________________ Date: ____________________


Course & Section: ________________________ Result: __________________

Read each item carefully, then circle the letter that best represent your answer.

1. Which of the following do you think is the native tongue language of a computer?
This language instruction is a binary string of 0’s and 1’s that specifies an operation
and identifies the memory cells involved in the process.
a. Assembly language

b. Machine Language
c. Low-level language

d. High-Level language

2. This type of flowchart is a graphic representation of the procedures involved in


converting input media data to data in the output form. It illustrates which data is
used or produced at various points in a sequence of operations. Which of the
choices below is being referred to?

a. Process Flowchart
b. Program Flowchart

c. System Flowchart
d. Scientific Flowchart

2
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

3. TRUE or FALSE. C++ program was developed by Bjarne Stroustrup, starting in


1979 at the Bell Labs in Murray Hill.
a. True

b. False

4. Which of the following choices below is a list or rundown of steps for solving a
problem in C++ programming? It requires the programmer to write the step-by-step
method or procedure and then verify that it solves the problem as intended.

a. Flowchart
b. Algorithm

c. Constant
d. Variables

5. The following is a mathematical operator that uses in C++ programming that


performs separation, but instead of rather the quotient, it returns the remainder?

a. Operand
b. Multiplication

c. Exponent
d. Modulus

6. Who is in-charge of designing/creating codes, tests, debugs, and documents a


computer program?

a. Computer Technician
b. Computer Analyst

c. Computer Programmer
d. Computer Specialist

7. In constructing a C++ program, using a “comment” gives additional useful


information inside a program. Is this statement True or False?
a. True

b. False

3
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

8. Which of the following is a program statement that checks an expression that may
or may not perform a statement or group of statements?
a. Conditional Expression

b. Conditional Execute
c. Conditional Statement

d. Conditional Symbol

9. The following selections you see below are a C++ programming language that can
deliver little or no abstraction from the computer's instruction command of set
architecture.

a. Machine Language
b. Low-level language

c. High-Level language
d. Assembly language

10. This is a type of a low-level programming language in which each program


statement corresponds to an instruction that the microprocessor can carry out.

a. Machine Language
b. Low-level language

c. High-Level language
d. Assembly language

4
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

LESSON 1:
Basic Programming Concepts

OBJECTIVES:
At the end of the lesson, students will be able to:

 Explain what a program is.

 Differentiate the categories of programming languages

 Identify the different steps in program development.

DURATION: 2 hours

5
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Introduction
Think about some various ways that people use computers. Each student uses
a computer to do some different tasks in school, such as typing a document, searching
for articles, sending an email, and participating or giving contributions in an online
class. At work, individuals use PCs to analyze data, make presentations, conduct
business transactions, communicate with colleagues and customers, control
machines in manufacturing facilities, and do numerous different things. At home,
individuals use PCs for various tasks such as paying bills, shopping online,

Figure 1. Microsoft Word and Adobe Photoshop. An example of Word Processing and Image Editing Program

communicating with friends and family, and of course, playing games.

Figure 1. shows screens from two usually used computer programs, Microsoft Word ,
and Adobe Photoshop. Microsoft Word is a word processing program that lets you
create a document, edit a document, and print documents with a personal computer.
Adobe Photoshop is an image editing or editor computer program that will enable you
to work with vivid images, such as photos taken with your mobile phone and digital
camera.

What is Computer Programming?

A computer program is a set


of instructions written in a
programming language that a
computer can execute. Computer
programs are designed to perform
specific tasks. Programmers write
these programs refers to the person
who plans or creates, codes, tests,
debugs, and documents a computer Figure 1.1. A Computer Programming Clipart
program. Programming requires Source: https://www.freecodecamp.org/

more than just the knowledge of a programming language. In effect, programmers


spend most of their time in planning solutions before they start writing the source code
for the program.

6
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Computer Programming

 Computer programming is defined as the art and science of designing a


program. Programming is the process of providing instructions for the
microprocessor.
 Computer programming is an evolving process of designing and constructing
executable computer programs to achieve a specific computing result.

The programming stages include design, or deciding what the program should
accomplish, and coding, which refers to the use of a programming language to express
the program logic in computer-readable form.

Let us take making a cup of tea as an example.

How will you make a cup of tea?

If you were to give instructions on making a cup of


tea, it would look like the following:

1. Boil some water


2. Pour hot water in a cup with a teabag
Figure 1.2. Computer Programmer 3. Let the tea brew
Source: https://www.freecodecamp.org/ 4. Remove the teabag
5. Add milk and sugar (if desired)

What we take to arranged is that the message with a human being is different than
communicating with any computer. A person has prior knowledge and life experience;
they know where to find the tea; they know that the milk is stored in a fridge or where
it is kept.

Categories of Programming Languages


Like many natural languages, we use to communicate with each other. There
are many languages that a computer programmer can use to speak with a computer.

Each programming language has its own set of words and rules, called the
syntax of that language. If you are working on writing a computer program, you have
to follow the syntax of the language you are using; otherwise, you would not be
understood.

7
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Machine Language

The native tongue of a computer is the


machine language. Each machine language
instruction directs a binary string of 0’s and 1’s that
stipulates an operation and classifies the memory
cells involved in the process.

Source: https://dfarq.homeip.net/

Example:

SUB AX, BX = 00001011 00000001 00100010, is an instruction set to subtract the


values of two registers AX and BX.

In the starting days of programming, the program was only written in


machine language. Each and every program was written as a sequence of binaries.

A computer programmer must have knowledge about the architecture of the particular
machine before programming in machine language. Developing programs using
machine language is a tedious job. It is challenging to recall the arrangement of binary
numbers for different computer architecture. Therefore, it is not much in practice.

Low-Level Language

A programming language that runs a little


abstraction from a computer's instruction set
architecture. The word " low " states to the small or
nonexistent volume of abstraction among the
language and machine language. Because of this, low-
level languages are sometimes labeled as being "
close to the hardware."
Low-level language does not essentially need
the compiler or an interpreter to run. The computer
Source: https://www.techdotmatrix.com/
processor in a programming language is written in a
suitable to run the code without using either of these.
Advantages of low-level languages

 Programs in a computer established using a low-level language is fast and


memory efficient.
 Programmers can apply processor and memory in an okay way using a low-
level language.
 Computer programs do not need any compiler or interpreters just to translate
the source code to machine code. Therefore, it cuts the compilation and
interpretation time.
8
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

 Low-level languages offer direct manipulation of computer registers and


storage.
 It can directly communicate with hardware devices.

Disadvantages of low-level languages

 Programs developed using a low-level language are computer machine-


dependent and not portable.
 It is challenging to develop, debug, and maintain.
 Low-level programs are more error-prone.
 Low-level programming typically results in faulty programming output.
 The programmer must have additional knowledge of the computer architecture
of a particular machine, for programming in a low-level language.

High-Level Language

The computer would have no difficulty


understanding the machine language instructions,
but the typical programmer will never be able to read
or understands it. To create a program that can be
understood is easily by programmers, language
designers (the one who designs programming
languages) and other language implementers (a
person or group of people who develops computer-
programming languages) set high-level languages
that enable the standard programmer to write
computer programs using instructions that resemble
Source: https://www.techdotmatrix.com/
everyday language.

Advantages of High-level language

 The high-level languages are computer programmer-friendly. Which it is easy


to write a program, debug a program, and maintain a program.
 It carries a higher level of concept from a computer machine language.
 Computer machine-independent language.
 Easy to gain knowledge or to learn.
 Fewer error-prone, easy to find a code, and debug errors in a program.
 The high-level programming language gives results in improving computer
programming productivity and efficiency.

Disadvantages of High-level language

 It takes additional translation times to translate the source to machine code.


 High-level programs are comparatively slower than low-level programs.
 Compared to low-level programs, they are generally less memory efficient.
 It cannot communicate directly with the hardware.

High-level languages, such as *COBOL, VISUAL BASIC, JAVA, etc. are some
of the popular languages used by the programmers. It is named high-level languages
to distinguish them from the machine and symbolic languages. It is also called
compiler languages since these languages require a unique program called a
9
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

compiler, which translates programs written in a particular language into a machine


language. When these languages are used, a compilation run is required before data
can be processed. The unique program written in a high-level language is called the
source program, and its translation in machine language is named an object program.

Here are the examples of Programming Languages

Language Description
Ada was developed in the 1970s,
Ada primarily for applications used by the
U.S. Department of Defense. This
computer language is named honor of
the “Countess Ada Lovelace" it is a
meaningful and vital historical symbol in
computing.
Beginners All-purpose Symbolic
Instruction Code is a general purpose-
BASIC language initially an outline designed in
the early 1960s to be straightforward
adequate for beginners to gain
knowledge. Nowadays, there are many
different versions of BASIC.
FORmulaTRANslator was the first high-
FORTRAN level programming language. It was
originally developed in the 1950s to carry
out complex arithmetic or mathematical
calculations.
Common Business-Oriented Language
COBOL was developed in the 1950s and was
designed for business applications.
Pascal was created in 1970 and was
Pascal initially designed for teaching computer
programming. The language was named
under the mathematician, physicist, and
philosopher Blaise Pascal.
C and C++ (it is pronounced as a "c plus
C and C++ plus"), and it is a powerful, general-
purpose computer language developed
at the Bell Laboratories. The C language
was developed in 1972, and the C++
language was developed in 1983.
Pronounced “c sharp. “This language
C# was created by Microsoft around 2000

10
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

for developing applications based on the


Microsoft.NET platform.
Java was created and developed by the
Java Sun Microsystems in the early 1990s. It
can develop programs that run on a
single computer or over the Internet from
a Web server.
JavaScript, crated in the 1990s, can be
JavaScript used in Web pages. Regardless of its
name, JavaScript is not related to Java.
Python is a general-purpose language
Python developed in the 1990s. It has gotten
become widely famous in business or in
e-commerce and an academic
application.
Ruby is a general-purpose language that
Ruby was developed in the 1990s. It is
gradually becoming a famous language
for programs that run on Web servers.
Visual Basic (commonly known as VB) is
Visual Basic a Microsoft programming language that
allows computer programmers to create
Windows-based applications quickly. VB
was initially created in the early 1990s.

Assembly Language

This is a type of a low-level programming language in which each program


statement corresponds to an instruction that the microprocessor can carry out.
Assembly language is thus specific to a given processor. After writing an assembly
language program, the programmer must use an assembler particular to the processor
to interpret the assembly language into machine code. An assembly language
provides precise control of the computer, but assembly language programs written for
one computer type must be rewritten to operate on other classes. An assembly
language might be used instead of a high –level language for any of these three
primary reasons; speed, control, and preference. The program written in assembly
language run faster than those generated by a compiler. The use of an assembly
language allows the programmer to interact directly with the hardware, including the
processor, memory display, input/output ports.

A high-level programming language separates the execution of computer


architecture from the requirement of the program. It makes the process of developing
a computer program much simpler and more understandable.

Now we could say that high-level languages are a lot easier to understand over
low-level languages. Let us take a look at the example below:

Let us say we want the value of a memory cell to be equal to number fifteen
(15). In a high-level language, we could simply accomplish this by writing: int x = 15;

11
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

where:

int (based from the dictionary word integer is a reserved word used to identify
the data type of a number equal (=) sign ( a generally accepted mathematical symbol)
is used to denote an equation process, 15 is simply the decimal value of the number
we wanted to be in a memory cell, x is any valid variable representing the computer
memory cell.

In assembly, we may write this by using the statement:


MOV Bx, Of or MOV Bx, IIII
where:

MOV is an instruction telling the processor to equate the value of the computer
memory (base memory – Bx) to OOFh in hexadecimal or IIII in binary (decimal
equivalent of 15)

Mnemonics are shortened English words that are used to stipulate a computer
instruction. Each special education in a binary code has a specific mnemonic. They are called
architecture-dependent, and there is a list to separate mnemonics for different computer
architectures.

Examples mnemonics are - ADD, MOV, SUB, etc.

Advantages of Assembly Language

 It allows more intricate jobs to run in a manageable way.


 It is memory efficient, which needs less computer memory.
 It is faster as its execution time is less.
 It is a hardware-oriented.
 It only requires less instruction to get the result.
 It is used for critical jobs.
 It is not required to keep track of memory locations.
 It is a low-level embedded system.

Disadvantages of Assembly Language

 It takes more time and effort to write the code for the same.
 It is very complex and challenging to understand.
 The syntax is difficult to remember.
 It has a lack of portability computer programs among different computer
architectures.
 It needs more size or memory of the computer to run the extended programs
written in Assembly Language.

12
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Compilers and Interpreters

As we learned in the previous section, the computer understands the program


only if it is coded in its machine language. In this segment, we explain the procedure
for turning a program written in a high-level language into machine language. Because
the computer can understand only machine language instructions, programs that are
written in a high-level language must be translated into machine language. Once a
plan has been reported in a high-level language, the programmer will use a compiler
or an interpreter to do the translation.

A compiler is required to translate a program written using a programming language


into a machine-readable form or known as binary code) before you can run the
program on your machine. While translation is finished, the binary code can be saved
or kept into an application file. It can stay successively run the application file without
using a compiler unless the computer program (source code) is rationalized updated,
and then you have to recompile it. The binary code or application file is also called
executable code (or an executable file).

Figure 1.3. Working with Compiler and Interpreter


Source: https://www.programiz.com

On the other hand, an interpreter to translate the high-level instructions into machine-
understandable instructions (binary code) at runtime. A computer programmer cannot
run the computer program on a machine except if the right interpreter is available.

INTERPRETER COMPILER
Scans the whole computer program and
Translates the program one statement
translates it as an entire into machine
at a time.
code.
Interpreters typically take a small
Compilers typically take a massive
amount of time to examine the source
amount of period to analyze the source
code. However, the general
code. But the available execution time is
implementation time is comparatively
reasonably faster than interpreters.
slower than compilers.
It generates the middle object code,
None intermediate object code is
which further needs linking. Thus it
generated, thus a memory efficient.
requires more memory.

13
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Programming languages like


Programming languages like C, C++,
JavaScript, Python, Ruby use
Java use compilers.
interpreters.

However, there is nothing intrinsic to a compiled language to prevent someone


from providing an interpreter for the language; likewise, people can often write
compilers for interpreted languages. It is not common to combine the two flavors of
languages, where a programmer compiles source code into a small binary file, which
is then executed by a runtime interpreter.

It is the job of the computer programmer to write and test the program. There
are four steps in this process:
(1) writing and editing the program,
(2) compiling the program,
(3) linking the program, and
(4) executing the program.

 Writing and Editing Programs

This is the process of developing and modifying source code - the name given to
the program instructions you write. Some C++ compilers come with a precise editor
that can deliver a lot of support in managing your computer programs. An editor often
provides a complete environment for writing, collecting, developing, and testing your
programs. This is sometimes called an integrated development environment, or
IDE.

You can also use some other editors to create your source files, but they must store
the code as plaintext without any extra formatting data embedded in it. Overall, if you
have a compiler system used and with an editor indicate, it will give a lot of features of
attributes that make it easier to write and organize your source code programs. There
will usually be automatic facilities for placing out the program text correctly, and color
highlighting for main essential language elements, which not only makes your code
more readable, also provides a clear indicator when you make errors when inputting
in such words.

On a Personal Computer, you could use one of the numerous free software and share
software computer programming editors. These will provide a lot of help in ensuring
your code is correct with syntax highlighting and auto indenting of your code. Try not
to utilize a word processor, for example, Microsoft Word, as these are not appropriate
for delivering a program code in light of the extra formatting information they store
beside the text. Purchasing one of the professionally developed programming
development environments which support C++, such as Borland or Microsoft, in which
case you will have pervasive editing capabilities. Before parting with your cash,
though, it is a good idea to manage that the level of C++ that is supported is
approximate to the current C++ standard.

 Compiling Programs
14
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

The compiler converts your source code into machine language and distinguish and
reports the errors in the compilation process. The input to this phase is the file you
produce during your editing, usually referred to as a source file.

The compiler can classify a broad scope of errors as a result of invalid or


unrecognized program code, just as structural errors where, for instance, some portion
of a program can never be carried out. The output from the compiler is also known as
the object code and is kept in files called object files, which are usually named with
the extension .obj in the Microsoft Windows environment. The outcome of a successful
compilation is a file with a similar name as that utilized for the source file, however,
with the .o or .obj extension.

 Linking Programs

The linker gives numerous modules generated by the compiler from source
code such as files, adds required code modules from program libraries supplied as
part of the C++ programming, and bonds everything into an executable whole. The
linker can also report and detect errors, for example, if part of your program is missing
or a nonexistent library component is referenced.

Effectively if your program is of any significant size, it will contain multiple


separate source code files, which can be linked. A massive program may be
challenging to compose in one working session, and it may be unbearable to work with
as a single file. By dividing into a number of smaller source files that each provide a
coherent part of what the full program does, you can make the development of the
program a whole lot easier. The source files can be compiled independently, which
makes removing simple typographical errors much more accessible.

Also, the entire computer program can classically be developed step-by-step,


rated under a project name, which is referred to the whole program.

Program libraries extend and support the C++ language by providing routines
to carry out operations that are not part of the language. For instance, libraries
comprise procedures that support processes such as performing input and output,
calculating a mathematical square root, can compare two-character strings, or acquire
date and time information.

A failure during the linking phase means that you have to go back and edit your
source code once again. Success, on the other hand, will produce an executable file.
In a Microsoft Windows environment, this executable file will have a .exe extension.
Several IDEs also take Build options, which compile and link your computer program
in one step. This possibility will usually be found inside an IDE, in the Compile menu,
or a menu of its own.

 Executing Programs

The execution phase is where you run your program, having completed all the
last process successfully. This phase can also generate a wide variety of errors that
can contain producing the wrong output. In all cases, it is back to the editing process
to check your source code.

15
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

In IDEs, you will find a suitable menu command that lets you run or execute
your compiled computer program. This Run or Execute selection may have a menu
of its own, or you may find it under the Compile menu option.

In Windows, you can run the.exe file for your program as you would any other
executable. The procedures of editing a program, compiling a program, linking a
program, and executing a program are essentially the same for developing computer
programs in any environment and with any compiled language.

Programming Paradigm

Programming is an original procedure carried out by computer programmers to


tell a computer how to do a specific task. There are some alternative approaches to
the programming process, referred to as programming paradigms. Different
paradigms signify fundamentally different approaches to building solutions to specific
types of problems using programming. Most computer programming languages fall
under one paradigm, but some computer languages have elements of numerous
paradigms. Two of the essential programming paradigms are the procedural paradigm
and the object-oriented paradigm.

Procedural Programming

Procedural programming is a list of instructions that tells the computer what to


do incrementally. Procedural programming can rely on procedures, also known as
routines or subroutines. A process contains a series of computational steps to be
carried out. Procedural programming is also referred to as imperative programming
and known as top-down language.

Procedural programming is instinctive in the sense that it is very like how a program
work. If you want a computer to do a certain task, you should provide incrementally
procedures on how to do it. No surprise that most of the early computer programming
languages are all technical. Examples of procedural programming languages include
Fortran, COBOL, and C, which have been throughout since the 1960s and 70s.

Object-Oriented Programming

Object-oriented programming (OOP) is an approach to problem-solving where


all computations are carried out using an object as the basic unit. An object is an
element of a program that sees how to perform specific actions and how to interact
with other components of the program. An example of an object would be a person
with attributes such as name, height, weight. It is expected for a person to be able to
do something, such as walking, running, etc. defined as the method of the object.
A process in object-oriented programming is like a procedure in procedural
programming. The necessary modification here is that the method is part of an object.
In object-oriented programming, you establish your code by creating objects, and then
you can give those objects attributes, and you can make them do certain things.
16
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Using classes is an aspect of object-oriented programming. A class is an outline


of an object. You can think of a class as an idea and the object as the representation
of that concept. Let us say you want to use a person in your program. You want to be
able to define the person and have the person do something. A class also know
'person' would deliver a blueprint for what a person airs like and what a person can
do. An example of object-oriented languages is C#, Java, Perl, and Python.

Procedure Programming VS Object-Oriented Programming

PROCEDURAL ORIENTED
OBJECT ORIENTED PROGRAMMING
PROGRAMMING
In procedural programming, the In object-oriented programming, the
computer program is divided into a little program is divided into small parts
part called the functions. called objects.
Procedural programming follows a top- Object-oriented programming follows a
down approach. bottom-up approach.
Object-oriented programming has
There is no access specifier in
access specifiers like private, public,
procedural programming.
protected, etc.
Adding new data and functions is not
Adding new data and functions is easy.
easy.
Procedural programming does not have
Object-oriented programming provides
any proper way of hiding data, so it is
data hiding, so it is more secure.
less secure.
In procedural programming, overloading Overloading is possible in object-
is not possible. oriented programming.
In procedural programming, the function In object-oriented programming, data is
is much essential than data. more important than function.
Procedural programming is based on an Object-oriented programming is based
unreal world. on the real world.
Examples: C, FORTRAN, Pascal,
Examples: C++, Java, Python, C#, etc.
Basic, etc.

17
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

APPLICATION ACTIVITY FOR LESSON 1


HOW DO YOU APPLY
WHAT HAVE YOU LEARNED?

Name: __________________________________ Date: ____________________


Course & Section: ________________________ Result: __________________

TRUE OR FALSE. Write T if the statement is true. If not, write F.

____1. Computer Programming is defined as the art and science of designing


a program.
____2. COBOL was created in the 1970s.
____3. Assembly Language a type of a low-level programming language in
which each program statement corresponds to an instruction that the
microprocessor can carry out.
____4. The compiler is used to convert source code into machine language
and detects and reports errors in the compilation process.
____5. Procedural Programming uses a list of instructions to tell the computer
what to do step-by-step.
____6. There is only one type of testing; it is called Blackbox testing.
____7. Documentation includes the necessary information about the
requirements of the program.
____8. The final stage in programming is Testing.
____9. An algorithm is a list of steps (similar to a recipe) for solving a
problem.
____10. A flowchart is a graphical representation that illustrates the sequence
of operations to be performed to get the solution to a problem.

18
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

APPLICATION ACTIVITY FOR LESSON 1

HOW DO YOU APPLY


WHAT HAVE YOU LEARNED?
Name: _______________________________ Date: _______________________
Course & Section: _____________________ Result: _____________________

TRUE OR FALSE. Write T if the statement is true. If not, write F.

_____1. Object-Oriented Programming is an approach to problem-solving where all


computations are carried without using the “object."

_____2. In most IDEs, you’ll find a suitable menu command which allows the
programmer to run or execute the compiled program.

_____3. The execution phase is where the programmer runs the program and has
completed all the previous procedures successfully.

_____4. A failure during the linking phase means that you have to go back and edit
your source code once again.

_____5. The whole computer program can usually develop in such a decrement
manner.

_____6. A Project name refers to the whole program.

_____7. The output from the compiler is known as object code.

_____8. Writing and Editing Programs is the process of creating and modifying
source code.

_____9. You can also use other editors to create your source files, but they must
store the code as plain text and with any extra formatting data embedded in it

_____10. MOV is an instruction telling the processor to equate the value of computer
memory.

19
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

IDENTIFICATION. Identify the following. Write your answer on the space


provided before each number.

_________________1. It refers to the person who designs or creates, codes, tests,


debugs, and documents a computer program.

_________________2. The native tongue of a computer.

_________________3. A programming language that was created in the 1950s for


business application.

_________________4. A programming language that was developed by Sun


Microsystems in the early 1990s that runs on a single computer or over the Internet
from a web server.

_________________5. A Low-level language in which each program statement


corresponds to an instruction that the microprocessor can carry out.

20
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

HOW DO YOU EXTEND YOUR


LEARNING?
ASSIGNMENT/ LEARNING INSIGHT/REFLECTION

Name: __________________________________ Date: ____________________


Course & Section: ________________________ Result: __________________

THINK ABOUT THIS!

Figure 1.4 Significance of software


Source: https://www.dlf.pt/pngs/219325/

The figure1.4 above illustrates the usage of software. You will see that the
image shows on some significance of software. What do you think is the relevance of
the software in our daily lives?

21
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

RUBRIC FOR ASSESSMENT

Exceeds Acceptable Acceptable Unacceptable


Criterion
10 6 3
The key topics in the 4 to 3 key topics in
1 to 2 key topics in
Content of the analysis are thoroughly the analysis are
the analysis are
topic discussed answered and answered and
answered
explained explained
At least 2
Most of the objectives objectives are Only 1 objective is
Goal and
are appropriately appropriately defined and
Outcome
defined and associated defined and associated with
Objective
with the analysis associated with the analysis
the analysis
A number of errors
Numerous errors
in grammar and
A few minor errors in in grammar and
punctuation;
grammar and punctuation;
Language average range of
punctuation; Excellent limited and
vocabulary and a
range of vocabulary wrongly used
few words are
vocabulary
wrongly used

22
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

11. remainder

LESSON 2:
Program Development

OBJECTIVES:
At the end of the lesson, students will be able to:

 Distinguish the process of Program Development


 Identify and differentiate types of testing.

DURATION: 3 hours

23
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Program Development Process


The process of developing a program in C++ may not be visible if you have
never written a computer program before. However, it is very similar to various
situations in life in which at the start, it just is not clear how you are going to attain your
objective. Generally, you start with a rough idea of what you want to attain, but you
need to interpret this into an additional exact specification of what you want.

Once you have reached this more precise specification, you can work out the
series of steps to direct your final objective. It is like the idea of building a house; you
need to know what kind of place you want, how large it is going to be, what types of
materials, and where you want to make it. This kind of detailed planning is necessary
when you want to compose or write a program.

At the point when we want to build a program utilizing any programming


language, we follow an order of steps. These steps are called the program
development process. The computer program development life cycle is a lot of steps
or stages utilized to develop a program in any programming language.

Understanding the Problem

In this phase, it is a problem definition, we define the problem statement, and


we decide the boundaries of the problem. In this stage, we need to understand the
problem statement, our requirement, and the output of the problem solution. These
are characterized in this first stage of the program development life cycle.

Also, the first step is to get a clear idea of what you want to do.

For example:

 To start building your house, you should consider what facilities it ought
to provide: like how many bedrooms, or how many bathrooms, or how
big it is going to be, etc.

 All these things affect the house cost in terms of materials and the work
involved in building it. Mostly, it originates down to a compromise that
best sees your requirements within the limitations of the budget allotted,
the workforce, and the time that is accessible for you to finish the project.

It is the same as developing a program of any size. Even for a generally exact
issue, you need to know what kind of input to expect, how the information is to be
prepared, and what sort of output is required and how it will look. The data could be
entered with the keyboard, but it might also involve data from a disk file, or information
achieves over a telephone line or a network.

The output could be displayed on the screen or printed; perhaps it might involve
updating a data file on disk.

24
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Note:

For more composite programs, you will need to look at many more
features of what the computer program will do. A direct definition of the problem
that your program is going to solve is an essential part of understanding the
resources and efforts that are going to be needed for the creation of a finished
product. Since these details also drive you to found whether the project is
possible.

Develop the Solution

In phase 2, we can implement the problem analysis here. We determine the


needs like variables, functions, etc. to solve the problem. That implies we accumulate
the necessary resources to solve the problem distinct in the problem definition stage.

For example:

 To get the house built, you will need detailed plans. These plans
empower the development workers to do their job, and the plans
describe in detail how the house will go together, the materials to use,
the dimensions, and so on.

You will also need a plan of what is to be done and when.

 You will need the establishment dug before the walls are built, so the
plan must involve the segmenting work into manageable units to be
performed in a logical sequence.

It is the same as a program. You will need to specify what the computer program
does by separating it into a set of well-defined and manageable chunks that are
reasonably self-contained. You will also need to detail how these chunks connect, as
well as what information each piece will need when it executes. This will empower you
to build the logic of each block comparatively independently from the rest of the
program.

If you treat a massive program as one colossal process that you try to code as
a single chunk, the chances are that you will never get it to work. Three tools will help
us with this task:

(1) structure charts,


(2) pseudocode, and
(3) flowcharts.

The structure chart is used to design the whole program. Pseudocode and
flowcharts, on the other hand, are used to develop the individual parts of the program.
These parts are known as modules in pseudocode or functions in the C++ language.

25
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

The hierarchy chart (also known as the structure chart) displays the
connection among several modules. Its name originates from its general use in
viewing the organization (or structure) of a corporate or business. For example, it is
the President at the top, then vice presidents on the next level, etc. In the context of a
program, it displays the connection among modules (or functions). Detail logic of the
program is not offered. It does represent the organization of the processes used within
the program showing which functions are calling on a subordinate process.

Hierarchy charts are generated by the computer programmer to aid the document in
a program. They carry the large image of the modules (or functions) used in a program.

Figure 2. Hierarchy or Structure chart for a program that has a five function
Source: https://press.rebus.community/programmingfundamentals/

The Pseudocode is a term often used in programming and algorithm-based


fields. It is a procedure that allows the computer programmer to characterize the
application of an algorithm. Simply, we can say that it is the cooked-up representation
of an algorithm. Algorithms are described with the aid of pseudocodes

, which is a representation of code or an incorrect code to be understood by even a


layman.

 Algorithm: It is an organized, logical sequence of the movements or the


approach towards a particular problem. A computer programmer implements
an algorithm to solve a problem. Algorithms are expressed using usual vocal
but somewhat technical annotations.

 Pseudocode: It is merely an implementation of an algorithm in the form of


annotations and informative text written in plain English. There is no syntax like
any of the programming languages and, therefore, can not be compiled or
interpreted by the computer.

The Flowchart is a graphical representation of an algorithm. Computer


programmers frequently use it as a program-planning tool to solve a specific
problem. It uses different symbols that are connected between them to designate the
flow of information and processing.
The process of an illustrate flowchart for an algorithm is known as “flowcharting”.

26
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Implementation

During this stage, it creates a step-by-step procedure to solve the problem


using the requirement given in the earlier stage. This phase is significant for program
development.

With the detailed design of a house, the work can start. Each group of
construction workers will start completing their parts of the project at the right time.
Each phase will need to be examined to check that it has been done correctly before
the following phase begins. Except these checks could simply result in the entire
house collapsing.

Naturally, if a program is enormous, you will write the computer source code
one element at a time. As one part is completed, you can now proceed writing the
next. Each part of the code will be based on the detailed design specifications; it must
verify that each piece performs the intended task, as much as you can, before
proceeding. It will enable you to gradually progress to a fully functioning program that
does everything you originally intended.

Testing and Debugging

In this stage, we see whether the code was written in the previous step is
solving the specified problem or not. That means we test the program, whether it is
solving the problem for several input information values or not. We also test whether
it could come up with the desired output or not.

The house is complete, but there are still a lot of things that need to be tested:
the water and electrical outlet, the water pump, the heating, and so on. Any of these
areas can have problems that need to be fixed. This is occasionally a reiterative
process, in which issues with one feature of the house can be the reason of effects
going wrong somewhere else.

The mechanism with a program is similar. Each of your program modules, the
pieces that make up your program, will need to be tested individually. When they do
not work correctly, there is a need to debug them. Debugging is the process of finding
and correcting errors in your program. When in finding the errors in a program, it
involves tracing where the information went and how it was processed

The term bug is used to denote any error in a program. It term came from a discovery
that a computer program error was caused by an insect shorting part of the circuit in
the computer.

By inspecting the code of a simple program, you can often find an error by
merely inspecting the code. The process of debugging a computer usually includes
adding extra program code to create output that will empower you to check what the
arrangement of events is and what intermediate values are produced in a computer
program. With a huge program, you will also need to test the computer program
modules in combination. Although the discrete modules may work, there is no
assurance that they will work together! The jargon for this stage of the program
development is integration testing.

27
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

There are two types of testing: Blackbox and Whitebox. The system test
engineer and the user do Blackbox testing. Whitebox testing is the responsibility of the
programmer.

Blackbox Testing

Blackbox Testing gets its name from the concept of testing the program
without knowing what is inside it- without knowing how It works. In other words,
the program is like a black box that we cannot see into.

Blackbox test plans are developed by looking only at the requirements


statement (this is only one reason why it is so important to have a good set of
requirements.) The test engineer uses conditions and his or her knowledge
systems development and the user working environment to create a test.

The plan will then be used when the system is tested as a whole. We
should ask to see this test plan before we write our program. The test engineer
goal will help us make sure we fully understand the requirements and also help
us create our test plan.

Whitebox Testing

Whereas Blackbox testing assumes that the tester knows nothing about
the program, Whitebox testing assumes that the tester knows everything about
the program. In this case, the program is like a glass in which everything inside
is visible.

Whitebox testing is our responsibility. As the programmer, we know what


is going on inside the program. We must make sure that every instruction and
every possible situation has been tested. How do we know when our program
is thoroughly tested? In reality, there is no way to know for sure. But we can do
a few things to help the odds. (Some of these concepts will not be clear until
you have read other sections; we include them here for completeness.)

1) Verify that every line of code has been executed at least once.
Fortunately, there are programming tools on the market today that
will do this for us.

2) Verify that every conditional statement in our program has executed


both the real and false branches, even if one of them is null.

3) For every condition that has a range, make sure the tests include the
first and last items in the content, as well as things below the first and
above the last-the most common mistakes in array range tests occur
at the extreme of the range.

4) If error conditions are being checked, make sure all error logic is
tested. This may require us to make temporary modifications to our
program to force the errors.

28
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Program Documentation

When the program is finished and thoroughly tested, the documentation on the
program is included for its distribution. Documentation usually contains the necessary
information about the program requirements – the operating system and hardware
requirements needed for the program to run. It also includes technical data such as
who created the program, whom to contact in case of a problem with the program, and
instructions on the use and maintenance of the program.

Maintenance

At this stage, the computer program is actively used by the users. If any
improvements are found in this stage, all the steps are to be repeated to make the
enhancements. That means, in this stage, the solution (program) is used by the end-
user. If the user experiences any issue or needs any improvement, then we need to
repeat all the stages from the beginning, so that the encountered problem is answered
or enhancement is added.

This final stage in programming is maintaining or updating the program. This is the
phase where the programmer has to keep the program running smoothly and updated
with the developments and changes in the field where it is used

29
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

APPLICATION ACTIVITY FOR LESSON 2

HOW DO YOU APPLY


WHAT YOU HAVE LEARNED?

Name: _______________________________ Date: _______________________


Course & Section: _____________________ Result: _____________________

IDENTIFICATION: From the pool of words below, choose the appropriate answer to
the following descriptions in the answer boxes.

Debugging Flowchart
Structure Chart Psuedocode Flowcharts
Hierarchy Chart Algorithm
Bug Blackbox Testing
Maintenance Whitebox Testing

_______________1. Used to design the whole program.

_______________2. Used to design the individual parts of the program.

_______________3. Also known as a structure chart.

_______________4. It is an organized logical sequence of the actions or the approach


towards a particular problem.

_______________5. It is a graphical representation of an algorithm.

_______________6. It is the method of discovering and correcting your software errors.

_______________7. Was used to refer to any error in a program.

______________8. Originally comes from the concept of testing the program without
knowing what is inside it- without knowing how It works.

______________9. Testing implies everything about the software is known to the tester.

______________10. This is where the programmer is charged with keeping the software
running smoothly and updating with the enhancements and changes in the area where it
is used.

30
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

APPLICATION ACTIVITY FOR LESSON 2

HOW DO YOU APPLY


WHAT YOU HAVE LEARNED?

Name: _______________________________ Date: _______________________


Course & Section: _____________________ Result: _____________________

Answer the following questions. Read carefully and write your answer on the space
provided.

Give ONE problem or a scenario that you will apply the 6 phases of the program
development process. You may use another paper for your answer.

Understanding the problem


_____________________________________________________________________
_____________________________________________________________________

Develop the solution


_____________________________________________________________________
_____________________________________________________________________

Implementation

_____________________________________________________________________
_____________________________________________________________________

Program Coding & Documentation


_____________________________________________________________________
_____________________________________________________________________

Testing and Debugging


_____________________________________________________________________
_____________________________________________________________________

Maintenance
_____________________________________________________________________
_____________________________________________________________________

31
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

APPLICATION ACTIVITY FOR LESSON 2

HOW DO YOU APPLY


WHAT YOU HAVE LEARNED?

Name: _______________________________ Date: _______________________


Course & Section: _____________________ Result: _____________________

Answer the following items.

1. Describe three tools that a programmer may use to develop a program


solution.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

2. What is the difference between Blackbox testing and Whitebox testing?

_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________

32
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

LESSON 3:
Logic Formulation

OBJECTIVES:
At the end of the lesson, students will be able to:

 Define the meaning and purpose of program logic formulation.


 Distinguish the tools used in program logic formulation
 Utilize algorithms and flowchart.

DURATION: 5 hours

33
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

What is the Program Logic Formulation?

Computers are logical machines. They follow instructions down to the letter
(follows steps as instructed than as intended). Although computers perform accurate
calculations or computations, an error in a formula or a value may cause difficulty
detecting errors. Computers cannot think and, therefore, cannot correct wrong
instructions. To be achieved, a program must be carefully designed before they are
created or written.

Program Logic Formulation deals with this problem. It provides the tools needed
to design the right solution by helping you define and identify the problem, its
requirements, and the required instructions.

The two most commonly used tools will be of great help for you to formulate a
better solution. These are the flowchart and algorithm.

Algorithm

An algorithm is a list of steps (similar to a recipe) for solving a problem.


Designing or creating an algorithm to solve a problem needs to write step-by-step
measures and then verify that the problem is solved as intended. This is often the most
challenging part of the problem-solving process. To design the solution for a problem
using an algorithm, programmers use a method called top-down design (also called
divide and conquer).

The following are the typical algorithmic steps in solving a problem:


1. Initialize data.
2. Read/Input the data.
3. Read/Input the data.
4. Perform computations.
5. Display/Output Results

Problem:

The price of one kilo of an apple is 50 pesos. If the customer buys three or more
kilos of apples, 5 pesos will be discounted for every kilo. Determine the total cost of
apples purchased.

Algorithm:

1) Read the number of apples purchased in kilos.


2) Calculate how much it would cost.
3) Output the total cost of the purchased apples.

34
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

The above example simply breaks down the problem into sub-problems that
need to be solved before coming up with the required answer. First, you have to know
how many apples the customer is buying before you can make any computations.
Next, you then compute the cost depending on the number of apples purchased and
then use a formula that would calculate the appropriate value. Finally, you then come
up with the answer through the calculations you made. You cannot give a solution to
the problem immediately by saying outright how much the apples cost without first
knowing how many apples are being purchased, how much is the cost of apples if
there were discounts and performing the calculations based on them .

Algorithm: This is a methodological approach, a precise, step-by-step process that


permits a computer to solve a problem.
Pseudocode: It is a simpler version of programming code in plain English, which
uses short phrases to write code for a program before implemented in a specific
programming language.
Program: It is an actual code written for problem succeeding all the rules of the
programming language.

Flowchart

A flowchart is a graphical representation that illustrates the sequence of the


operations to be performed to get the solution to a problem. Flowcharts are usually
drawn in the early phases of formulating computer program solutions. Flowcharts ease
communication between programmers and business people. These flowcharts are
shown a vibrant role in the computer programming of a problem and are relatively
helpful in understanding the logic of complicated and prolonged issues.

Flowcharts are visual representations of an algorithm. In creating flowcharts, we


use the special symbols that represent specific functions performed by a computer.

 Variable - The memory cells used for storing a program’s input data and its
computational results are called variables. It is the representation of an idea
that is changing.

For Example:
int a, b, c;

 Constant - Named item is used to specify a name for a memory cell that will
contain a value that does not change (fixed amount).
For Example:
long width = 5;

Note:

35
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

V ariables that hold a number must be initialized by equating it to zero, and variables
that will keep word(s) may be initialized by equating it to space and enclosed it in double-
quotes (name" ")

Types of Flowchart

Program Flowchart. A computer program flowchart defines graphically in detail the


logical operations and stages within a computer program and the categorization in
which these steps are to be executed for the changes of data to produce the needed
output.

System Flowchart. A system flowchart is a graphical representation of the


procedures involved in converting data on input media to data in output form. It
illustrates which data is used or produced at various points in a sequence of
operations. System flowcharts represent the interaction among data, hardware, and
personnel. The emphasis is on the media used and the work stations through which
the data passes. It illustrates more on the system elements; little is shown about how
processing will be accomplished.

36
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Flowcharting Symbols

Input / Output Symbol (Parallelogram). The input /output symbol


represents an instruction to an input or an output device.

Processing symbol (Rectangle). This symbol is used to signify a


collection of program instructions that accomplish a program's
processing function, such as performing arithmetic or mathematical
operations.

Decision Symbol (Diamond). This diamond-shaped box symbolizes a


point in the computer program where more than one track can be taken.
It is used to document facts in the program where, based upon variable
conditions, a branch to alternative paths is possible. The chosen
approach depends on the answer to a question or the result of a test,
which is inserted in the symbol.

Preparation Symbol (Hexagon). This symbol is used to represent an


instruction or group of instructions that will alter, or modify operations
such as control, index register, initialization, switch setting, and loops.

Terminal Symbol (Oval). The terminal symbol is used to designate the


beginning and the end of a program, or a point of interruption. It can
also be used in other places in the flowchart for stipulating error
situations, such as parity error checks or detection of invalid characters.

Predefined Process Symbol (Rectangle with Two Vertical Bars).


This symbol is a specialized process symbol that represents a named
operation or programmed step not explicitly detailed in the program
flowchart. As a subroutine symbol, it can be used when a procedure
needs to be repeated several times. Instead of writing the instructions
for the procedure each time it is required, the predefined process symbol
is used.

On-page Connector (Small Circle). This is a nonprecessing symbol


used to connect one part of a flowchart to another without drawing flow
lines. It signified an entry or an exit from another part of the flowchart
and used to change the reading order on the same page. On-page
connectors it conserves space by keeping related blocks near one
another and lessens the number of flow lines in complex programs; it
also eliminates the cross lines from taking place. It aids in developing a
more detailed, better organized, and more simplified flowchart.

37
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Flow Direction Indicators (Arrowheads). Arrowheads are used to


show the direction of the processing of data flow. These are added to
flow lines if a flowchart looks confusing in its layout.

Off-page Connector (Small Pentagon). This kind of connector is


used instead of the on-page connector to appoint entry or exit from a
page when a flowchart requires more than one page. The off-page
connector is commonly used in complex flowcharts, requiring a
detailed diagram extending over several pages.

Flow Line (Horizontal/Vertical Lines). Flow Lines are used to


showing reading order or sequence in which flowchart symbols are to
be read. Flow lines are sometimes drawn with arrowheads. The
commonly accepted practice indicates an arrowhead if the logic flow is
from right to left or from bottom to top. The arrowheads are not
mandatory when the logic flow is from right to left or top to bottom.

Guidelines for Preparing a Flowchart


The guidelines for preparing a flowchart are as follows:

1. A flowchart always begins with START and is completed by END symbol;


2. Symbols are interconnected using arrows;
3. Use comma (,) to separate data, and use a semicolon (;) to separate
instructions;
4. The arrowhead indicates the direction to be followed;
5. All the symbols except the diamond may have only one indicator branching out,
but may have one or more arrows branching in;
6. Whenever circles are used, the symbol leading to the circle should flow to the
symbol where a circle containing a similar character is leading to;
7. The sequence of a procedure using symbols matters because it indicates the
logical steps to be followed;
8. A flowchart may contain many symbols of the same kind depending on the
solution of the problem;
9. There may be many types of flowcharts to solve one problem, but the most
straightforward flowchart is advisable and most efficient.

Flowchart Development
The phases that encompass a flowchart must be ordered in an arranged,
understandable, and transparent manner. The program that executes this flowchart is
likewise in an orderly, understandable, and transparent way. An orderly, legible, and
exact solution is called a structured flowchart.

38
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Structured flowcharts are designed using the four program structures, namely:

a) Sequential - Steps are carried out in a firmly sequential manner; each stage is
performed exactly once.

b) Selection - The execution of instructions by section, wherein conditions for a


series of alternative statements are evaluated to specify which instruction is to
be executed.

c) Repetition - It consists of repeating steps on more than one set of data

d) Modular - The approach is sometimes called divide and conquer because an


enormous task is split up into several smaller tasks that are easily performed.

These structures will be our guide to produce a correct structured flowchart necessary
to prepare the right program.

Sequential

In this structure, steps are performed in a strictly sequential manner and are
executed once. This is the simplest method of control. It is easy to develop and
understand. The following problems in flowcharting illustrate simple logic flow.

Problem 1
Design an algorithm and flowchart that would determine the product of two numbers.
Algorithm
START
1: Define the variables.
(Let A be the first number A=0
B=0
and B as the second C=0
number, C for a product).
2: Initialize the values to be used: Input
A,B
A = 0, B= 0, C= 0
3: Input values for A and B. C = A* B

4: Calculate the product of the two


numbers. C = A*B. Output C

5: Output the product.


END

39
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Problem 2

Design an algorithm and a flowchart that will compute for the sum, difference, product,
and quotient of these values and print them out.

Algorithm
1. Define the variables.
(Let X, be the first number and Y as the
second number, SUM for sum, DIFF for
difference PROD for a product, and QUO for
quotient).
2. Initialize the variables to be used.
3. Input values for X and Y.
4. Calculate the sum, difference, product, and
quotient of the two values read.
5. Output the computed values (sum, average,
product, and quotient).

START

X=0; Y=0; SUM=0;


DIFF=0; PROD=0;
QUO=0

Input
X, Y

SUM = X+Y; DIFF=X-Y;


PROD= X*Y; QUO=X/Y

Output SUM, DIFF,


PROD, QUO

END

40
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Selection

The execution of instructions by the selection, wherein conditions for a series of


alternative statements are evaluated to specify which instruction is to be executed.

Problem 3
Design an algorithm and a flowchart that will determine if the grade of a student is
"passed" or failed," considered 75 as the passing grade.
Algorithm
1. Define the variables.
(Let G be the grade of a student)
2. Initialize the variables to be used.
3. Input student grade.
4. Test if G is greater than or less than 75.
5. If G is greater than or equal to 75, print "Passed," and if it is less than 75, print
"Failed."

Start

G =0;

Input
G

True
If Print

G >=75 “Passed”

False

Print
“Failed”

End

41
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Problem 4

A company plans to give a year-end bonus to each of its employees. Draw a


flowchart, which will compute the bonus of an employee. Consider the following
criteria: If the monthly salary of the employee is less than 10,000.00 pesos, the bonus
is fifty percent of the wage; for employees with wages greater than or equal to
10,000.00 pesos, the bonus is equivalent to the monthly salary. Print out the
corresponding bonus of the employee.

Algorithm
1. Define the variables to be used
(Let S be the salary, B for bonus of the employee)
2. Initialize the variables to be used.
3. Input salary.
4. Test the value of the salary. If S is less than 10,000, then the bonus of the
employee is fifty percent of the salary. If the salary is greater than or equal to
10,000, the bonus is equivalent to their monthly salary.
5. Output the corresponding bonus of the employees.

START

S = 0; B = 0

INPUT

True
IF
S < 10,000 B = S *0 .50 A

False

B=S

Output B

END

42
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Problem 5:

Design an algorithm and a flowchart that will examine the value of the temperature.
Then display the following messages depending on the value assigned to temp.
Temperature Message
Less than 0 ICE
Between 0 and 100 WATER
Exceeds 100 STEAM

Algorithm
1. Define the variables. (Let temp be variable for the temperature)
2. Initialize the variables to be used.
3. Input the value of temp.
4. Test if the value of temp is less than 0, between 0 and 100, or exceeds 100.
5. If the temp is less than zero, print "ICE," and if the number is greater than or equal
to zero and less than or equal to 100, print "WATER". Else the number is greater
than 100, print "STEAM."

START

temp = 0

input
temp

True
IF PRINT A
temp< 0 “ICE”

False

True
IF
temp>=0 and PRINT
temp < = 100N “WATER” A

False

PRINT
“STEAM”

END

43
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Repetition

A Loop is used when it is desired to make the same calculation on more than
one set of data. It consists of repeating a program, or a selection of programs, and
substituting new data for each repetition. A computer program loops play an important
part in data processing since they provide efficient means of processing several sets
of data with the identical program segment.

Problem6
Design a flowchart that will print “Hello “twenty times.

Solution 1
Algorithm:
1. Define the variables to be used. (Let x be the counter)
2. Initialize the counter x = 1.
3. Test the value of x. if the value of x < = 20 Print “Hello”, else end of program.
4. Increment x (x=x+1).
5. Repeat step 3.

START

X=1

False
X <= 20
END

True

PRINT

X=X+1

44
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Solution 2
Algorithm:
1. Define the variables to be used. (Let x be the counter)
2. Initialize the x = 0.
3. Print “Hello”
a. Increment x Increment x (x=x+1).
4. Test the value of x. if the value of x < = 20 repeat step 3, else end of program.
.

START

X=0

PRINT

X=X+1

True
False
X <= 20
END

Modular Structure

Most computer programs perform a task that is huge enough to be broken down
into various subtasks. For this reason, computer programmers usually break down
their programs into modules. A module is a set of statements that exist within a
program to perform a specific task. Instead of writing a massive program as one long
sequence of statements, numerous small modules can be written; each carries out a
specific part of the task. These modules can then be executed in the want order to
perform the overall task.
The approach is sometimes called divide and conquer because an enormous
task is divided into several smaller tasks that are easily performed. This approach is
represented by the structure chart. A structure chart, also is known as a hierarchy
chart, shows the functional flow through the different modules in a program. For

45
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

example, let us write separate modules for the kitchen, bathroom(s), bedrooms, family
room, and living room in designing the flooring of a house, as illustrated below.

Flooring

Kitchen Living Area

Family Room Dine Living

Every modern programming language lets you create modules that are
commonly called procedures, subroutines, subprograms, methods, and functions.

Advantages of Using Modules

Using modules in a program has the following advantages:

 Simpler Code

A program code tends to be simple and more comfortable to understand when


it is divided into modules. Modules are more readable than one lone sequence
of statements.

 Code Reuse

Modules also decrease the duplication of code inside a program. If a particular


operation is performed in several places in the program, a module can be
composed once to perform that operation and then be executed at any time
required. This benefit of utilizing modules is known as code reuse because you
are composed of the code to accomplish a task once and then reusing it each
time you need to make the task.

 Better Testing

The testing and debugging of the program get less complex when every
programming task is contained in a module. Developers can test every module
in a program independently to determine whether it correctly performs its
operation. This makes it simpler to segregate and fix errors.

46
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

 Faster Development

Suppose a programmer or a team of programmers is developing multiple


programs. There is no need to write the code for these tasks multiple times.
Modules can be written or composed for the commonly needed tasks, and
those modules can be combined into each program that needs them.

 Easier Facilitation of Teamwork

Modules enable the programmers to work with teams. When a program is


established as a set of modules that each performs an individual task, different
programmers can be assigned to compose other modules.

Top-Down Design

Programmers commonly use a technique known as top-down design to break


down an algorithm into modules. The process of top-down design is performed in the
following manner:

 The overall task that the program is to perform is divided into a series of
subtasks.
 Each of the subtasks is evaluated to determine whether it can be further broken
down into more subtasks. This step is repetitive until no more subtasks can be
recognized.
 Once all of the subtasks have been identified, code will be written.

This process is called a top-down design because the computer programmer


starts by observing at the topmost level of task that must be performed, and then
breaks down those errands into lower levels of subtasks.

Calling a Module

A module definition specifies what the module does and must be called to
execute. When a module is called, the control jumps to that module and then executes
the statement in the body of the module. When the end of the module is reached, the
control jumps back to the part of the program that called the module, and the program
resumes execution at that point.

Flowcharting a Program with Modules

A module call is shown in a flowchart with a rectangle with vertical bars on each
side. The name of the module that is being called is written on the symbol.

Message( )

47
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Programmers typically draw a separate flowchart for each module in a program.

start

Display “I have a showMessage


message for you.”

Display “I have a
message for you.”
Message()

return

Display “That’s
all.”

end

48
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Flowchart Tracing

To determine the correctness of logic flow within any given flowcharting, it will
usually require some tracing and testing. Tracing, it will provide a clearer
understanding of the processing steps involved. This will usually require the use of
actual test data values. The first step is to have a list of variables to hold different
values during the processing operation. We begin tracing the flowchart with the first
instruction and continue by following the appropriate flow lines and flow direction
indicators.

Tracing the Output

1. START

A=0;B=0;
C=0;D=0;

The input value of B.


INPUT B
Example B = 5.

A=B+1

Compute the value of A.


Result: B=5; A=6
D=A+1

Compute the value of D.


C=A*D
Result: A=6 ;D = 7

Output C
Compute the value of C. Result: C =42

END
Output:42

49
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

APPLICATION ACTIVITY FOR LESSON 3

HOW DO YOU APPLY


WHAT HAVE YOU LEARNED?

Name: _______________________________ Date: _______________________


Course & Section: _____________________ Result: _____________________

Create an algorithm and a flowchart for the given problem below.

(Sequential)
Convert an input inch(es) into its equivalent centimeters (cm). Take note that one inch
is equivalent to 2.54 cm.

50
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

APPLICATION ACTIVITY FOR LESSON 3

HOW DO YOU APPLY


WHAT HAVE YOU LEARNED?

Name: _______________________________ Date: _______________________


Course & Section: _____________________ Result: _____________________

Create an algorithm and a flowchart for the given problem below.

(Selection)
Determine if the number inputted is an even or odd number.

51
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

APPLICATION ACTIVITY FOR LESSON 3

HOW DO YOU APPLY


WHAT HAVE YOU LEARNED?

Name: _______________________________ Date: _______________________


Course & Section: _____________________ Result: _____________________

Create an algorithm and a flowchart for the given problem below.

(Repetition)
Compute for the sum of all even numbers among the ten inputted numbers

52
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
APPLICATION ACTIVITY FOR LESSON 3

HOW DO YOU APPLY


WHAT HAVE YOU LEARNED?

Name: _______________________________ Date: _______________________


Course & Section: _____________________ Result: _____________________

Trace the output for each set of the given input of the flowchart below. Write your
answer inside the table given below.

Start Input Output


a b a b c
a=0; 5 5
b=0; 10 3
c=0; 15 2
0 4
Input a, b 8 7

c=c+a

a=a+b

T
Is
a<=20
?
F

Print a, b, c

End

53
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

GRADING RUBRICS FOR UNIT 2

HOW DID YOU PERFORM?

Name: _______________________________ Date: _______________________


Course & Section: _____________________ Result: _____________________

ALGORITHM AND FLOWCHART RUBRIC

CATEGORY 21-25 11-20 6-10 0-5


A clear
understanding
A clear
of using a
understanding
conditional
of using an
algorithm to
algorithm to
create a
create a Missing some Missing many
flowchart, use
flowchart, set of tasks, tasks, use of
Content of illustrating a
primarily mostly correct decisions
complete set of
complete set of use of decisions incorrect
tasks
tasks, correct
accurately,
use of decisions
correct use of
(yes/no)
decisions
(true/false)
(yes/no)
(true/false)
The path shows
Accurate insight into the The path The path does The path fails to
depiction of a algorithm and matches the not fit well with match the
selected path making some algorithm the algorithm algorithm
strategies
The flowchart is
There is no
well-designed, Flowchart lacks
evidence of a
logically a logical and
The flowchart is planned design
organized, and visual flow of
Layout and neatly designed or organization
graphically ideas, is
organization and logically of ideas in the
pleasing, and disorganized,
organized flowchart. Work
demonstrates and is difficult to
is not
attention to interpret.
presentable
detail
The flowchart The flowchart
The flowchart The flowchart contains has a significant
contains no has few several number of
Output mechanical or mechanical or mechanical errors that
grammatical grammatical errors that make the
errors. errors detect from the document
content difficult to read

54
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

HOW DO YOU EXTEND YOUR


LEARNING?
ASSIGNMENT/ LEARNING INSIGHT/REFLECTION

Name: _______________________________ Date: _______________________


Course & Section: _____________________ Result: _____________________
For your practice, complete the table below by computing the value of C++ based on
the example mentioned above.

1.
START

A=0;B=0;
INPUT B INPUT C
C=0;D=0; 5 42
10
14
INPUT B
45
80
A=B+1

D=A+1

C=A*D

Output C

END

55
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

2. Trace the output of the given flowchart.

START

X=0
The value of x is
initialized to 0.
B

X = X +1

Increment the value


of x by 1
X <= 50 True B

False

PRINT X
Test if x <=50 if true,
the program will
repeat the process of
END incrementing the
value of x Output: _____

56
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

POST-TEST FOR UNIT 1

HOW MUCH HAVE YOU LEARNED?

Name: __________________________________ Date: ____________________


Course & Section: ________________________ Result: __________________

Read each item carefully, then circle the letter that best represent your answer.

1. C++ program was developed by Bjarne Stroustrup, starting in 1991 at the Bell
Labs in Murray Hill.
a. True

b. False

2. Is it a list of steps for solving a problem? It involves you to write step-by-step


measures and then validate that it solves the problem as intended.
a. Flowchart

b. Algorithm
c. Constant
d. Variables

3. This mathematical operator uses C++ programming that performs division, but
instead of returning the quotient, it returns the remainder.
a. Operand

b. Modulus
c. Multiplication

d. Exponent

4. Is the person who designs or creates, codes, tests, debugs, and documents a
computer program?
a. Computer Programmer
57
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

b. Computer Programing

c. Computer Program
d. Computer Programmable

5. Is it the native tongue language of a computer? This language instruction is a


binary string of 0's and 1's that specifies an operation and identifies the memory
cells involved in the process.
a. Machine Language

b. Assembly language
c. Low-level language

d. High-Level language

6. This type of FLOWCHART is a graphic representation of the procedures


involved in converting input media data to data in the output form. It illustrates
which data is used or produced at various points in a sequence of operations.

a. System Flowchart
b. Scientific Flowchart

c. Process Flowchart
d. Program Flowchart

7. This program statement checks an expression that may or may not execute a
statement or group of statements?

a. Conditional Expression
b. Conditional Execute

c. Conditional Statement
d. Conditional Declaration

8. It is a C++ programming language that runs little or no abstraction from a


computer's instruction set architecture.
a. Machine Language

b. Low-level language
c. High-Level language

d. Assembly language
58
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

9. This is a type of a low-level programming language in which each program


statement corresponds to an instruction that the microprocessor can carry out.
Assembly language

a. Machine Language
b. Low-level language

c. High-Level language
d. Assembly language

10. In constructing a C++ program, using a “comment” gives additional useful


information inside a program.

a. True
b. False

59
IT 103: COMPUTER PROGRAMMING 1

You might also like