Professional Documents
Culture Documents
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
a. Process Flowchart
b. Program Flowchart
c. System Flowchart
d. Scientific Flowchart
2
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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
c. Computer Programmer
d. Computer Specialist
3
IT 103: COMPUTER PROGRAMMING 1
a. True
b. False
4
IT 103: COMPUTER PROGRAMMING 1
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
5
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
6
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
7
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.
8
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.
9
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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.
Machine Language
Source: https://dfarq.homeip.net/
Example:
Low-Level Language
10
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
High-Level Language
11
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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
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.
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
BASIC purposelanguage 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
FORTRAN highlevel programming language. It was
originally developed in the 1950s to
carry out complex arithmetic or
mathematical calculations.
12
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Assembly Language
13
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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 we wanted to be in a memory cell, x is any valid variable representing the
computer memory cell.
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.
14
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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.
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.
15
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
INTERPRETER COMPILER
Scans the whole computer program and
Translates the program one statement at
translates it as an entire into machine
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.
16
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.
17
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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
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
18
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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.
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
19
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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 called
part called the functions. objects.
Procedural programming follows a Object-oriented programming follows a
topdown 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 objectoriented
is not possible. 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
20
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
21
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
22
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.
23
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
24
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?
25
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
26
IT 103: COMPUTER PROGRAMMING 1
27
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
28
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
The process of developing a program in C++ may not be visible if you have
never written a computer program before. However, it is very similar to various
situations in life in which at the start, it just is not clear how you are going to attain
your objective. Generally, you start with a rough idea of what you want to attain, but
you need to interpret this into an additional exact specification of what you want.
Once you have reached this more precise specification, you can work out the
series of steps to direct your final objective. It is like the idea of building a house; you
need to know what kind of place you want, how large it is going to be, what types of
materials, and where you want to make it. This kind of detailed planning is necessary
when you want to compose or write a program.
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.
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:
30
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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 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/
31
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.
32
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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.
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
33
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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.
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
enduser. 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
34
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
35
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
______________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.
36
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
______________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.
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
_____________________________________________________________________
_____________________________________________________________________
Name: _______________________________ Date: _______________________
Course & Section: _____________________ Result: _____________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
38
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
40
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
Program Logic Formulation deals with this problem. It provides the tools
needed to design the right solution by helping you define and identify the problem, its
requirements, and the required instructions.
The two most commonly used tools will be of great help for you to formulate a
better solution. These are the flowchart and algorithm.
Algorithm
An algorithm is a list of steps (similar to a recipe) for solving a problem.
Designing or creating an algorithm to solve a problem needs to write step-by-step
measures and then verify that the problem is solved as intended. This is often the
most challenging part of the problem-solving process. To design the solution for a
problem using an algorithm, programmers use a method called top-down design
(also called divide and conquer).
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:
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
41
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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
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.
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).
42
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
For
Example: long
width = 5;
Note:
Variables that hold a number must be initialized by equating it to zero, and variables that
will keep word(s) may be initialized by equating it to space and enclosed it in doublequotes
(name" ")
Types of Flowchart
Flowcharting Symbols
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.
45
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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 and B as the A=0
second number, C for a product). B=0
C=0
END
46
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
Input
X, Y
END
47
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
48
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
Problem 5:
49
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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 < = 100 N “WATER” A
False
PRINT
“STEAM ”
END
50
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
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
51
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
52
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
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.
53
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.
Message( )
start
Display “I have a
Message() message for you.”
return
Display “That’s
all.”
end
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.
55
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
1. START
A=0;B=0;
C=0;D=0;
A=B+1
Compute the value of A.
Result: B=5; A=6
D=A+1
Output C
Compute the value of C. Result: C =42
END
Output:42
56
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.
57
IT 103: COMPUTER PROGRAMMING 1
UNIT 1: Basic Programming Concepts
(Selection)
Determine if the number inputted is an even or odd number.
(Repetition)
Compute for the sum of all even numbers among the ten inputted numbers
T
Is
a<=20
Print a, b, c
End
1.
START
INPUT B INPUT C
5 42
A=0;B=0; 10
C=0;D=0;
14
INPUT B 45
80
A=B+1
D=A+1
C=A*D
Output C
END
START
The value of x is
X=0
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: _____
1. C++ program was developed by Bjarne Stroustrup, starting in 1991 at the Bell
Labs in Murray Hill.
a. True
b. False
3. This mathematical operator uses C++ programming that performs division, but
instead of returning the quotient, it returns the
mainder.
re
a. Operand
b. Modulus
c. Multiplication
d. Exponent
4. Is the person who designs or creates, codes, tests, debugs, and documents a
a. Computer Programmer
b. Computer Programing
c. Computer Program
d. Computer Programmable
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
a. True
b. False