0% found this document useful (0 votes)
3 views

CC111_ComputerProgramming1_PRELIM_DAY 1 to 2

The document is a student learning module for the course CC111 - Computer Programming 1 at the Polytechnic College of Botolan, covering fundamental programming concepts. It outlines the stages of program development, including problem definition, solution design, coding, testing, and maintenance, while also discussing different programming languages and their characteristics. The module emphasizes the importance of documentation and debugging in programming to ensure effective and efficient software development.

Uploaded by

rhysse52
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CC111_ComputerProgramming1_PRELIM_DAY 1 to 2

The document is a student learning module for the course CC111 - Computer Programming 1 at the Polytechnic College of Botolan, covering fundamental programming concepts. It outlines the stages of program development, including problem definition, solution design, coding, testing, and maintenance, while also discussing different programming languages and their characteristics. The module emphasizes the importance of documentation and debugging in programming to ensure effective and efficient software development.

Uploaded by

rhysse52
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Republic of the Philippines

POLYTECHNIC COLLEGE OF BOTOLAN


(Formerly Botolan Community College)
Botolan, Zambales
E-mail: [email protected]
Website: www.pcb.edu.ph
Contact Number: 0968-307-5040

INSTITUTE OF COMPUTING STUDIES


STUDENT LEARNING MODULE (SLM)

COURSE CC111- COMPUTER PROGRAMMING 1


SEMESTER & YEAR 1st Sem 2024-2025
YEAR LEVEL 1
MODULE No. PR-DAY-01 to 02
LESSON Programming Concepts
MODULE MODEL
NO. OF PAGES 9

INSTRUCTOR Kristel Joy D. Salinas


Royssan L. Salinas
ID 23-011
21-012
EMAIL [email protected]
[email protected]
DATE SUBMITTED September 30, 2024

NOTE
Do not write anything on this module. There are answer sheets provided, use separate paper if
necessary.

1st Semester A.Y. 2024-2025 PR-DAYS-01-02 CC111 – Programming Concepts


Lesson 1
UNDERSTANDING COMPUTER CONCEPTS

Intended Learning Outcomes


At the end of this module, the students should be able to:
1. Understand Fundamental Programming

Programming Concepts

Every computer program has to be well-planned and executed correctly. Instructions


must be ordered in a logical sequence that can easily be understood by the computer. The
problem must be analyzed to such a level of detail that all logical conditions that may be
encountered during the process are taken into consideration. As we all know computers are
just a tool, it does not have its own mind. It is very dependent to the programmer who gives
instruction to it. We must make sure we analyze the problem very well before we start writing
some codes using programming languages such as Java.

There are six stages in developing a computer program.


1. Defining the problem
2. Designing a solution to the problem
3. Writing the program
4. Compiling, debugging and testing the program
5. Documenting the program
6. Maintaining the program

Defining the Problem


The first step in defining a problem begins with recognizing the need for information.
As we all know information is very important primarily because such information can help us
in making a good decision. This information may be requested for a solution to a particular
problem. The problem is thoroughly analyzed in order to determine what is required for its
solution.
To better understand and analyze the problem we must conduct a study of the nature
of the problem and we must able to identify the necessary outputs required in the program. In
conducting a study or investigation of the problem we must talk to the end-user of the
proposed program we are trying to develop since he understands the problem prior to writing
the necessary code for the program itself.
The programmer must determine what data are needed, what form they are to be in,
what information should the program generate, and how the data are to be manipulated to
produce this result.

Designing a Solution
When the problem is defined properly, we can start designing the solution to the
problem. In designing the solution, we must be able to breakdown the problem into several
steps so that it is easier for us to solve the problem in smaller pieces. This method is called
divide and conquer principle. This sequence of steps for the solution to the problem is
called an Algorithm.

Algorithm
It refers to well-defined procedures or instructions to solve a problem.
Flowcharting
One way a programmer can illustrate the sequence of steps in an algorithm is
with a flowchart. A flowchart is a graphical representation of the sequence of
operations where a computer is to perform. Flowcharting uses easily recognizable
symbols to represent the type of processing performed in a program.

Pseudocode
A pseudocode is a version of the instructions describing each step, that the
computer must follow. It is written in an abbreviated form of spoken language and
there lies somewhere commands written in ordinary English and those in a computer
language.

Writing the Program


After the programmer has defined the problem and designed a solution, the next step
is to write the program in a specific programming language. Although the definition and
solution of the problem are independent of the programming language, the proposed solution
to the problem may limit the choices of languages that can be used.

Program
1. A program is a list of instructions written in a programming language that a
computer can execute so that the machine acts in a predetermined way.
2. Program is synonymous with software. A program is also a sequence of instructions
that can be executed by a computer. The term may also refer to the original source
code or to an executable (machine language) version. The word program also implies
a degree of completeness, that is, a source code program compressing all statements
and files necessary for complete interpretation and compilation, and an executable
program that can be loaded into a given environment and executed independently
from other programs.
Despite the fact that programming languages differ in commands they use
high-level programming languages must have certain types of programming
statements in common. These are comments, declarations, input/output statements,
computations, transfer of control, and comparison.
Comments are statements that have no effect on the program. They are
simply used to make the program easier to understand. They are inserted at the key
points in the program and serve as an internal documentation of the program.
The programmer uses declarations to define items used in the program. Examples
include definitions of files, records, initial values, reusable functions and the like.
Input/output statements transfer data to and from the primary storage for use
by the program, as well as to and from other I/O devices like the monitor and the
keyboard. Commands such as READ and PRINT are examples of these types of
statements.
Computational instructions perform arithmetic operations such as addition,
subtraction, multiplication, division and exponentiation. Different programming
languages vary in the way they invoke the computer's arithmetic capabilities.
Another type of instruction allows the sequence of execution to be altered by
transferring control. A conditional transfer of control alters the sequence only when a
certain condition met. An unconditional transfer of control always changes the
sequence of execution.
Comparisons allow two items to be compared. Based on the result of the
comparison, input/output, computation, or transfer of control could occur.
As the program is being coded, the programmer should be aware that although
generating the correct output is the primary goal of the program, it is not the only
requirement of a good program. The programmer should try to incorporate the
following qualities into any program:
1. Programs should be easy to read and understand. Data names should be
descriptive. Statements should be placed in a format that is easy to read and follow.
Placing enough comments can help in making the program easier to understand.
2. Programs should be efficient. Programs should execute in as little time as
possible.
3. Programs should be reliable. Programs should consistently produce the correct
output. All formulas and computations, as well as all logic test and transfer control,
must be accurate.
4. Programs must be robust. Programs should work under all conditions. Reliability
alone is no guarantee for a successful program. Internal logic may be correct but
incorrect data item could produce an incorrect output. For example, how would a
program react if a person's age is between 16, 29 or -21? Or instead of accepting
numerical values such as 1, 10, 45, the person gives letter A?
5. Programs should be maintainable. They should be easy to update and modify.
Programs should be written in independent modules so that a change in one module
does not mean change of other modules.

Compiling, Debugging and Testing the Program


The instructions written in a programming language such as Java must be translated into
machine language before they can be executed. A compiler is a special program for each
programming language that is loaded into the computer when that language is used. It
translates each line of code into machine instruction that can easily be understood by the
computer.

Compiler
1. A computer program (or set of programs) that transforms source code written in a
programming language (the source language) into another computer language (the
target language, often having a binary form known as object code).
2. Refers to any program that transforms one set of symbols into another by following
a set of syntactic and semantic rules. In the most common sense, a compiler is a
program that translates all the source codes of a program written in a high-level
language into object codes prior to the execution of the program.

Debugging
1. In computers, debugging is the process of locating and fixing or bypassing bugs
(errors) in computer program code or the engineering of a hardware device. To debug
a program or to fix the hardware is to start with a problem, isolate the source of the
problem, and then fix it.
2. It is the process of correcting programming errors.

Testing
1. A method of assessing the functionality of a software program.
2. The process of checking if a program actually performs its functions as planned.

Documentation of the Program


Documentation consists of written descriptions and explanations of programs and
other materials associated with an organization's data processing system. Documentation of
a system and program designs are one of the most important requirements for success in
data processing application. Proper program documentation serves as a guide for
programmers and system analysts who must modify or update the existing programs and
system procedures.

The process of documentation is an ongoing process in any system being developed


and implemented. It begins with the initial request for information. The individual making the
request should be identified. So should those responsible for designing the system and
required programs.
During the problem definition state, the problem should be described clearly in a short
and narrative statement. The objectives of the program should be included with the problem
statement. Several other descriptions are needed.
1. A complete description of the contents and formats of all data inputs, outputs and
files to be used.
2. A statement of hardware requirements for running the program, as well as
estimated processing time and storage requirements.
3. A statement of software requirements, such as utility programs and library
programs
In the planning phase, the most important documentation produced is the flowchart
and pseudocode. Descriptive comments may be included in each processing step. The test
data used to test the program should also be included.

Maintenance
During the implementation of the system, there are some changes in the program that
will occur depending on the nature of the system that is being developed. Maintenance is
one of the most important aspects in developing a computer program in a sense that is there
are errors or bugs that are spotted by the user it should be fixed as soon as possible in order
to avoid big problems along the way of using the system. Let say, for example, the user has
discovered that every time a new record is being added in the database the record is not
being saved correctly having this problem is very critical in any business organization. This
problem should be corrected right away from the programmer, so that it will not hamper the
day-to-day operation of the company.

Bugs refers to errors in a computer program.

Types of Programming Errors


1. Syntax errors - Errors due to the fact that the syntax of the language is not
respected.
2. Semantic errors - Errors due to an improper use of program statements.
3. Logical errors - Errors that occur when the specification is not respected.
4. Compile time errors - Syntax errors and static semantic errors indicated by the
compiler.
5. Runtime errors - Dynamic semantic errors and logical errors that cannot be
detected by the compiler (debugging).

Programming Language
1. A programming language is an artificial language designed to communicate
instructions to a machine, particularly a computer
2. Programming languages can be used to create programs that control the behavior
of a machine and/or to express algorithms precisely.
3. Software used to create another software

Generations of Programming Languages


1. First Generation: Machine Language
2. Second Generation: Assembly Language
3. Third Generation: High-Level Language
4. Fourth Generation: Object-Oriented Programming
5. Fifth Generation: Logic Programming
TYPES OF PROGRAMMING LANGUAGES

1. Machine Language
It is the only language that the computer understands. It consists only of binary
numbers 0 and 1. The use of binary numbers as basis of machine language was proposed
by Dr. John Von Neumann. Each different type of CPU (Central Processing Unit) has its
own unique machine language. Programs written in machine language is very fast in terms of
program execution and uses only minimal amount of computer resources such as memory,
hard drive and CPU but it is not easy to write, debug and test programs written in machine
language on the part of the programmer. Machine language is widely used in 1930's up to
early 1950's primarily because of the small storage capacity and CPU speed of computer
during that time.

Advantage of Machine Language:


The only advantage of machine language is it runs very fast because no translation program
is required for the CPU.

Disadvantages of Machine Language:


1. It is very difficult to program in machine language. The programmer has to know details of
the computer hardware to write the program.
2. The programmer has to remember a lot of codes to write a program which usually results
in program errors.
3. It is difficult to debug the program.
4. It is very difficult to maintain and modify the program.
5. It is designed to work in a particular computer hardware architecture.

Example of Machine Language

ba 0c 01
b4 09
cd 21
b8 00 4c cd 21
48 65 6c 6c 6f 2c
20 57 6f 72 6c 64
21 0d 0a 24

2. Low Level Language


Low-level language is also known as assembly language. This is a type of low-level
programming language in which each program statement corresponds to an instruction that
the microprocessor can carry out. Assembly languages are thus specific to a given
microprocessor or CPU (Central Processing Unit) of the computer. After writing an
assembly language program, the programmer must use the assembler specific to the
processor to translate the assembly language into a corresponding machine code that
computers understand. An assembly language provides precise control of the computer, but
assembly language programs written for one type of computer must be rewritten to operate
on other types.
An assembly language might be used instead of a high-level language for any of these three
major reasons: speed, control, and preference. Programs written in an assembly language
usually run faster than those generated by a compiler. The use of assembly language allows
a programmer to interact directly with the hardware, including the processor, memory
display, and input/out ports.

Advantages of Low-Level Languages


1. It consists of binary digits and some symbols.
2. Very fast program execution
3. It depends on the machine.
4. Machine language directly executes on a computer.
5. No need of language translator for machine language
6. Program written in low level language is called object code.

Disadvantages of Low-Level Languages


1. It is not easy to understand.
2. It is difficult to modify.
3. Program written in low level language can run only on specific microprocessor or CPU.

Example of Assembly Language

.model small
.stack 100h

.data
message db 13,10, "Hello World!$"

.code
main proc near
lea dx, message
mov ah, 09h
int 21h

mov ah, 4ch


int 21h
main endp

3. High-Level Programming Language


High level programming languages enable the programmer to write programs that are
more or less independent of a particular type of computer. Such languages are considered
high level because they are closer to human language than the machine languages the
computer truly understands. The main advantage of a high-level language over, low-level
language is that they are easier to understand, modify and debug. They allow the
programmers to focus on solving the problem rather than knowing how to program a
computer.
Ultimately, programs written in a high level language must be translated into machine
language the language that computers understand. A good example of high level language
are COBOL, RPG, FORTRAN, Modula-2, LOGO, C, CH, Java, C#, JavaScript, BASIC and
Pascal. Since their development in the 1950's, many other languages have been developed
today. These include Visual Basic, Visual Foxpro, Ruby, Perl, Python, Lisp, PHP, ASP.NET,
C#, Objective C, Prolog and Java. Most programming languages were created to serve
specific purposes such teaching basic computer programming at schools, creating database
applications for business use, weather forecasting system, airport reservation system,
creating graphic images and animations, creating computer games, creating video
presentations, communication tools such as email, chat, text message, video conferencing,
device drivers for interface different computer hardware such as printers, scanners, digital
cameras and controlling input and output devices in the computer system. However,
programmers found that languages could develop for one purpose with few modifications
serving equally well in writing other programs.
The question of what programming language to use depends on the type of problem you
want to solve. Every language has its advantages and disadvantages. For example Pascal is
very good to use a tool in teaching fundamentals in computer programming in schools, but it
is not good in creating web applications. Java is a very good language to use in writing
secure, robust and web ready applications. It is also a great language to learn object-
oriented programming that is very helpful in creating large software applications.

Advantages and Disadvantages of High-Level Languages:


1. It is close to a human being.
2. It is easy to understand.
3. It consists of English language like structure.
4. It does not depend upon the machine.
5. It is easy to modify.
6. The programs written in high level languages are called source code.

Here are some disadvantages of high-level languages:


1. It needs language translator to translate program into machine language.
2. It is very slow in terms of program execution compared to machine or assembly language.
3. It needs big amount of system resources such as memory, disk space and CPU speed to
run the program properly.
4. It does not execute directly on the computer.

Example of High Level Language

/* hello.java */
/* Author: Mr. Jake R. Pomperada, MAED-IT*/
/* Date: August 8, 2015*/
public class HelloWorld {
public static void main(String[| args) {
System.out.println("Hello, World");
}
}

Interpreters and Compilers


Regardless of what type of language you are using, eventually you will convert your
program into a machine language so that the computer can understand and execute your
program. When we write our programs in a high-level language the computer does not
understand the language because it is only operated with bit or one's and zero's. There is a
need for translation process that will convert the programs written in high-level language into
machine language.
There are two ways of doing this, either compile the program or interpret the
program. The process of compiling and interpreting a program can be accomplished by
using other programs called compilers and interpreters, these programs translate the
program written in high-level language into machine language.

Compiler
A compiler is a program that translates a program written in a high-level language
(source code) and translates into machine language (object code). The compiler derives its
name from the way it works. The first practical compiler was written by Commodore Grace
Murray Hopper of United States Navy in 1952; she named it A compiler, It analyzes the
entire piece of source code and then reorganizes the instructions and then translates into
machine code.
Every high-level programming language (except strictly interpretive languages) comes
with a compiler. In the effect, the compiler is the language because it defines which
instructions are acceptable and which are not.

Source Code is any series of statements written in some high-level computer


programming language.
The term is typically used in the context of a particular piece of computer software. A
computer program's source code is the collection of files that can be converted from human-
readable form to an equivalent computer-executable form in machine language. The source
code is either converted into an executable file by a compiler for a particular computer
architecture, or executed on the fly from the human readable form with the aid of an
interpreter.
Object Code, also known as object file, is an intermediate representation of code
generated by a compiler after it processes a source code file. Object files contain compact,
pre-parsed code, often called binaries that can be linked with other object files to generate a
final executable or code library. An object file is mostly machine code that can be directly
executed by a computer's CPU. An object file contains not only the object code, but also
relocation information that the linker uses to assemble multiple object files into an executable
or library, program symbols (names of variables and functions), and debugging information.
Programming languages that use compilers are Java, C, C+, BASIC, Fortran, COBOL, Go,
Felix, D, Oberon, Pascal, Python, Eiffel, Smalltalk, Haskell, Batch and CLI.

This is How Compilers Work

Interpreter
The most common way to translate a high-level language to machine language is to
compile the program; the other method is to pass the program through an interpreter. The
interpreter translates and executes the program line by line. An interpreter translates into an
intermediate form, which it then executes. In contrast, a compiler translates high-level
instructions or commands directly into machine language. The first interpreter was written by
Steve Russell on an IBM 704 computers in 1958. The first high-level language that uses an
interpreter to translate its code into machine code is LISP or List Processing language
written and developed by John McCarthy in 1958.
The advantage of an interpreter, however, is that it does not need to go through the
compilation stage during which machine instructions are generated. This compilation process
can be time consuming if the program is long. The interpreter, on the other hand, can
immediately execute high level programs.
Programming languages that use interpreters are LISP, BASIC, Java, Pascal,Ruby
and Python.

This is How Interpreter Works


Comparison between Compiler and Interpreter
COMPILER INTERPRETER
Scans the entire program and translates it Translates program one statement at a
as a whole into machine code. time
It takes large amount of time to analyze It takes less amount of time to analyze the
the source code but the overall execution source code but the overall execution time
time is comparatively faster. is slower.
Generates intermediate object code which No intermediate object code is generated,
further requires linking, hence requires hence it is memory efficient.
more memory.
It generates the error message only after Continues translating the program until,
scanning the whole program. Hence, the first error is met, in which case, it
debugging is comparatively hard. stops. Hence debugging is easy.
Programming language like C, C+ uses Programming languages like Python and
compilers. Ruby use interpreters.

You might also like