You are on page 1of 25

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, uses of
computer programs, skills required for
programming and tips on choosing a
programming language shall be presented.

Understanding of the algorithm as the basis


for the program flow will be introduced. In
addition there will be a basic introduction to
common program errors. The programming process and
methodologies are being presented in a
very simple way to prepare the students in
understanding the programming concepts.

1
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

TIME DURATION: 3 hours

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

Introduction
Think about some various ways that people use computers. In school, students
use computers for tasks such as writing papers, searching for articles, sending email,
and participating in online classes. 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 different tasks such as paying bills, shopping
online, communicating with friends and family, and of course playing games.

Figure 1. Microsoft Word and Adobe


Photoshop. An example of Word Processing and Image Editing Program

Figure 1. shows screens from two commonly used programs, Microsoft Word, and
Adobe Photoshop. Microsoft Word is a word processing program that allows you to
create, edit, and print documents with your computer. Adobe Photoshop is an image
editing program that allows you to work with graphic images, such as photos taken
with your digital camera.

What is Computer
Programming?

A computer program is a
set
of instructions written in a
programming language that a
computer can execute.
Programs
are designed to perform specific
tasks. These programs are written
by programmers refers to the
person who designs or creates,
codes, tests, debugs and
documents a computer programs.
Figure 1.1. A Computer Programming
Clipart Source: https://www.freecodecamp.org/

Programming requires 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.

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

Computer Programming

▪ is the art and science of designing a program. Programming is the process of


providing instructions for the microprocessor.
▪ it is a developing process of designing and building an executable computer
programs to accomplish a specific computing result.

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

Let’s take making a cup of tea as an example…

Programming how to make a cup of tea

If you were to give instructions on how to make 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 3. Let the tea brew
1.2. 4. Remove the teabag
Computer Programmer Source: 5. Add milk and/or sugar (if desired)
https://www.freecodecamp.org/

What we take for granted is that communication with a human being is different
than communicating with a computer. A human 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 communicate with a
computer.

Each programming language has its own set of words and rules, called the syntax of
that language. If you're going to write a program, you have to follow the syntax of the
language you're using, otherwise you won't be understood.
Machine Language

The native tongue of a computer is the


machine language. Each machine language
instruction is a binary string of 0’s and 1’s that
specifies an operation and identifies the memory
cells involved in the operation.

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

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

Example:

SUB AX, BX = 00001011 00000001 00100010 is an instruction


set to subtract values of two registers AX and BX.

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


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

A Programmer must have additional knowledge about the architecture of the particular
machine, before programming in machine language. Developing programs using
machine language is tedious job. Since, it is very difficult to remember sequence of
binaries for different computer architectures. Therefore, nowadays it is not much in
practice.

Low Level Language

A programming language that provides little or


no abstraction from a computer's instruction set
architecture. The word "low" refers to the small
or
nonexistent amount of abstraction between the
language and machine language; because of
this, low
level languages are sometimes described as
being
"close to the hardware."
A low-level language does not need a compiler
or interpreter to run; the processor for which the
language was written is able to run the
Advantages of low-level languages
code without using either of these.
Source:
https://www.techdotmatrix.com/

▪ Programs developed using low level languages are fast and memory efficient. ▪
Programmers can utilize processor and memory in better way using a low-level
language.
▪ There is no need of any compiler or interpreters to translate the source to
machine code. Thus, cuts the compilation and interpretation time. ▪ Low level
languages provide direct manipulation of computer registers and storage.
▪ It can directly communicate with hardware devices.

Disadvantages of low-level languages

▪ Programs developed using low level languages are machine dependent and are
not portable.
▪ It is difficult to develop, debug and maintain.
▪ Low level programs are more error prone.
▪ Low level programming usually results in poor programming productivity. ▪
Programmer must have additional knowledge of the computer architecture of
particular machine, for programming in low level language.
5
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Advantages of High-level language
High Level Language

The computer would have no difficulty


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

▪ High level languages are programmer friendly. They are easy to write, debug
and maintain.
▪ It provides higher level of abstraction from machine languages. ▪
It is machine independent language.
▪ Easy to learn.
▪ Less error prone, easy to find and debug errors.
▪ High level programming results in better programming productivity.

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. ▪
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. These are called high-level
languages to distinguish them from the machine and symbolic languages. They are
also called compiler languages, since these languages require a special program
called a 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 original program that is written in a high-level
language is called the source program, and its translation in machine language is
called object program.

Here are the examples of Programming Languages


Language Description

Ada Ada was created in the 1970s, primarily for


applications used by the U.S. Department of

6
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Defense. The language is named in honor of
Countess Ada Lovelace, an influential and
historical figure in the field of computing.

BASIC Beginners All-purpose Symbolic Instruction Code


is a general purpose-language that was originally
designed in the early 1960s to be simple enough
for beginners to learn. Today, there are many
different versions of BASIC.

FORTRAN FORmulaTRANslator was the first high-level


programming language. It was designed in the
1950s for performing complex mathematical
calculations.

COBOL Common Business-Oriented Language was


created in the 1950s, and was designed for
business applications.

Pascal Pascal was created in 1970, and was originally


designed for teaching programming. The
language was named in the honor of the
mathematician, physicist, and philosopher Blaise
Pascal.

C and C++ C and C++ (pronounced “c plus plus”) are


powerful, general-purpose languages developed
at Bell Laboratories. The C language was created
in 1972 and the C++ language was created in
1983.
C# Pronounced “c sharp.”This language was created
by Microsoft around the year 2000 for developing
applications based on the Microsoft.NET
platform.

Java Java was created by Sun Microsystems in the


early 1990s. it can be used to develop programs
that run on a single computer or over the Internet
from a Web server.

JavaScript JavaScript, crated in the 1990s, can be used in


Web pages. Despite its name JavaScript is not
related to Java.

Python Python is a general purpose language created in


the 1990s. It has become popular in business and
academic applications.

Ruby Ruby is a general purpose language that was


created in the 1990s. it is increasingly becoming
popular language for programs that run on Web
servers.

Visual Basic Visual Basic (commonly known as VB) is a


Microsoft programming language and software
development environment that allows
programmers to create Windows-based

7
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
applications quickly. VB was originally 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 assembler specific to the processor to
translate the assembly language into a machine code. An assembly language provides
precise control of the computer, but assembly language programs written for one type
of computer must be rewritten to operate on other types. An assembly language might
be used instead of a high –level language for any of these three major reasons; speed,
control, and preference. Program written in assembly language run faster than those
generated by a compiler. The use of an assembly language allows programmer to
interact directly with the hardware including the processor, memory display,
input/outputs ports.

By comparison, a high-level programming language isolates the execution semantics


of computer architecture from the specification of the program, making the process of
developing a program simpler and more understandable.

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

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

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 memory cell, x is any valid variable representing the computer memory
cell.

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


MOV Bx, Ofh 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 short abbreviated English words used to specify a computer instruction.
Each instruction in binary has a specific mnemonic. They are architecture dependent and there
is a list of separate mnemonics for different computer architectures.

Examples of mnemonics are – ADD, MOV, SUB etc.

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

Advantages of Assembly Language

▪ It allows complex jobs to run in a simpler way.


▪ It is memory efficient, as it requires less memory.
▪ It is faster in speed, as its execution time is less.
▪ It is mainly hardware oriented.
▪ It 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 a lot of time and effort to write the code for the same.
▪ It is very complex and difficult to understand.
▪ The syntax is difficult to remember.
▪ It has a lack of portability of program between different computer architectures. ▪
It needs more size or memory of the computer to run the long programs written in
Assembly Language
Compilers and Interpreters
As we learned in the previous section, computer understands program only if it
is coded in its machine language. In this section, we explain the procedure for turning
a program written in high level language into machine language. Because the
computer can understands only machine language instructions, programs that are
written in a high-level language must be translated into machine language. Once a
program has been written in a high-level language, the programmer will use a compiler
or an interpreter to make the translation.

There are generally two types of programming languages: compiled languages and
interpreted languages. A compiler is needed to translate a program written in a
compiled language into machine-understandable code (that is, binary code) before you
can run the program on your machine. When the translation is done, the binary code
can be saved into an application file. You can keep running the application file without
the compiler unless the program (source code) is updated and 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

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

On the other hand, a program written in an interpreted language can be run


immediately after you finish writing it - or for that matter, while you are writing it. But
such a program always needs an interpreter to translate the high-level instructions
into machine-understandable instructions (binary code) at runtime. You cannot run the
program on a machine unless the right interpreter is available.
INTERPRETER COMPILER

Translates program one statement at Scans the entire program and


a time. translates it as a whole into machine
code.

Interpreters usually take less amount Compilers usually take a large


of time to analyze the source code. amount of time to analyze the
However, the overall execution time is source code. However, the overall
comparatively slower than compilers. execution time is comparatively
faster than interpreters.

No intermediate object code is Generates intermediate object


generated, hence are memory efficient. code which further requires linking,
hence requires more memory.

Programming languages like Programming languages like C,


JavaScript, Python, Ruby use C++, Java use compilers.
interpreters.

However, there is nothing inherent to a compiled language to prevent someone from


providing an interpreter for the language; likewise, people can and often do write
compilers for interpreted languages. In fact, it is not common to mix the two flavour 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 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 with the required library modules, and (4)
executing the program.

✓ Writing and Editing Programs

This is the process of creating and modifying source code - the name given to
the program instructions you write. Some C compilers come with a specific editor that
can provide a lot of assistance in managing your programs. In fact, an editor often
provides a complete environment for writing, managing, developing and testing your
programs. This is sometimes called an integrated development environment, or
IDE.

You can also use other editors to create your source files, but they must store the code
as plaintext without any extra formatting data embedded in it. In general, if you have a
compiler system with an editor included, it will provide a lot of features that make it
easier to write and organize your source programs. There will usually be automatic
facilities for laying out the program text appropriately, and color highlighting for
important language elements, which not only makes your code more readable but also
provides a clear indicator when you make errors when keying in such words.

On a PC you could use one of the many freeware and shareware programming
editors. These will often provide a lot of help in ensuring your code is correct with
syntax
10
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
highlighting and auto indenting of your code. Do not use a word processor such as
Microsoft Word, as these are not suitable for producing program code because of the
extra formatting information they store along with the text. Of course, you also have
the option of purchasing one of the professionally created programming development
environments that support C, such as those from Borland or Microsoft, in which case
you will have very extensive editing capabilities. Before parting with your cash though,
it is a good idea to check that the level of C that is supported is approximate to the
current C standard.

✓ Compiling Programs

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

The compiler can detect a wide range of errors that are due to invalid or
unrecognized program code, as well as structural errors where, for example, part of a
program can never be executed. The output from the compiler is known as object
code and is stored in files called object files, which usually have names with the
extension .obj in the Microsoft Windows environment, The result of a successful
compilation is a file with the same name as that used for the source file, but with the
.o or .obj extension.

✓ Linking Programs

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

In practice, if your program is of any significant size, it will consist of several


separate source code files, which can then be linked. A large program may be difficult
to write in one working session, and it may be impossible to work with as a single file.
By breaking it up into a number of smaller source files that each provide a coherent
part of what the whole program does, you can make the development of the program
a whole lot easier. The source files can be compiled separately, which makes
eliminating simple typographical errors a bit easier.

Furthermore, the whole program can usually be developed incrementally. The


set of source files that make up the program will usually be integrated under a project
name, which is used to refer to the whole program.

Program libraries support and extend the C language by providing routines to


carry out operations that are not part of the language. For example, libraries contain
routines that support operations such as performing input and output, calculating a
square root, comparing two character strings, or obtaining date and time information.

A failure during the linking phase means that once again you have to go back
and edit your source code. Success on the other hand will produce an executable file.
In a Microsoft Windows environment, this executable file will have an .exe extension.
Many IDEs also have a Build option, which will compile and link your program in one

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

step. This option will usually be found, within an IDE, in the Compile menu;
alternatively, it may have a menu of its own.

✓ Executing Programs

The execution stage is where you run your program, having completed all the
previous processes successfully. Unfortunately, this stage can also generate a wide
variety of error conditions that can include producing the wrong output or just sitting
there and doing nothing, perhaps crashing your computer for good measure. In all
cases, it’s back to the editing process to check your source code.

In most IDEs, you’ll find an appropriate menu command that allows you to run
or execute your compiled program. This Run or Execute option 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 processes of editing, compiling, linking, and executing are
essentially the same for developing programs in any environment and with any
compiled language.

Programming Paradigm
Programming is a creative process carried out by programmers to instruct a computer
on how to do a task. A program is a set of instructions that tells a computer what to do
in order to come up with a solution to a particular problem. There are a number of
alternative approaches to the programming process, referred to as programming
paradigms. Different paradigms represent fundamentally different approaches to
building solutions to specific types of problems using programming. Most programming
languages fall under one paradigm, but some languages have elements of multiple
paradigms. Two of the most important programming paradigms are the procedural
paradigm and the object-oriented paradigm. Let's look at each of these in a bit more
detail.

Procedural Programming
Procedural programming uses a list of instructions to tell the computer what to
do step-by-step. Procedural programming relies on - you guessed it - procedures, also
known as routines or subroutines. A procedure contains a series of computational
steps to be carried out. Procedural programming is also referred to as imperative
programming. Procedural programming languages are also known as top-down
languages.

Procedural programming is intuitive in the sense that it is very similar to how you would
expect a program to work. If you want a computer to do something, you should provide
step-by-step instructions on how to do it. It is, therefore, no surprise that most of the
early programming languages are all procedural. Examples of procedural languages
include Fortran, COBOL and C, which have been around since the 1960s and 70s.

Object-Oriented Programming
Object-oriented programming, or OOP, is an approach to problem-solving
where all computations are carried out using objects. An object is a component of a
12
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

program that knows how to perform certain actions and how to interact with other
elements of the program. Objects are the basic units of object-oriented programming.
A simple example of an object would be a person. Logically, you would expect a person
to have a name. This would be considered a property of the person. You would also
expect a person to be able to do something, such as walking. This would be considered
a method of the person.

A method in object-oriented programming is like a procedure in procedural


programming. The key difference here is that the method is part of an object. In
object oriented programming, you organize your code by creating objects, and then
you can give those objects properties and you can make them do certain things.

A key aspect of object-oriented programming is the use of classes. A class is a


blueprint of an object. You can think of a class as a concept, and the object as the
embodiment of that concept. So, let's say you want to use a person in your program.
You want to be able to describe the person and have the person do something. A class
called 'person' would provide a blueprint for what a person looks like and what a person
can do. Examples of object-oriented languages include C#, Java, Perl and Python.

Procedure Programming VS Object-Oriented Programming


PROCEDURAL ORIENTED OBJECT ORIENTED PROGRAMMING
PROGRAMMING

In procedural programming, program In object-oriented programming,


is divided into small parts called program is divided into small
functions. parts called objects.

Procedural programming follows Object oriented programming


top down approach. follows bottom up approach.

There is no access specifier in Object oriented programming have


procedural programming. access specifiers like private,
public, protected etc.

Adding new data and functions is Adding new data and function is easy.
not easy.

Procedural programming does not Object oriented programming


have any proper way of hiding data provides data hiding so it is more
so it is less secure. secure.

In procedural programming, Overloading is possible in


overloading is not possible. object oriented programming

In procedural programming, function In object-oriented programming, data


is more important than data. is more important than function.

Procedural programming is based Object oriented programming is


on unreal world. based on real world.

Examples: C, FORTRAN, Pascal, Examples: C++, Java, Python, C# etc.


Basic etc.

13
IT 103: COMPUTER PROGRAMMING 1
LESSON 2:
Program Development

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


▪ Understand the process of Program Development ▪
Identify and differentiate types of testing.

TIME DURATION: 3 hours


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

Program Development Process


The process of developing programs in C++ may not be evident if you’ve never
written a program before. However, it’s very similar to many other situations in life in which
at the beginning it just isn’t clear how you’re going to achieve your objective. Normally you
start with a rough idea of what you want to achieve, but you need to translate this into a
more precise specification of what you want.

Once you have reached this more precise specification, you can work out the series
of steps that will lead to your final objective. So having an idea that you want to build a
house just isn’t enough. You need to know what kind of house you want, how large it’s going
to be, what kinds of materials you have to build it with, and where you want to build it. This
kind of detailed planning is also necessary when you want to write a program.

When we want to develop a program using any programming language, we follow a


sequence of steps. Generally, program development life cycle contains 6 phases, they are
as follows:

1) Understanding the problem


2) Develop the solution
3) Implementation
4) Program Coding & Documentation
5) Testing and Debugging
6) Maintenance

These steps are called phases in program development. The program development life
cycle is a set of steps or phases that are used to develop a program in any programming
language.

Understanding the Problem

In this phase, it is the problem definition, we define the problem statement and we
decide the boundaries of the problem. In this phase we need to understand the problem
statement, what is our requirement, what should be the output of the problem solution.
These are defined in this first phase of the program development life cycle.

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

For example:
▪ It would be lunacy to start building your house before you had established what
facilities it should provide: how many bedrooms, how many bathrooms, how
big it’s going to be, and so on.

▪ All these things affect the cost of the house in terms of materials and the work
involved in building it. Generally, it comes down to a compromise that best
meets your needs within the constraints of the money, the workforce, and the
time that’s available for you to complete the project.

It is the same with developing a program of any size. Even for a relatively
straightforward problem ,you need to know what kind of input to expect, how the input

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

is to be processed, and what kind of output is required—and how it’s going to look. The
input could be entered with the keyboard, but it might also involve data from a disk file or
information obtained over a telephone line or a network.

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

Note:

For more complex programs, you’ll need to look at many more aspects
of what the program is going to do. A clear definition of the problem that your program is
going to solve is an essential part of understanding the resources and effort that are going
to be needed for the creation of a finished product. Considering these details also forces
you to establish whether the project is actually feasible.

Develop the Solution

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


requirements like variables, functions, etc. to solve the problem. That means we gather the
required resources to solve the problem defined in the problem definition phase. We also
determine the bounds of the solution.

For example:
▪ To get the house built, you will need detailed plans. These plans enable the
construction workers to do their job and the plans describe in detail how the
house will go together the dimensions, the materials to use, and so on.

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

▪ you’ll want the foundation dug before the walls are built, so the plan must involve
segmenting the work into manageable units to be performed in a logical
sequence.

It’s the same with a program. You will need to specify what the program does by
dividing it into a set of well-defined and manageable chunks that are reasonably self-
contained. You will also need to detail the way in which these chunks connect, as well as
what information each chunk will need when it executes. This will enable you to develop the
logic of each chunk relatively independently from the rest of the program.

If you treat a large program as one huge process that you try to code as a single
chunk, chances are that you’ll never get it to work. Three tools will help us in 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 design the individual parts of the program. These
parts are known as modules in pseudocode or functions in the C++ language.
3
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
The hierarchy chart (also known
as a structure chart) shows the relationship
between various modules. Its name
comes from its general use in showing the
organization (or structure) of a business.
The President at the top, then vice presidents
on the next level, etc. Within the context of a
computer program, it shows the
relationship between modules (or
functions). Detail logic of the program is
not presented. It does represent the
organization of the functions used within
the program showing which functions are
calling on a subordinate function. Those above are calling those on the next level down.

Hierarchy charts are created by the programmer to help document a program. They
convey the big picture 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 Pseudo code is a term which is often used in programming and algorithm
based fields. It is a methodology that allows the programmer to represent the
implementation of an algorithm. Simply, we can say that it’s the cooked-up representation
of an algorithm. Often at times, algorithms are represented with the help of pseudo codes
as they can be interpreted by programmers no matter what their programming background
or knowledge is. Pseudo code, as the name suggests, is a false code or a representation
of code which can be understood by even a layman with some school level programming
knowledge.

▪ Algorithm: It’s an organized logical sequence of the actions or the approach towards
a particular problem. A programmer implements an algorithm to solve a problem.
Algorithms are expressed using natural verbal but somewhat technical annotations.
▪ Pseudo code: It’s simply an implementation of an algorithm in the form of annotations
and informative text written in plain English. It has no syntax like any of the
programming language and thus can’t be compiled or interpreted by the computer.

The Flowchart is a graphical representation of an algorithm. Programmers often use it as


a program-planning tool to solve a problem. It makes use of symbols which are connected
among them to indicate the flow of information and processing. The process of drawing a
flowchart for an algorithm is known as “flowcharting”.
4
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

Implementation

During this phase, we develop a step by step procedure to solve the problem using
the specification given in the previous phase. This phase is very important for program
development.

Given the detailed design of a house, the work can start. Each group of construction
workers will need to complete its part of the project at the right time. Each stage will need
to be inspected to check that it’s been done properly before the next stage begins.
Omitting these checks could easily result in the whole house collapsing.

Of course, if a program is large, you’ll write the source code one unit at a time. As
one part is completed, you can write the code for the next. Each part will be based on the
detailed design specifications, and you’ll verify that each piece works, as much as you can,
before proceeding. In this way, you’ll gradually progress to a fully working program that does
everything you originally intended.

Testing and Debugging

During this phase, we check whether the code written in previous step is solving the
specified problem or not. That means we test the program whether it is solving the problem
for various input data values or not. We also test that whether it is providing the desired
output or not.

The house is complete, but there are still a lot of things that need to be tested: the
drainage, the water and electricity supplies, the heating, and so on. Any one of these areas
can have problems that the contractors need to go back and fix. This is sometimes an
iterative process, in which problems with one aspect of the house can be the cause of things
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 don’t work
properly, you need to debug them. Debugging is the process of finding and correcting
errors in your program. This term is said to have originated in the days when finding the
errors in a program involved tracing where the information went and how it was processed
by using the circuit diagram for the computer.

The story goes that it was discovered that a computer program error was caused by an
insect shorting part of the circuit in the computer. The problem was caused by a bug.

Subsequently, the term bug was used to refer to any error in a program.

With a simple program, you can often find an error simply by inspecting the code. In
general, though, the process of debugging usually involves adding extra program code to
produce output that will enable you to check what the sequence of events is and what
intermediate values are produced in a program. With a large program, you’ll also need to
test the program modules in combination because, although the individual modules may
work, there’s no guarantee that they’ll work together! The jargon for this phase of program
development is integration testing.

5
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 requirements and his or her knowledge
systems development and the user working environment to create a test.

Plan that 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’s plan will
help us make sure we fully understand the requirements and also help us create our
own test plan.

Whitebox Testing

Whereas, Blackbox testing assume 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 house in which everything inside is
visible.

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


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
completely tested? In reality, there is no way to know for sure. But there are a few
things we can do 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 true 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 range, as well as items 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.

6
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 includes the necessary information about
the requirements of the program – the operating system and hardware requirements needed
for the program to run. It also contains technical information such as who created the
program, who to contact when there’s a problem with the program and instructions on the
use and maintenance of the program.

Maintenance

During this phase, the program is actively used by the users. If any enhancements
found in this phase, all the phases are to be repeated again to make the enhancements.
That means in this phase, the solution (program) is used by the end user. If the user
encounters any problem or wants any enhancement, then we need to repeat all the phases
from the starting, so that the encountered problem is solved or enhancement is added.

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

7
IT 103: COMPUTER PROGRAMMING 1
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.
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. Perform computations.
4. Display/Output Results
algorithm
Example:
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.
Remember!
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.
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). Example: long width = 5;
Remember!
Variables 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.

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.
Structured flow charts 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.
sequential
Problem 2
Design an algorithm and a flowchart that will compute for the sum, difference,
product, and quotient of two number and print them out.
sequential
Problem 3
Convert an input inch(es) into its equivalent centimeters (cm). Take note that
one inch is equivalent to 2.54 cm.

You might also like