Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 37

DCIT 22 –

COMPUTER
PROGRAMMING 1
Introduction to
Computer
Programming
Introduction to Computer
Programming

 Computer programming is the act of


writing computer programs, which are a sequence of
instructions written using a Computer Programming
Language to perform a specified task by the computer.

 Computer Programming is fun and easy


to learn provided you adopt a proper approach. This
tutorial attempts to cover the basics of computer
programming using a simple and practical approach for
the benefit of novice learners.
Introduction to Computer
Programming

 Before getting into computer


programming, let us first understand computer
programs and what they do.

 A computer program is a sequence of


instructions written using a Computer Programming
Language to perform a specified task by the
computer.

 The two important terms that we have


used in the above definition are −
 Sequence of instructions
 Computer Programming Language
To understand these terms, consider a
situation when someone asks you about how
Introduction to to go to a nearby KFC. What exactly do you
do to tell him the way to go to KFC?
Computer
Programming You will use Human Language to tell
the way to go to KFC, something as
follows −

First go straight, after half kilometer, take


left from the red light and then drive
around one kilometer and you will find
KFC at the right.
 Here, you have used English
Language to give several steps to be taken to
reach KFC. If they are followed in the following
sequence, then you will reach KFC –

Introduction to 1. Go straight


Computer 2. Drive half kilometer
Programming 3. Take left
4. Drive around one kilometer
5. Search for KFC at your right side
 Now, try to map the situation with a
computer program. The above sequence of instructions
is actually a Human Program written in English
Language, which instructs on how to reach KFC from a
given starting point. This same sequence could have
been given in Spanish, Hindi, Arabic, or any other
human language, provided the person seeking direction
Introduction to knows any of these languages.

Computer  Now, let's go back and try to understand a

Programming computer program, which is a sequence of instructions


written in a Computer Language to perform a specified
task by the computer. Following is a simple program
written in Java programming Language –

System.out.println(“Hello, World!”);
 The above computer program instructs the
computer to print "Hello, World!" on the computer screen.
 A computer program is also called a computer
software, which can range from two lines to
millions of lines of instructions.

Introduction to  Computer program instructions are also called


program source code and computer
programming is also called program coding.
Computer  A computer without a computer program is just a
dump box; it is programs that make computers
Programming 
active.
As we have developed so many languages to
communicate among ourselves, computer scientists have
developed several computer-programming languages to provide
instructions to the computer (i.e., to write computer programs).
We will see several computer programming languages in the
subsequent chapters.
 If you understood what a computer
program is, then we will say: the act of writing
computer programs is called computer programming.

 As we mentioned earlier, there are hundreds


of programming languages, which can be used to write
computer programs and following are a few of them −
Introduction to
Computer  Java

Programming 
C
C++
 Python
 PHP
 Perl
 Ruby
Uses of Computer
Programs
Today computer programs are being used in almost every field,
household, agriculture, medical, entertainment, defense,
communication, etc. Listed below are a few applications of
computer programs −

 MS Word, MS Excel, Adobe Photoshop, Internet Explorer,


Chrome, etc., are examples of computer programs.
 Computer programs are being used to develop graphics and
special effects in movie making.
 Computer programs are being used to perform Ultrasounds,
X-Rays, and other medical examinations.
 Computer programs are being used in our mobile phones
for SMS, Chat, and voice communication.
Computer
Programmer
Someone who can write computer programs or
in other words, someone who can do computer programming
is called a Computer Programmer.
Based on computer programming language
expertise, we can name a computer programmers as follows −
 C Programmer
 C++ Programmer
 Java Programmer
 Python Programmer
 PHP Programmer
 Perl Programmer
 Ruby Programmer
The concepts discussed on
this page are essential knowledge to
anyone who wants to become skilled
Computer in computer programming. While
programming some are not universal, these concepts
are present in the majority of computer
concepts programming languages and/or are a
fundamental part of the programming
process.
1. Algorithm
A set of steps for carrying out a
specific task. Algorithms are used extensively
in computer programming to arrive at a
Computer solution for a problem. The process of
creating an algorithm involves documenting
programming all the necessary steps needed to arrive at the
solution and how to perform each step. A real
concepts world example of an algorithm would be a
recipe. The instructions of a typical recipe
(add ingredients, mix, stir, etc.) are an
algorithm.
2. Source Code
The actual text used to write the
instructions for a computer program. This
text is then translated into something
meaningful the computer can understand.

Computer
3. Compiler
programming
A software tool that translates
concepts source code into data that the computer can
understand. Specifically, a compiler is used
to turn source code into object code. The
object code is then passed through a program
called a linker which turns it into an
executable program.
4. Data type
the classification of pieces of
information in a program. The amount
of different data types varies between
Computer languages. Typically, there are data
programming types for integers (whole numbers),
floating-point numbers (numbers with a
concepts decimal part), and single characters. To
distinguish between different data
types, a computer uses special internal
codes.
5. Variable
A container which represents a
value in a program. Variables can store
different types of data including numeric
values, single characters, and text strings.
Computer The value of a variable can change all
throughout a program
programming
concepts 6. Constant
The same thing as a variable with
one major difference - the value of a
constant does not change, while the value of
a variable can change all throughout a
program.
7. Conditional
A set of code that will execute
only if a certain condition is true.
Computer Conditionals are used to test expressions
and perform certain operations accordingly.
programming For example, you could test a number input
by the user and if it is too high print the
concepts message "The number entered is to high"
and the program exits. Thanks to
conditionals, a program can work
differently every time it runs.
8. Array
A special type of variable used in
many programming and web languages
including PHP, Javascript, and Java that
contains a list of related values. For example, a
colors array would contain a list of colors.
Computer
programming 9. Loop
A segment of code that executes
concepts repeatedly based on a certain condition. Loops
are used to perform tasks repeatedly a certain
amount of times. For example, if you needed to
print the numbers 1 to 10. You can use a loop for
this task instead of manually printing all the
numbers.
10. Function
A set of code used to carry out
specific tasks. A function can take
parameters which will effect its output as
Computer well as return values. Functions prevent
unnecessary redundancy because you can
programming use them as much as needed instead of
retyping some code over and over. For
concepts example, if you need to multiply two
numbers, instead of doing the calculation
manually every time, you can supply the
data to a function through some parameters
which will do it for you.
11. Class
A template for a real world
object to be used in a program. For
example, a programmer can create a
Computer car class which represents a car. This
programming class can contain the properties of a
car (color, model, year, etc.) and
concepts functions that specify what the car
does (drive, reverse, stop, etc.).
Classes are used in object-oriented
programming.
There are five generation of Programming languages.
They are:

 First Generation Languages :


These are low-level languages like machine language.
Generation of
Programming  Second Generation Languages :
These are low-level assembly languages used in kernels
Languages and hardware drives.

 Third Generation Languages :


These are high-level languages like C, C++, Java, Visual
Basic and JavaScript.
Generation of Programming Languages

 Fourth Generation Languages :


These are languages that consist of statements that are similar to statements in the
human language. These are used mainly in database programming and scripting. Example of these
languages include Perl, Python, Ruby, SQL, MatLab(Matrix Laboratory).

 Fifth Generation Languages :


These are the programming languages that have visual tools to develop a program.
Examples of fifth generation language include Mercury, OPS5, and Prolog.
The first two generations are called low level languages. The next three generations are
called high level languages.
Generation of
Programming
Languages
The Programming
Process
Developing a program involves steps
similar to any problem-solving task. There are five main
ingredients in the programming process:

 Defining the problem


 Planning the solution
 Coding the program
 Testing the program
 Documenting the program

Let us discuss each of these in turn.


The Programming Process
Defining the Problem:
Suppose that, as a programmer, you are contacted because your
services are needed. You meet with users from the client organization to
analyze the problem, or you meet with a systems analyst who outlines the
project. Specifically, the task of defining the problem consists of identifying
what it is you know (input-given data), and what it is you want to obtain
(output-the result). Eventually, you produce a written agreement that, among
other things, specifies the kind of input, processing, and output required. This
is not a simple process.
The Programming Process

Planning the Solution:


Two common ways of planning the solution to a problem are to draw a
flowchart and to write pseudocode, or possibly both. Essentially, a flowchart is a
pictorial representation of a step-by-step solution to a problem. It consists of arrows
representing the direction the program takes and boxes and other symbols
representing actions. It is a map of what your program is going to do and how it is
going to do it. The American National Standards Institute (ANSI) has developed a
standard set of flowchart symbols. Figure 1 shows the symbols and how they might
be used in a simple flowchart of a common everyday act-preparing a letter for
mailing.
The Programming Process
Pseudocode is an English-like nonstandard language that lets you
state your solution with more precision than you can in plain English but
with less precision than is required when using a formal programming
language. Pseudocode permits you to focus on the program logic without
having to be concerned just yet about the precise syntax of a particular
programming language. However, pseudocode is not executable on the
computer. We will illustrate these later in this chapter, when we focus on
language examples.
The Programming Process

Coding the Program:


As the programmer, your next step is to code the program-that is, to express
your solution in a programming language. You will translate the logic from the
flowchart or pseudocode-or some other tool-to a programming language. As we have
already noted, a programming language is a set of rules that provides a way of
instructing the computer what operations to perform. There are many programming
languages: BASIC, COBOL, Pascal, FORTRAN, and C are some examples. You may
find yourself working with one or more of these. We will discuss the different types of
languages in detail later in this chapter.
The Programming
Process
Although programming languages operate
grammatically, somewhat like the English language,
they are much more precise. To get your program to
work, you have to follow exactly the rules-the syntax-
of the language you are using. Of course, using the
language correctly is no guarantee that your program
will work, any more than speaking grammatically
correct English means you know what you are talking
about. The point is that correct use of the language is
the required first step. Then your coded program must
be keyed, probably using a terminal or personal
computer, in a form the computer can understand.
The Programming
Process

One more note here: Programmers


usually use a text editor, which is
somewhat like a word processing
program, to create a file that contains
the program. However, as a beginner,
you will probably want to write your
program code on paper first.
Testing the Program:
Some experts insist that a well-designed
program can be written correctly the first time. In fact,
they assert that there are mathematical ways to prove that
a program is correct. However, the imperfections of the
The world are still with us, so most programmers get used to
Programming the idea that their newly written programs probably have a
few errors. This is a bit discouraging at first, since
Process programmers tend to be precise, careful, detail-oriented
people who take pride in their work. Still, there are many
opportunities to introduce mistakes into programs, and
you, just as those who have gone before you, will
probably find several of them.
The Programming Process

Eventually, after coding the program, you must prepare to test it on the computer.
This step involves these phases:

A. Desk-checking. This phase, similar to proofreading, is sometimes avoided by the


programmer who is looking for a shortcut and is eager to run the program on the computer
once it is written. However, with careful desk-checking you may discover several errors and
possibly save yourself time in the long run. In desk-checking you simply sit down and
mentally trace, or check, the logic of the program to attempt to ensure that it is error-free
and workable. Many organizations take this phase a step further with a walkthrough, a
process in which a group of programmers-your peers-review your program and offer
suggestions in a collegial way.
The Programming Process

B. Translating. A translator is a program that (1) checks the syntax of your program
to make sure the programming language was used correctly, giving you all the
syntax-error messages, called diagnostics, and (2) then translates your program into
a form the computer can understand. A by-product of the process is that the
translator tells you if you have improperly used the programming language in some
way. These types of mistakes are called syntax errors. The translator produces
descriptive error messages.
The Programming Process

For instance, if in FORTRAN you mistakenly write N=2 *(I+J))-which has


two closing parentheses instead of one-you will get a message that says,
"UNMATCHED PARENTHESES." (Different translators may provide different
wording for error messages.) Programs are most commonly translated by a compiler.
A compiler translates your entire program at one time. The translation involves your
original program, called a source module, which is transformed by a compiler into an
object module. Prewritten programs from a system library may be added during the
link/load phase, which results in a load module. The load module can then be
executed by the computer.
The Programming Process

C. Debugging. A term used extensively in programming, debugging means


detecting, locating, and correcting bugs (mistakes), usually by running the
program. These bugs are logic errors, such as telling a computer to repeat
an operation but not telling it how to stop repeating. In this phase you run
the program using test data that you devise. You must plan the test data
carefully to make sure you test every part of the program.
The Programming Process

Documenting the Program:


Documenting is an ongoing, necessary process, although, as many programmers
are, you may be eager to pursue more exciting computer-centered activities. Documentation
is a written detailed description of the programming cycle and specific facts about the
program. Typical program documentation materials include the origin and nature of the
problem, a brief narrative description of the program, logic tools such as flowcharts and
pseudocode, data-record descriptions, program listings, and testing results. Comments in the
program itself are also considered an essential part of documentation. Many programmers
document as they code. In a broader sense, program documentation can be part of the
documentation for an entire system.
The Programming Process

The wise programmer continues to document the program throughout its


design, development, and testing. Documentation is needed to supplement human
memory and to help organize program planning. Also, documentation is critical to
communicate with others who have an interest in the program, especially other
programmers who may be part of a programming team. And, since turnover is
high in the computer industry, written documentation is needed so that those who
come after you can make any necessary modifications in the program or track
down any errors that you missed.
Thank you!

You might also like