CPE112 Programming Concept

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

CITY GOVERNMENT OF SAN PABLO

PAMANTASAN NG LUNGSOD NG SAN PABLO


CHED Recognized Local College
TESDA Recognized Programs
ALCU Commission on Accreditation – Level 1 Re-Accredited
Member, Association of Local Colleges and Universities
Patriotism • Leadership • Service • Professionalism
Member, Local Colleges and Universities Athletic Association, Inc.

Module 1
(Programming Concept)

Programming Logic and


Design
CPE112

Prepared By:

Manalo, Adrian M.

Instructor

Address: Brgy. San Jose, City of San Pablo, Laguna Cel. no. (0929) 356 7646 E – mail (Administrative Office), dlspofficial97@gmail.com
CITY GOVERNMENT OF SAN PABLO
PAMANTASAN NG LUNGSOD NG SAN PABLO
CHED Recognized Local College
TESDA Recognized Programs
ALCU Commission on Accreditation – Level 1 Re-Accredited
Member, Association of Local Colleges and Universities
Patriotism • Leadership • Service • Professionalism
Member, Local Colleges and Universities Athletic Association, Inc.

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 C and C++.

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

Address: Brgy. San Jose, City of San Pablo, Laguna Cel. no. (0929) 356 7646 E – mail (Administrative Office), dlspofficial97@gmail.com
CITY GOVERNMENT OF SAN PABLO
PAMANTASAN NG LUNGSOD NG SAN PABLO
CHED Recognized Local College
TESDA Recognized Programs
ALCU Commission on Accreditation – Level 1 Re-Accredited
Member, Association of Local Colleges and Universities
Patriotism • Leadership • Service • Professionalism
Member, Local Colleges and Universities Athletic Association, Inc.

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.

Address: Brgy. San Jose, City of San Pablo, Laguna Cel. no. (0929) 356 7646 E – mail (Administrative Office), dlspofficial97@gmail.com
CITY GOVERNMENT OF SAN PABLO
PAMANTASAN NG LUNGSOD NG SAN PABLO
CHED Recognized Local College
TESDA Recognized Programs
ALCU Commission on Accreditation – Level 1 Re-Accredited
Member, Association of Local Colleges and Universities
Patriotism • Leadership • Service • Professionalism
Member, Local Colleges and Universities Athletic Association, Inc.

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

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 C or C++ 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

Address: Brgy. San Jose, City of San Pablo, Laguna Cel. no. (0929) 356 7646 E – mail (Administrative Office), dlspofficial97@gmail.com
CITY GOVERNMENT OF SAN PABLO
PAMANTASAN NG LUNGSOD NG SAN PABLO
CHED Recognized Local College
TESDA Recognized Programs
ALCU Commission on Accreditation – Level 1 Re-Accredited
Member, Association of Local Colleges and Universities
Patriotism • Leadership • Service • Professionalism
Member, Local Colleges and Universities Athletic Association, Inc.

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.

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

Address: Brgy. San Jose, City of San Pablo, Laguna Cel. no. (0929) 356 7646 E – mail (Administrative Office), dlspofficial97@gmail.com
CITY GOVERNMENT OF SAN PABLO
PAMANTASAN NG LUNGSOD NG SAN PABLO
CHED Recognized Local College
TESDA Recognized Programs
ALCU Commission on Accreditation – Level 1 Re-Accredited
Member, Association of Local Colleges and Universities
Patriotism • Leadership • Service • Professionalism
Member, Local Colleges and Universities Athletic Association, Inc.

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

1. First Generation (1GL)

1. Machine Language

2. Uses binary codes that consist of string of only zeroes and ones.

3. These are languages that a computer can understand and execute directly.

4. Machine dependent

5. Low-level Language

2. Second Generation (2GL)

1. Assembly Language

2. Instead of zeroes and ones, it uses mnemonics or very short words for commands.

3. Program written in assembly language must be converted by an ASSEMBLER.

4. Low level language TASM, MASM

3. Third Generation (3GL)

1. High-Level Language

2. Can write programs that are more or less independent of a particular type of computer

3. It is considered high-level because they are closer to human languages and they are easier to read,
write, and maintain.

4. Uses a COMPILER to translate the source code into machine readable code

5. FORTRAN, BASIC, COBOL, Pascal, C, C++, Algol, Ada

Address: Brgy. San Jose, City of San Pablo, Laguna Cel. no. (0929) 356 7646 E – mail (Administrative Office), dlspofficial97@gmail.com
CITY GOVERNMENT OF SAN PABLO
PAMANTASAN NG LUNGSOD NG SAN PABLO
CHED Recognized Local College
TESDA Recognized Programs
ALCU Commission on Accreditation – Level 1 Re-Accredited
Member, Association of Local Colleges and Universities
Patriotism • Leadership • Service • Professionalism
Member, Local Colleges and Universities Athletic Association, Inc.

4. Fourth Generation (4GL)

1. Object Oriented Programming Language

2. Organize coding around objects

3. Event driven - event triggers the outcome of the program

4. JAVA, C++, C#, Visual Basic, VB.NET

5. Fifth Generation (5GL)

1. Logic Programming

2. Artificial Language

3. Operates on the concept of solving problems based on constraints or rules that have been declared
in the program

4. The focus is on making the computer program solve the problem for you.

5. Uses knowledge bases and expert system

6. PROLOG, Mercury, LISP

7. PROGRAMMING PARADIGMS

8. Imperative

9. Functional

10. Logic

11. Object-oriented

12. Concurrent and Distributed

TYPES OF PROGRAMMING LANGUAGES

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 Dr. John Von Neumann. Each
different type of CPU (Central Processing Unit) has its own unique machine language. Programs
writer 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 is not easy to write, debug and test

Address: Brgy. San Jose, City of San Pablo, Laguna Cel. no. (0929) 356 7646 E – mail (Administrative Office), dlspofficial97@gmail.com
CITY GOVERNMENT OF SAN PABLO
PAMANTASAN NG LUNGSOD NG SAN PABLO
CHED Recognized Local College
TESDA Recognized Programs
ALCU Commission on Accreditation – Level 1 Re-Accredited
Member, Association of Local Colleges and Universities
Patriotism • Leadership • Service • Professionalism
Member, Local Colleges and Universities Athletic Association, Inc.

programs written in machine language 0the part of the programmer. Machine language is widely used
in 1930's up to earl1950's primarily because of the small storage capacity and CPU speed of computer
during that time.

Low Level Language

Low-level language is also known as assembly language. This is a type or 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.

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 is COBOL, RPG, FORTRAN, Modula-2, LOGO, C, Ct+, 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

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

Address: Brgy. San Jose, City of San Pablo, Laguna Cel. no. (0929) 356 7646 E – mail (Administrative Office), dlspofficial97@gmail.com
CITY GOVERNMENT OF SAN PABLO
PAMANTASAN NG LUNGSOD NG SAN PABLO
CHED Recognized Local College
TESDA Recognized Programs
ALCU Commission on Accreditation – Level 1 Re-Accredited
Member, Association of Local Colleges and Universities
Patriotism • Leadership • Service • Professionalism
Member, Local Colleges and Universities Athletic Association, Inc.

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.

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 re- organizes
the instructions and then translates into machine code.

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.

Address: Brgy. San Jose, City of San Pablo, Laguna Cel. no. (0929) 356 7646 E – mail (Administrative Office), dlspofficial97@gmail.com

You might also like