Beruflich Dokumente
Kultur Dokumente
Introduction to Programming
1.1 What is Programming?
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.
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:
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
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
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.
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.
1. Desk-checking
2. Translating
3. Debugging
Desk-checking
Translating
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
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.
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.
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.
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.
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.
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:
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.
http://homepage.cs.uri.edu/faculty/wolfe/book/Readings/Reading13.htm