MODULE 1 - Programming 1
MODULE 1 - Programming 1
Overview
This course introduces the fundamentals of logic formulation and allows the student to
learn and apply the art and style of procedural programming to solve computational problems
adhering to the standards and guidelines of documentation. It includes discussion on I/O
statements, loop and branching instructions, and creating functions and procedures. This
course will help the students in designing, implementing, testing and debugging a program
based on a given specification that uses such of the following fundamental programming
components: (1) primitive data types (2) basic computation (3) simple I/O (4) conditional and
iterative structures (5) definition of functions and parameters.
Objectives
At the end of the course, the students should be able to:
✓ Understand the concept of programming
✓ Define the terminology used in programming
✓ Learn the different programming paradigm and understand their uses
✓ Apply steps in program development.
✓ Design flowcharts and algorithms to solve the problems.
✓ Predict the results when an expression is evaluated.
Programming Concepts
of instructions that performs a specific task when executed by a computer. Your computer will not
be able to accomplish a task if you do not provide instructions for it to follow.
The people who write these instructions are called programmers. In order to write a
program to instruct a computer, you need to think about each problem clearly, breaking them into
something called methods. A typical computer program will be constructed of lots of these
methods, and each will contain commands and statements to perform the operations required.
In able to write computer instructions, programmers use a specific set of language, called
programming languages to create computer programs. Some popular languages are C++,
Visual Basic, C# and Java. In this module, you will use C++ programming language.
Just as human begins communicate with each other through the use of languages such
as English, Spanish, Hindi and Chinese, programmers use a variety of programming languages
to communicate with the computer. Following are the development of programming languages
from machine learning, assembly languages, and then to high-level languages.
Machine Languages
The machine language represents only the way to communicate directly with the
computer. As you can imagine, programming in machine language is very tedious and error-prone
and requires highly trained programmers.
Assembly Languages
High-Level Languages
Some high-level languages also offer additional program called an interpreter. Unlike
compiler, which translates all of a program’s high-level instructions before running the program,
an interpreter translates the instructions line by line as the program is running.
1. Structured Programming
The following are six steps in the Program Development Life Cycle:
1. Analyze the problem. The computer user must figure out the problem, then decide how
to resolve the problem - choose a program.
2. Design the algorithm. A flow chart is important to use during this step of the PDLC. This
is a visual diagram of the flow containing the program. This step will help you break down
the problem.
3. Implement the algorithm. This is using the language of programming to write the lines
of code. The code is called the listing or the source code. The computer user will run an
object code for this step.
4. Test and Verify Program. The computer user must debug. This is the process of finding
the "bugs" on the computer. The bugs are important to find because this is known as errors
in a program. One must run the program to make sure there are no syntax and logic errors.
Syntax are grammatical errors and logic errors are incorrect results.
5. Maintain and update the program. This step is the final step of gathering everything
together. Internal documentation is involved in this step because it explains the reason
one might have made a change in the program or how to write a program.[7]
You cannot solve a problem unless you understand it, and you cannot understand a
problem unless you analyze it – in other words, unless you identify its important components. The
two most important components of any problems are the problem’s output and its input. The
output is the goal of solving the problem, and the input is the item or items needed to achieve
the goal. When analyzing a problem, you always search first for the output and then for the input.
A helpful way to identify the output is to search the problem for an answer to the following
question: What does the user want to see displayed on the screen, printed on paper, or stored in
a file? The answer to this question typically is stated as nouns and adjectives in the problem
specification.
Treyson Mobley wants a program that calculates and displays the amount he
should tip a waiter at a restaurant. The program should subtract any liquor
charge from the total bill and then calculate the tip (using a percentage) on the
remainder.
Figure 7 indicates that Treyson (the program’s user) wants to see the amount of the
waiter’s tip displayed on the screen; therefore, the output is the tip.
After determining the output, you then determine the input. A helpful way to identify the
input is to search the problem specification for an answer to the following question: What
information will the computer need to know to display, print, or store the output items? As with the
output, the input typically is stated as nouns and adjectives in the problem specification. When
determining the input, it helps to think about the information that you would need to solve the
problem manually, because the computer will need to know the same information. In this case, to
determine the tip, both you and the computer need to know the total bill, the liquor charge, and
the tip percentage; these items, therefore, are the input.
The second step in the problem-solving process is to plan the algorithm that will transform the
problem’s input into its output. An algorithm is a step-by-step instruction that accomplish a task.
It is an English-like way of writing and expressing a solution to a problem. An algorithm helps
construct the actual program easily and clearly because it is like a blueprint of a program, it served
as an effective guide to our programming tasks.
Treyson Mobley wants a program that calculates and displays the amount he should tip a waiter at a restaurant. The
program should subtract any liquor charge from the total bill and then calculate the tip (using a percentage) on the
remainder.
Beside using pseudocode, programmers also use flowcharts when planning algorithms.
Unlike pseudocode, a flowchart uses standardized symbols to visually depict an algorithm. It is
the graphical representation of a program. A flowchart shows the logical sequence of instructions
which a computer has to follow. The major uses of flowchart are in program documentation and
program presentation.
You can draw the flowchart symbols by hand; or you can use drawing or shapes feature
in a word processor. You can also use a flowcharting program, such as SmartDraw or Visio.
The flowchart contains different symbols which are connected using lines, called
flowlines. Below are some of the basic symbols that are used in flowcharting:
Treyson Mobley wants a program that calculates and displays the amount he should tip a waiter at a
restaurant. The program should subtract any liquor charge from the total bill and then calculate the tip
(using a percentage) on the remainder.
Algorithm(flowchart)
start
Display tip
stop
After analyzing a problem and planning its algorithm, you then desk-check the algorithm
before implementing it using a chosen programming language. The term desk-check refers to
the fact that the programmer reviews the algorithm. You desk-check the algorithm to verify that
it is not missing any instructions and that the existing instructions are correct and in the proper
order. Once you checked that your algorithm is correct you can now convert the pseudocode
into the programming language that you will use to code your program.
Treyson Mobley wants a program that calculates and displays the amount he should tip a waiter at a
restaurant. The program should subtract any liquor charge from the total bill and then calculate the tip (using
a percentage) on the remainder.
In figure 12 you can see who the algorithm for the Treyson Mobley problem is converted
into a C++ statements. Do not worry if you do not understand yet the codes that are used in
C++. We will be discussing the C++ statements on the next modules. This diagram is just to
show you how a programmer uses pseudocodes as guide in writing program codes.
The next step is to evaluate and modify (if necessary) the program. You can test and
evaluate a program by entering your C++ instructions into the computer and then using the
computer to run (execute) the program. While the program is running, you enter the same sample
data used when desk-checking the program. If the results obtained when running the program
differ from those shown in the program’s desk-check, it indicates that the program contains errors,
referred to as bugs. The bugs must be located and removed from the program before the program
is released to the user. The programmer’s job is not finished until the program runs without errors
and produces the expected results.
The process of locating and correcting a bug in a program is called debugging. Program
bugs typically are caused by either syntax errors or logic errors. A syntax error occurs when you
break one of the programming language’s rules. A logic error can occur for a variety of reasons,
such as forgetting to enter an instruction or entering the instructions in the wrong order. Some
logic errors occur as a result of calculation statements that are correct syntactically but incorrect
mathematically.
In order to enter your C++ instructions into the computer, you need to have access to a
text editor, more simply referred to as an editor. You will also need a compiler which scans the
entire program and translate it as a whole into a machine code for the computer to understand.
The instructions you enter into an editor are called source code. Many C++ development tools
contain both editor and compiler in one integrated environment, referred to as IDE (Integrated
Development Environment). Examples include Microsoft Visual C++, Borland C++ Builder, and
CodeBlocks.
After testing, the software project is almost complete. The structure charts, pseudocodes,
flowcharts and decision tables developed during the design phase become documentation for
others who are associated with the software project. This phase ends by writing a manual that
provides an overview of the program’s functionality, tutorials for the beginner, in-depth
explanations of major program features, reference documentation of all program commands and
a thorough description of the error messages generated by the program. Even after the software
is completed, it needs to be maintained and evaluated regularly. In software maintenance, the
programming team fixes program errors and updates the software.[8]
Module 1: ACTIVITIES/ASSESSMENT
Activity 1.1 – Writing your own step-by-step procedure
There’s no one correct answer for each task. This exercise is to give you practice in converting
heuristic commands into equivalent algorithms.
Exercise 1: Determine a step-by-step procedure (list the steps) to do the following tasks:
a. Fix a flat tire.
b. Make a telephone call
c. Log on to a computer
d. Cook a sunny side up egg
c. Log on to a computer
1st __________________________
2nd __________________________
3rd __________________________
NOTE: Submit your Activities on our Google Class page in a document format on the specified
date. Late submission will have deduction in grades.
Module 1: ACTIVITIES/ASSESSMENT
Activity 1.2 – Program problem analysis
In each of these exercises, a programming problem is given. Read the problem statement first,
and then answer the question pertaining to the problem. Do not attempt to write a program to
solve problems. Instead, simply answer the questions following the program specifications.
Exercise 1: You’ve been asked to write a program to calculate the value of distance, in miles,
given this relationship: distance = rate X elapsed time
Exercise 2: You’ve been asked to write a program that calculates the average grade of a student
based on his/her 3 quizzes.
NOTE: Submit your Activities on our Google Class page in a document format on the
specified date. Late submission will have deduction in grades.
Module 1: ACTIVITIES/ASSESSMENT
Exercise 1: Write an algorithm and create a flowchart that computes and prints the sum of two
input numbers.
Exercise 2: Write an algorithm and create a flowchart that determines if the input number is
ODD or EVEN number.
Exercise 3: Write an algorithm and draw a flowchart that will compute the average of 3 quizzes
entered by the user. And then determine if the average of the 3 quizzes is passing grade or
failing grade. The passing grade is 75 and above. Display the average grade and remark (Pass
or failed)
NOTE: Submit your Activities on our Google Class page in a document format on the specified
date. Late submission will have deduction in grades.
References
1. https://www.assignmentexpert.com/blog/wp-content/uploads/2019/10/hardest-
programming-language.png
2. Bebbington, Shaun (2014). "What is coding". Tumblr. Archived from the original on 2020-04-29.
Retrieved 2014-03-03.
3. https://medium.com/@rats/java-basics-how-java-is-understood-by-your-machine-
57161a212b85
4. https://microcontrollerslab.com/pic-microcontroller-assembly-language/
5. https://techterms.com/definition/high-level_language
6. https://www.techdotmatrix.com/2018/01/high-level-programming-language-low-level-
programming-language/
7. http://blog.teachbook.com.au/index.php/computer-science/software-development/program-
development-lifecycle/
8. https://www.geeksforgeeks.org/software-engineering-program-development-life-cycle-pdlc/
9. Pomperada, Jake (2018). Introduction to Java Programming