Sie sind auf Seite 1von 9

1.

Introduction to Programming
1.1 What is Programming?

A problem is defined as any question, something involving doubt, uncertainty,


difficulty or a situation whose solution is not immediately obvious. A situation which is
a problem for one person may not be a problem for another person. Figure 1.1
graphically represents the concept of problem solving.

Figure 1.1 : Problem Solving

A Computer is a tool that can be used to solve problems by writing programs.


Writing a program without knowing the problem that we are trying to solve is like
swinging a knife without knowing what it is that we want to cut.

A program is a set of instructions that tells the computer how to do a task.


When a computer follows these instructions, we say it executes the program.

A programming language is a computer language that programmers use to


develop applications. An application is a set of instructions for a computer to execute.
A set of rules that provides a way of telling a computer what operations to perform is
called a Program.

Programming is the process of designing, developing, testing, debugging and


maintaining the source code of computer programs. It is used to create a set of
instructions that computers use to perform specific operations or to exhibit desired
behaviors. Source code can be written using programming language such as C++, Java,
Python, Smalltalk, C#, etc. The process of writing source code often requires expertise
in many different subjects, including knowledge of the specialized algorithms,
application domain and formal logic.

Within software engineering, programming (implementation) is considered as


a phase in the software development process.
1.1.1 The Programming Process

Developing a program involves different steps similar to any problem solving


task. There are five main steps in the programming process and are given below:

1. Defining the problem


2. Planning the solution
3. Coding the program
4. Testing the program
5. Documenting the program

Let us discuss each of these steps.

1. Defining the problem

As a programmer, you meet with end 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 you know (input-given data),
and what you want to obtain (output-the result). Eventually, you create a document
agreement that specifies the kind of input, processing, and output required to complete
the task.

2. Planning the solution

There are two ways that are commonly used to plan the solution to a problem. These are
to draw a flowchart and to write pseudo code, or both.

Pseudo code

Pseudo code is an English-like non-standard langauge that permits you to focus on the
program logic without having to be concerned about the precise syntax of a particular
programming language. However, pseudo code is not executable on the computer. It lets
you state your solution with more precision than plain English. However psuedo code has
lesser precision than is required when using a formal programming language. An example
is given below:

Example: Read number n and print the integers counting up to n.

Read n
Initialize the variable i to 1
while i 'less than or equal to n' do
Print i
Increment i
end while
Stop
In the above example, the program enters the while loop only if the condition ( i less
than or equal to n) is true. Two statements Print i and Increment i are executed for each
iteration. At the end of each iteration, the condition is evaluated again and the loop
continues as long as the condition is true.

Flowchart

It 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 the steps involved in a program. The American
National Standards Institute (ANSI) has come up with a standard set of flowchart
symbols. The following figure shows the flowchart symbols and how they might be used
in a simple flowchart of a everyday action preparing a letter for mailing.

Figure 1.2 : Flowchart

Please refer the links below to learn more about pseudo code and flow chart.
 http://ceng.anadolu.edu.tr/emrekacmaz/bil158/flowchart-pseudocode-
examples.pdf
 http://ozark.hendrix.edu/~burch/csbsju/cs/150/sched/pseudo.pdf
 http://www.cosc.canterbury.ac.nz/tim.bell/dt/Tutorial_Pseudocode.pdf
 http://users.csc.calpoly.edu/~jdalbey/SWE/pdl_std.html

3. Coding the program

As the programmer, your next step is to code the program to express the solution in a
programming language. You will translate the logic from the flowchart or pseudo code to
a programming language. As we have already discussed, 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 such as BASIC, COBOL, Pascal, FORTRAN, C , etc .

Programming languages are precise like the English language, To get your program to
work, you have to follow exactly the syntax (rules) of the language you are using.
However there is no guarantee that your program will work, because the syntax in
programming language is correct. The correctness of the language is the required first
step. Then the program must be keyed, probably using a personal computer, in a form
that the computer can understand.

4. Testing the program

Some experts insist that a well designed program can be written correctly the first time
and there are mathematical ways to prove that a program is correct. Most of the
programs may have a few bugs (errors) when executed the first time. This is a bit
discouraging at first, since programmers tend to be careful, precise and detail-oriented
people who take pride in their work. There are many ways in which mistakes or problems
may happen in programs. You will probably have made some of them. Eventually, after
coding, we must prepare to test the program on the computer.

This step involves three phases:

1. Desk-checking
2. Translating
3. Debugging

Let us discuss each of these phases.

Desk-checking

This is similar to proofreading. This phase is sometimes avoided by the


developer/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 we can discover
several errors and possibly save our time in the long run. In desk-checking you simply sit
down and mentally check or trace, the logic of the program in an attempt to ensure that
it is error-free and is in workable condition. Many organizations take this phase a step
further called as walk through, a process in which a group of programmers review the
program and make suggestions or comments in a collegial way.

Translating

A translator is a program that

I. checks the syntax of the program to make sure that the programming language was
used correctly, giving you all the syntax related error messages, called diagnostics,
and
II. then translates the program into a form which the computer can understand. A by-
product of the process is that the translator tells us if we have improperly used the
programming language. These types of mistakes are called as syntax errors. The
translator gives descriptive error messages.

Programs are most commonly translated using a compiler. A compiler translates the
entire program at one time. The translation involves your original program (Source file)
which is transformed by a compiler into an object module. Pre-written programs from a
system library may be added during the load/link phase, which results in a load module.
The load module can then be executed by the computer.

Debugging

Debugging is used extensively in programming. It means detecting, locating, and


correcting bugs (mistakes), by running the program. These bugs are called as logic errors,
which tells the computer to repeat an operation but not telling it how to stop repeating.
In this phase we run the program using the test data that we devise. We must plan the
test data carefully to make sure we test every part of the program.

5. Documenting the program

Documenting is an ongoing process. It 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 pseudo code and
flowcharts, program listings, data-record descriptions and testing results. Comments in
the program are also considered an essential part of documentation. Many programmers
document as they code.

A wise programmer continues to document the program throughout its design,


development and testing. Documentation is used 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 and may be part of a programming team.

1.2 Why programming is required?

We may already have used software, perhaps for spreadsheets or word processing, or to
solve problems. Perhaps now we are curious to learn how programmers write software.
A program is a set of step-by-step instructions that directs the computer to do the tasks
we want it to do and produce the results we want.

There are three good reasons for learning programming:

1. Programming helps us to understand computers. If we learn how to write simple


programs, we will gain more knowledge about how a computer works.
2. Writing a few simple programs increases our confidence level. We will find great
personal satisfaction in creating a set of instructions that solve a problem.
3. Learning programming lets us find out quickly whether we like programming and
whether we have the analytical turn of mind that programmers need. Even if we
decide that programming is not for us, understanding the process certainly will
increase our appreciation of what computers and programmers can do.

What Programmers Do?

The programmer prepares the set of instructions of a computer program and runs those
instructions on the computer,tests the program to see if it is working properly, and
makes corrections to the program. These activities are all done for the purpose of
helping a user to fill a need, such as paying employees, admitting students to college or
billing customers.

The programming activities can be done as a solo activity, but a programmer typically
interacts with a variety of people. For example, if a program is part of a system of several
programs, the programmer coordinates with others (other programmers) to make sure
that the programs fit together well. If you are a programmer, you might also have
coordination meetings with users, systems analysts, managers, and with peers who
evaluate your work just as you evaluate theirs.

1.2.1 Levels of Language

Programming languages can be "lower" or "higher," depending on how close they are to
the language the computer itself uses (0s and 1s = low) or to the language people use
(English like high). We will consider five levels of language. These are numbered 1
through 5 to correspond to generations. In terms of ease of use and capabilities, each
generation or level is an improvement over its predecessor.

The five generations of languages are:


1. Machine languages
2. Assembly languages
3. High-level languages
4. Very high-level languages
5. Natural languages

Let us look at each of these categories.

1. Machine languages

Humans do not like to deal with numbers alone: they prefer letters and words also.
machine language consists of numbers. Eeach type of computer has its own machine
language. This lowest level of language, represents data and program instructions as 1s
and 0s-binary digits corresponding to the on and off electrical states in the computer. In
the early days of computing, programmers used rudimentary systems for combining
numbers to represent instructions such as add or compare. These programs are not
convenient for people to read and use and the industry quickly moved to develop
assembly languages.

2. Assembly languages

Assembly languages are considered as very low level language. They are not as
convenient to use as the more recent languages. At the time they were developed,
however, they were considered as a great leap forward. To replace the 1s and 0s used in
machine language, assembly languages use mnemonic codes. Mnemonic codes are
abbreviations that are easy to remember: A for add, C for compare, MP for Multiply and
so on. Although these codes are not English words, they are better accepted than
numbers (0s and 1s)alone. Just like machine language, each type of computer has its own
assembly language.

The programmer who uses an assembly language requires a translator which is used to
convert the assembly language program into machine language. A translator is required
because machine language is the only language that the computer can actually execute.
The translator is an assembler program, which is also referred to as an assembler. It
takes the programs written in assembly language and converts them into machine
language. Programmers need not worry about the translating aspect, they only need to
write programs in assembly language.

Although assembly languages represent a step forward, they still have many
disadvantages. A key disadvantage is that assembly language is detailed to the extreme,
making assembly language programming repetitive, error prone and tedious.
3. High-Level Languages

The first widespread use of high-level languages in the early 1960's transformed
programming into something quite different from what it had been. Programs were
written in an English-like manner, thus making them more easy and convenient to use. A
programmer can accomplish more with less effort, and programs can now take care of
much more complex tasks.

These so-called third generation languages spurred a great increase in data processing
that characterized the 1960's and 1970's. During that period, the number of mainframes
in use increased from hundreds to tens of thousands.

A translator is used to translate the symbolic statements of a high level language into
computer executable machine language, this translator is usually called as a compiler.
There are many compilers for each language and one for each type of computer. For
example, it is necessary to have a COBOL compiler for each type of computer on which
COBOL programs are to be run. A program can be compiled to different machine
language versions on different machines, the source program itself, the COBOL version
can be essentially identical on each machine.

Some languages are used to serve a specific purpose, such as creating graphics or
controlling industrial robots. Many languages are extraordinarily flexible and are
considered to be general-purpose languages. In the past the majority of programming
applications were written in BASIC, COBOL or FORTRAN. All of them are general purpose
languages.

4. Very High-Level Languages

Very high-level languages are often known by their generation number, they are called
fourth-generation languages or 4GLs. Fourth-generation languages are beneficial
because:

I. They are result-oriented; they emphasize what instead of how.


II. They improve productivity because programs are easy to write and modify.
III. They can be used with minimum training by both programmers and non
programmers.
IV. They shield users from needing an awareness of program structure and hardware.

5. Natural Languages

The word "natural" has become most popular in computing circles. Fifth generation
languages are most often called natural languages because of their resemblance to the
"natural" spoken English language. Instead of being forced to key correct commands and
data names in correct order, a manager tells the computer what to do by keying in their
own words.
1.2.1.1 Choosing a Language

 In a work environment, the manager may decide that everyone in project will use
a certain language.
 We may need to use a certain language, particularly in a business environment,
based on the need to interface with other programs. If two programs are to work
together, it is easiest if they are written in the same language.
 We may choose a language based on its suitability or criteria. For example, COBOL
will be the best option for a business program that handles large files .
 If a program is to be run on different computers, it must be written in a language
that is portable and suitable on each type of computer, so that the program needs to
be written only once.
 We may be limited by the availability of languages. Not all languages are available
on all computers and in all installations.
 The language may be limited to the expertise of the programmer. The program
may have to be written in a language that available programmer knows.

Major Programming Languages are FORTRAN (a scientific language), COBOL (a business


language), BASIC (simple language used for education and business), Pascal (education),
Ada (military), and C (general purposed), C, C++, Java, and Javascript.

Please refer the link below to know more about programming.

 http://homepage.cs.uri.edu/faculty/wolfe/book/Readings/Reading13.htm

Das könnte Ihnen auch gefallen