Unit-1 Intro To Programming - Edited PDF
Unit-1 Intro To Programming - Edited PDF
Unit-1 Intro To Programming - Edited PDF
UNIT
1 Introduction to
Programming
1
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Read each item carefully, then circle the letter that best represent your answer.
1. Which of the following do you think is the native tongue language of a computer?
This language instruction is a binary string of 0’s and 1’s that specifies an operation
and identifies the memory cells involved in the process.
a. Assembly language
b. Machine Language
c. Low-level language
d. High-Level language
a. Process Flowchart
b. Program Flowchart
c. System Flowchart
d. Scientific Flowchart
2
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
b. False
4. Which of the following choices below is a list or rundown of steps for solving a
problem in C++ programming? It requires the programmer to write the step-by-step
method or procedure and then verify that it solves the problem as intended.
a. Flowchart
b. Algorithm
c. Constant
d. Variables
a. Operand
b. Multiplication
c. Exponent
d. Modulus
a. Computer Technician
b. Computer Analyst
c. Computer Programmer
d. Computer Specialist
b. False
3
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
8. Which of the following is a program statement that checks an expression that may
or may not perform a statement or group of statements?
a. Conditional Expression
b. Conditional Execute
c. Conditional Statement
d. Conditional Symbol
9. The following selections you see below are a C++ programming language that can
deliver little or no abstraction from the computer's instruction command of set
architecture.
a. Machine Language
b. Low-level language
c. High-Level language
d. Assembly language
a. Machine Language
b. Low-level language
c. High-Level language
d. Assembly language
4
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
LESSON 1:
Basic Programming Concepts
OBJECTIVES:
At the end of the lesson, students will be able to:
DURATION: 2 hours
5
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Introduction
Think about some various ways that people use computers. Each student uses
a computer to do some different tasks in school, such as typing a document, searching
for articles, sending an email, and participating or giving contributions in an online
class. At work, individuals use PCs to analyze data, make presentations, conduct
business transactions, communicate with colleagues and customers, control
machines in manufacturing facilities, and do numerous different things. At home,
individuals use PCs for various tasks such as paying bills, shopping online,
Figure 1. Microsoft Word and Adobe Photoshop. An example of Word Processing and Image Editing Program
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.
6
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Computer Programming
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.
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.
Each programming language has its own set of words and rules, called the
syntax of that language. If you are working on writing a computer program, you have
to follow the syntax of the language you are using; otherwise, you would not be
understood.
7
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Machine Language
Source: https://dfarq.homeip.net/
Example:
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
High-Level Language
High-level languages, such as *COBOL, VISUAL BASIC, JAVA, etc. are some
of the popular languages used by the programmers. It is named high-level languages
to distinguish them from the machine and symbolic languages. It is also called
compiler languages since these languages require a unique program called a
9
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Language Description
Ada was developed in the 1970s,
Ada primarily for applications used by the
U.S. Department of Defense. This
computer language is named honor of
the “Countess Ada Lovelace" it is a
meaningful and vital historical symbol in
computing.
Beginners All-purpose Symbolic
Instruction Code is a general purpose-
BASIC language initially an outline designed in
the early 1960s to be straightforward
adequate for beginners to gain
knowledge. Nowadays, there are many
different versions of BASIC.
FORmulaTRANslator was the first high-
FORTRAN level programming language. It was
originally developed in the 1950s to carry
out complex arithmetic or mathematical
calculations.
Common Business-Oriented Language
COBOL was developed in the 1950s and was
designed for business applications.
Pascal was created in 1970 and was
Pascal initially designed for teaching computer
programming. The language was named
under the mathematician, physicist, and
philosopher Blaise Pascal.
C and C++ (it is pronounced as a "c plus
C and C++ plus"), and it is a powerful, general-
purpose computer language developed
at the Bell Laboratories. The C language
was developed in 1972, and the C++
language was developed in 1983.
Pronounced “c sharp. “This language
C# was created by Microsoft around 2000
10
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Assembly Language
Now we could say that high-level languages are a lot easier to understand over
low-level languages. Let us take a look at the example below:
Let us say we want the value of a memory cell to be equal to number fifteen
(15). In a high-level language, we could simply accomplish this by writing: int x = 15;
11
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
where:
int (based from the dictionary word integer is a reserved word used to identify
the data type of a number equal (=) sign ( a generally accepted mathematical symbol)
is used to denote an equation process, 15 is simply the decimal value of the number
we wanted to be in a memory cell, x is any valid variable representing the computer
memory cell.
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.
It takes more time and effort to write the code for the same.
It is very complex and challenging to understand.
The syntax is difficult to remember.
It has a lack of portability computer programs among different computer
architectures.
It needs more size or memory of the computer to run the extended programs
written in Assembly Language.
12
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
On the other hand, an interpreter to translate the high-level instructions into machine-
understandable instructions (binary code) at runtime. A computer programmer cannot
run the computer program on a machine except if the right interpreter is available.
INTERPRETER COMPILER
Scans the whole computer program and
Translates the program one statement
translates it as an entire into machine
at a time.
code.
Interpreters typically take a small
Compilers typically take a massive
amount of time to examine the source
amount of period to analyze the source
code. However, the general
code. But the available execution time is
implementation time is comparatively
reasonably faster than interpreters.
slower than compilers.
It generates the middle object code,
None intermediate object code is
which further needs linking. Thus it
generated, thus a memory efficient.
requires more memory.
13
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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.
This is the process of developing and modifying source code - the name given to
the program instructions you write. Some C++ compilers come with a precise editor
that can deliver a lot of support in managing your computer programs. An editor often
provides a complete environment for writing, collecting, developing, and testing your
programs. This is sometimes called an integrated development environment, or
IDE.
You can also use some other editors to create your source files, but they must store
the code as plaintext without any extra formatting data embedded in it. Overall, if you
have a compiler system used and with an editor indicate, it will give a lot of features of
attributes that make it easier to write and organize your source code programs. There
will usually be automatic facilities for placing out the program text correctly, and color
highlighting for main essential language elements, which not only makes your code
more readable, also provides a clear indicator when you make errors when inputting
in such words.
On a Personal Computer, you could use one of the numerous free software and share
software computer programming editors. These will provide a lot of help in ensuring
your code is correct with syntax highlighting and auto indenting of your code. Try not
to utilize a word processor, for example, Microsoft Word, as these are not appropriate
for delivering a program code in light of the extra formatting information they store
beside the text. Purchasing one of the professionally developed programming
development environments which support C++, such as Borland or Microsoft, in which
case you will have pervasive editing capabilities. Before parting with your cash,
though, it is a good idea to manage that the level of C++ that is supported is
approximate to the current C++ standard.
Compiling Programs
14
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
The compiler converts your source code into machine language and distinguish and
reports the errors in the compilation process. The input to this phase is the file you
produce during your editing, usually referred to as a source file.
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.
Program libraries extend and support the C++ language by providing routines
to carry out operations that are not part of the language. For instance, libraries
comprise procedures that support processes such as performing input and output,
calculating a mathematical square root, can compare two-character strings, or acquire
date and time information.
A failure during the linking phase means that you have to go back and edit your
source code once again. Success, on the other hand, will produce an executable file.
In a Microsoft Windows environment, this executable file will have a .exe extension.
Several IDEs also take Build options, which compile and link your computer program
in one step. This possibility will usually be found inside an IDE, in the Compile menu,
or a menu of its own.
Executing Programs
The execution phase is where you run your program, having completed all the
last process successfully. This phase can also generate a wide variety of errors that
can contain producing the wrong output. In all cases, it is back to the editing process
to check your source code.
15
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
In IDEs, you will find a suitable menu command that lets you run or execute
your compiled computer program. This Run or Execute selection may have a menu
of its own, or you may find it under the Compile menu option.
In Windows, you can run the.exe file for your program as you would any other
executable. The procedures of editing a program, compiling a program, linking a
program, and executing a program are essentially the same for developing computer
programs in any environment and with any compiled language.
Programming Paradigm
Procedural Programming
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
PROCEDURAL ORIENTED
OBJECT ORIENTED PROGRAMMING
PROGRAMMING
In procedural programming, the In object-oriented programming, the
computer program is divided into a little program is divided into small parts
part called the functions. called objects.
Procedural programming follows a top- Object-oriented programming follows a
down approach. bottom-up approach.
Object-oriented programming has
There is no access specifier in
access specifiers like private, public,
procedural programming.
protected, etc.
Adding new data and functions is not
Adding new data and functions is easy.
easy.
Procedural programming does not have
Object-oriented programming provides
any proper way of hiding data, so it is
data hiding, so it is more secure.
less secure.
In procedural programming, overloading Overloading is possible in object-
is not possible. oriented programming.
In procedural programming, the function In object-oriented programming, data is
is much essential than data. more important than function.
Procedural programming is based on an Object-oriented programming is based
unreal world. on the real world.
Examples: C, FORTRAN, Pascal,
Examples: C++, Java, Python, C#, etc.
Basic, etc.
17
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
18
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
_____2. In most IDEs, you’ll find a suitable menu command which allows the
programmer to run or execute the compiled program.
_____3. The execution phase is where the programmer runs the program and has
completed all the previous procedures successfully.
_____4. A failure during the linking phase means that you have to go back and edit
your source code once again.
_____5. The whole computer program can usually develop in such a decrement
manner.
_____8. Writing and Editing Programs is the process of creating and modifying
source code.
_____9. You can also use other editors to create your source files, but they must
store the code as plain text and with any extra formatting data embedded in it
_____10. MOV is an instruction telling the processor to equate the value of computer
memory.
19
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
20
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
The figure1.4 above illustrates the usage of software. You will see that the
image shows on some significance of software. What do you think is the relevance of
the software in our daily lives?
21
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
22
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
11. remainder
LESSON 2:
Program Development
OBJECTIVES:
At the end of the lesson, students will be able to:
DURATION: 3 hours
23
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Once you have reached this more precise specification, you can work out the
series of steps to direct your final objective. It is like the idea of building a house; you
need to know what kind of place you want, how large it is going to be, what types of
materials, and where you want to make it. This kind of detailed planning is necessary
when you want to compose or write a program.
Also, the first step is to get a clear idea of what you want to do.
For example:
To start building your house, you should consider what facilities it ought
to provide: like how many bedrooms, or how many bathrooms, or how
big it is going to be, etc.
All these things affect the house cost in terms of materials and the work
involved in building it. Mostly, it originates down to a compromise that
best sees your requirements within the limitations of the budget allotted,
the workforce, and the time that is accessible for you to finish the project.
It is the same as developing a program of any size. Even for a generally exact
issue, you need to know what kind of input to expect, how the information is to be
prepared, and what sort of output is required and how it will look. The data could be
entered with the keyboard, but it might also involve data from a disk file, or information
achieves over a telephone line or a network.
The output could be displayed on the screen or printed; perhaps it might involve
updating a data file on disk.
24
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Note:
For more composite programs, you will need to look at many more
features of what the computer program will do. A direct definition of the problem
that your program is going to solve is an essential part of understanding the
resources and efforts that are going to be needed for the creation of a finished
product. Since these details also drive you to found whether the project is
possible.
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 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:
The structure chart is used to design the whole program. Pseudocode and
flowcharts, on the other hand, are used to develop the individual parts of the program.
These parts are known as modules in pseudocode or functions in the C++ language.
25
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
The hierarchy chart (also known as the structure chart) displays the
connection among several modules. Its name originates from its general use in
viewing the organization (or structure) of a corporate or business. For example, it is
the President at the top, then vice presidents on the next level, etc. In the context of a
program, it displays the connection among modules (or functions). Detail logic of the
program is not offered. It does represent the organization of the processes used within
the program showing which functions are calling on a subordinate process.
Hierarchy charts are generated by the computer programmer to aid the document in
a program. They carry the large image of the modules (or functions) used in a program.
Figure 2. Hierarchy or Structure chart for a program that has a five function
Source: https://press.rebus.community/programmingfundamentals/
26
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Implementation
With the detailed design of a house, the work can start. Each group of
construction workers will start completing their parts of the project at the right time.
Each phase will need to be examined to check that it has been done correctly before
the following phase begins. Except these checks could simply result in the entire
house collapsing.
Naturally, if a program is enormous, you will write the computer source code
one element at a time. As one part is completed, you can now proceed writing the
next. Each part of the code will be based on the detailed design specifications; it must
verify that each piece performs the intended task, as much as you can, before
proceeding. It will enable you to gradually progress to a fully functioning program that
does everything you originally intended.
In this stage, we see whether the code was written in the previous step is
solving the specified problem or not. That means we test the program, whether it is
solving the problem for several input information values or not. We also test whether
it could come up with the desired output or not.
The house is complete, but there are still a lot of things that need to be tested:
the water and electrical outlet, the water pump, the heating, and so on. Any of these
areas can have problems that need to be fixed. This is occasionally a reiterative
process, in which issues with one feature of the house can be the reason of effects
going wrong somewhere else.
The mechanism with a program is similar. Each of your program modules, the
pieces that make up your program, will need to be tested individually. When they do
not work correctly, there is a need to debug them. Debugging is the process of finding
and correcting errors in your program. When in finding the errors in a program, it
involves tracing where the information went and how it was processed
The term bug is used to denote any error in a program. It term came from a discovery
that a computer program error was caused by an insect shorting part of the circuit in
the computer.
By inspecting the code of a simple program, you can often find an error by
merely inspecting the code. The process of debugging a computer usually includes
adding extra program code to create output that will empower you to check what the
arrangement of events is and what intermediate values are produced in a computer
program. With a huge program, you will also need to test the computer program
modules in combination. Although the discrete modules may work, there is no
assurance that they will work together! The jargon for this stage of the program
development is integration testing.
27
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
There are two types of testing: Blackbox and Whitebox. The system test
engineer and the user do Blackbox testing. Whitebox testing is the responsibility of the
programmer.
Blackbox Testing
Blackbox Testing gets its name from the concept of testing the program
without knowing what is inside it- without knowing how It works. In other words,
the program is like a black box that we cannot see into.
The plan will then be used when the system is tested as a whole. We
should ask to see this test plan before we write our program. The test engineer
goal will help us make sure we fully understand the requirements and also help
us create our test plan.
Whitebox Testing
Whereas Blackbox testing assumes that the tester knows nothing about
the program, Whitebox testing assumes that the tester knows everything about
the program. In this case, the program is like a glass in which everything inside
is visible.
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.
3) For every condition that has a range, make sure the tests include the
first and last items in the content, as well as things below the first and
above the last-the most common mistakes in array range tests occur
at the extreme of the range.
4) If error conditions are being checked, make sure all error logic is
tested. This may require us to make temporary modifications to our
program to force the errors.
28
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Program Documentation
When the program is finished and thoroughly tested, the documentation on the
program is included for its distribution. Documentation usually contains the necessary
information about the program requirements – the operating system and hardware
requirements needed for the program to run. It also includes technical data such as
who created the program, whom to contact in case of a problem with the program, and
instructions on the use and maintenance of the program.
Maintenance
At this stage, the computer program is actively used by the users. If any
improvements are found in this stage, all the steps are to be repeated to make the
enhancements. That means, in this stage, the solution (program) is used by the end-
user. If the user experiences any issue or needs any improvement, then we need to
repeat all the stages from the beginning, so that the encountered problem is answered
or enhancement is added.
This final stage in programming is maintaining or updating the program. This is the
phase where the programmer has to keep the program running smoothly and updated
with the developments and changes in the field where it is used
29
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
IDENTIFICATION: From the pool of words below, choose the appropriate answer to
the following descriptions in the answer boxes.
Debugging Flowchart
Structure Chart Psuedocode Flowcharts
Hierarchy Chart Algorithm
Bug Blackbox Testing
Maintenance Whitebox Testing
______________8. Originally comes from the concept of testing the program without
knowing what is inside it- without knowing how It works.
______________9. Testing implies everything about the software is known to the tester.
______________10. This is where the programmer is charged with keeping the software
running smoothly and updating with the enhancements and changes in the area where it
is used.
30
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Answer the following questions. Read carefully and write your answer on the space
provided.
Give ONE problem or a scenario that you will apply the 6 phases of the program
development process. You may use another paper for your answer.
Implementation
_____________________________________________________________________
_____________________________________________________________________
Maintenance
_____________________________________________________________________
_____________________________________________________________________
31
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
32
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
LESSON 3:
Logic Formulation
OBJECTIVES:
At the end of the lesson, students will be able to:
DURATION: 5 hours
33
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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
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:
34
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
The above example simply breaks down the problem into sub-problems that
need to be solved before coming up with the required answer. First, you have to know
how many apples the customer is buying before you can make any computations.
Next, you then compute the cost depending on the number of apples purchased and
then use a formula that would calculate the appropriate value. Finally, you then come
up with the answer through the calculations you made. You cannot give a solution to
the problem immediately by saying outright how much the apples cost without first
knowing how many apples are being purchased, how much is the cost of apples if
there were discounts and performing the calculations based on them .
Flowchart
Variable - The memory cells used for storing a program’s input data and its
computational results are called variables. It is the representation of an idea
that is changing.
For Example:
int a, b, c;
Constant - Named item is used to specify a name for a memory cell that will
contain a value that does not change (fixed amount).
For Example:
long width = 5;
Note:
35
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
V ariables that hold a number must be initialized by equating it to zero, and variables
that will keep word(s) may be initialized by equating it to space and enclosed it in double-
quotes (name" ")
Types of Flowchart
36
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Flowcharting Symbols
37
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Flowchart Development
The phases that encompass a flowchart must be ordered in an arranged,
understandable, and transparent manner. The program that executes this flowchart is
likewise in an orderly, understandable, and transparent way. An orderly, legible, and
exact solution is called a structured flowchart.
38
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Structured flowcharts are designed using the four program structures, namely:
a) Sequential - Steps are carried out in a firmly sequential manner; each stage is
performed exactly once.
These structures will be our guide to produce a correct structured flowchart necessary
to prepare the right program.
Sequential
In this structure, steps are performed in a strictly sequential manner and are
executed once. This is the simplest method of control. It is easy to develop and
understand. The following problems in flowcharting illustrate simple logic flow.
Problem 1
Design an algorithm and flowchart that would determine the product of two numbers.
Algorithm
START
1: Define the variables.
(Let A be the first number A=0
B=0
and B as the second C=0
number, C for a product).
2: Initialize the values to be used: Input
A,B
A = 0, B= 0, C= 0
3: Input values for A and B. C = A* B
39
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Problem 2
Design an algorithm and a flowchart that will compute for the sum, difference, product,
and quotient of these values and print them out.
Algorithm
1. Define the variables.
(Let X, be the first number and Y as the
second number, SUM for sum, DIFF for
difference PROD for a product, and QUO for
quotient).
2. Initialize the variables to be used.
3. Input values for X and Y.
4. Calculate the sum, difference, product, and
quotient of the two values read.
5. Output the computed values (sum, average,
product, and quotient).
START
Input
X, Y
END
40
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Selection
Problem 3
Design an algorithm and a flowchart that will determine if the grade of a student is
"passed" or failed," considered 75 as the passing grade.
Algorithm
1. Define the variables.
(Let G be the grade of a student)
2. Initialize the variables to be used.
3. Input student grade.
4. Test if G is greater than or less than 75.
5. If G is greater than or equal to 75, print "Passed," and if it is less than 75, print
"Failed."
Start
G =0;
Input
G
True
If Print
G >=75 “Passed”
False
Print
“Failed”
End
41
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Problem 4
Algorithm
1. Define the variables to be used
(Let S be the salary, B for bonus of the employee)
2. Initialize the variables to be used.
3. Input salary.
4. Test the value of the salary. If S is less than 10,000, then the bonus of the
employee is fifty percent of the salary. If the salary is greater than or equal to
10,000, the bonus is equivalent to their monthly salary.
5. Output the corresponding bonus of the employees.
START
S = 0; B = 0
INPUT
True
IF
S < 10,000 B = S *0 .50 A
False
B=S
Output B
END
42
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Problem 5:
Design an algorithm and a flowchart that will examine the value of the temperature.
Then display the following messages depending on the value assigned to temp.
Temperature Message
Less than 0 ICE
Between 0 and 100 WATER
Exceeds 100 STEAM
Algorithm
1. Define the variables. (Let temp be variable for the temperature)
2. Initialize the variables to be used.
3. Input the value of temp.
4. Test if the value of temp is less than 0, between 0 and 100, or exceeds 100.
5. If the temp is less than zero, print "ICE," and if the number is greater than or equal
to zero and less than or equal to 100, print "WATER". Else the number is greater
than 100, print "STEAM."
START
temp = 0
input
temp
True
IF PRINT A
temp< 0 “ICE”
False
True
IF
temp>=0 and PRINT
temp < = 100N “WATER” A
False
PRINT
“STEAM”
END
43
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Repetition
A Loop is used when it is desired to make the same calculation on more than
one set of data. It consists of repeating a program, or a selection of programs, and
substituting new data for each repetition. A computer program loops play an important
part in data processing since they provide efficient means of processing several sets
of data with the identical program segment.
Problem6
Design a flowchart that will print “Hello “twenty times.
Solution 1
Algorithm:
1. Define the variables to be used. (Let x be the counter)
2. Initialize the counter x = 1.
3. Test the value of x. if the value of x < = 20 Print “Hello”, else end of program.
4. Increment x (x=x+1).
5. Repeat step 3.
START
X=1
False
X <= 20
END
True
X=X+1
44
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Solution 2
Algorithm:
1. Define the variables to be used. (Let x be the counter)
2. Initialize the x = 0.
3. Print “Hello”
a. Increment x Increment x (x=x+1).
4. Test the value of x. if the value of x < = 20 repeat step 3, else end of program.
.
START
X=0
X=X+1
True
False
X <= 20
END
Modular Structure
Most computer programs perform a task that is huge enough to be broken down
into various subtasks. For this reason, computer programmers usually break down
their programs into modules. A module is a set of statements that exist within a
program to perform a specific task. Instead of writing a massive program as one long
sequence of statements, numerous small modules can be written; each carries out a
specific part of the task. These modules can then be executed in the want order to
perform the overall task.
The approach is sometimes called divide and conquer because an enormous
task is divided into several smaller tasks that are easily performed. This approach is
represented by the structure chart. A structure chart, also is known as a hierarchy
chart, shows the functional flow through the different modules in a program. For
45
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
example, let us write separate modules for the kitchen, bathroom(s), bedrooms, family
room, and living room in designing the flooring of a house, as illustrated below.
Flooring
Every modern programming language lets you create modules that are
commonly called procedures, subroutines, subprograms, methods, and functions.
Simpler Code
Code Reuse
Better Testing
The testing and debugging of the program get less complex when every
programming task is contained in a module. Developers can test every module
in a program independently to determine whether it correctly performs its
operation. This makes it simpler to segregate and fix errors.
46
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Faster Development
Top-Down Design
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.
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.
A module call is shown in a flowchart with a rectangle with vertical bars on each
side. The name of the module that is being called is written on the symbol.
Message( )
47
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
start
Display “I have a
message for you.”
Message()
return
Display “That’s
all.”
end
48
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Flowchart Tracing
To determine the correctness of logic flow within any given flowcharting, it will
usually require some tracing and testing. Tracing, it will provide a clearer
understanding of the processing steps involved. This will usually require the use of
actual test data values. The first step is to have a list of variables to hold different
values during the processing operation. We begin tracing the flowchart with the first
instruction and continue by following the appropriate flow lines and flow direction
indicators.
1. START
A=0;B=0;
C=0;D=0;
A=B+1
Output C
Compute the value of C. Result: C =42
END
Output:42
49
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
(Sequential)
Convert an input inch(es) into its equivalent centimeters (cm). Take note that one inch
is equivalent to 2.54 cm.
50
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
(Selection)
Determine if the number inputted is an even or odd number.
51
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
(Repetition)
Compute for the sum of all even numbers among the ten inputted numbers
52
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
APPLICATION ACTIVITY FOR LESSON 3
Trace the output for each set of the given input of the flowchart below. Write your
answer inside the table given below.
c=c+a
a=a+b
T
Is
a<=20
?
F
Print a, b, c
End
53
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
54
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
1.
START
A=0;B=0;
INPUT B INPUT C
C=0;D=0; 5 42
10
14
INPUT B
45
80
A=B+1
D=A+1
C=A*D
Output C
END
55
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
START
X=0
The value of x is
initialized to 0.
B
X = X +1
False
PRINT X
Test if x <=50 if true,
the program will
repeat the process of
END incrementing the
value of x Output: _____
56
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Read each item carefully, then circle the letter that best represent your answer.
1. C++ program was developed by Bjarne Stroustrup, starting in 1991 at the Bell
Labs in Murray Hill.
a. True
b. False
b. Algorithm
c. Constant
d. Variables
3. This mathematical operator uses C++ programming that performs division, but
instead of returning the quotient, it returns the remainder.
a. Operand
b. Modulus
c. Multiplication
d. Exponent
4. Is the person who designs or creates, codes, tests, debugs, and documents a
computer program?
a. Computer Programmer
57
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
b. Computer Programing
c. Computer Program
d. Computer Programmable
b. Assembly language
c. Low-level language
d. High-Level language
a. System Flowchart
b. Scientific Flowchart
c. Process Flowchart
d. Program Flowchart
7. This program statement checks an expression that may or may not execute a
statement or group of statements?
a. Conditional Expression
b. Conditional Execute
c. Conditional Statement
d. Conditional Declaration
b. Low-level language
c. High-Level language
d. Assembly language
58
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
a. Machine Language
b. Low-level language
c. High-Level language
d. Assembly language
a. True
b. False
59
IT 103: COMPUTER PROGRAMMING 1