Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
54 views

Module - Unit-1 Intro To Programming

The document discusses basic programming concepts and introduces UNIT 1 of a computer programming course. It covers: 1) The definition of a computer program and programming. Programming involves writing instructions for a computer in the form of source code. 2) The different categories of programming languages from low-level machine language to high-level languages. Low-level languages are close to machine instructions while high-level languages resemble everyday language. 3) The first lesson of UNIT 1 which explains what a program is, differentiates programming language categories, and identifies the steps in program development.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Module - Unit-1 Intro To Programming

The document discusses basic programming concepts and introduces UNIT 1 of a computer programming course. It covers: 1) The definition of a computer program and programming. Programming involves writing instructions for a computer in the form of source code. 2) The different categories of programming languages from low-level machine language to high-level languages. Low-level languages are close to machine instructions while high-level languages resemble everyday language. 3) The first lesson of UNIT 1 which explains what a program is, differentiates programming language categories, and identifies the steps in program development.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

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

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

2
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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 Figure 1.1. A Computer Programming Clipart
computer program. Programming Source: https://www.freecodecamp.org/

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
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

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:

Boil some water


Pour hot water in a cup with a teabag
Figure 1.2. Computer Programmer Let the tea brew
Source: https://www.freecodecamp.org/ Remove the teabag
tea as an example. 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.

4
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
processor in a programming language is written in a Source: https://www.techdotmatrix.com/

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.
5
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
everyday language.
Source: https://www.techdotmatrix.com/

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
compiler, which translates programs written in a particular language into a machine
6
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

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
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

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

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;

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

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

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.

9
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming
Multimedia ConceptsConcepts

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.

10
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.

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

✔ Compiling Programs

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
12
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming
Multimedia ConceptsConcepts

can contain producing the wrong output. In all cases, it is back to the editing process
to check your source code.

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.

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

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.

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.

14
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming
Multimedia ConceptsConcepts

LESSON 2:
1. remainder

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

15
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 a
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 are, 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 requirements, 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, 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 a disk.

16
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.

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
17
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts

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/

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 toward 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, cannot 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 illustrating a flowchart for an
algorithm is known as “flowcharting”.

18
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 with 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 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 for 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 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. Its 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 program
development is integration testing.

19
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 it is inside- 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 of
systems development and the user working environment to create a test.

The plan will then be used when the system is tested. We should ask to
see this test plan before we write our program. The test engineer’s goal will help
us make sure we fully understand the requirements and 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 programmers, 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? 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.

20
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 must keep the program running smoothly and updated
with the developments and changes in the field where it is used

21
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

22
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming
Multimedia ConceptsConcepts

What is the Program Logic Formulation?

Computers are logical machines. They follow instructions down to the letter
(follow 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 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 (like a recipe) for solving a problem. Designing


or creating an algorithm to solve a problem needs to write step-by-step measures and
then verifying 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.

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 must know
how many apples the customer is buying before you can make any computations.
23
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming
Multimedia ConceptsConcepts

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 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:

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 enclosing it in double-
quotes (name" ")

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

Types of Flowcharts

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 workstations through which
the data passes. It illustrates more the system elements; little is shown about how
processing will be accomplished.

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.

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

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 is used to change the reading order on the same page. On-page
connectors conserve space by keeping related blocks near one another
and lessen 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.

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 the 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 the END symbol.
2. Symbols are interconnected using arrows.
3. Use a 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.

26
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming
Multimedia ConceptsConcepts

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 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 producing the 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 A=0
B=0
number and B as the C=0
second number, C for a
product).
Input
A,B
2: Initialize the values to be used:
A = 0, B= 0, C= 0
C = A* B
3: Input values for A and B.
4: Calculate the product of the two
Output C
numbers. C = A*B. 27
IT 103: COMPUTER PROGRAMMING 1
5: Output the product.
END
UNIT 1: Basic Programming Concepts

Problem 2
Design an algorithm and a flowchart that will compute 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

28
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

29
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

30
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

31
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. Computer program loops play an important
part in data processing since they provide efficient means of processing several sets
of data with an 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

32
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

33
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.

34
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( )
35
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

36
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming
Multimedia ConceptsConcepts

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;

INPUT B The input value of 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

37
IT 103: COMPUTER PROGRAMMING 1

You might also like