What is a program? - Admas University College

advertisement
1
Programming Development and approaches
What is a program?

A program is a list of instructions that the computer must follow in order to
process data into information.

The instructions consist of statements written in a programming language, such as
Basic, Pascal, C, ...
3.1 Programming Development life cycle.
Programming Development life cycle involves the following steps:
 Preliminary Investigation
 Systems Analysis
 Systems Design
 Systems Development
 Systems Implementation &

Systems maintenance.
System Analysis

The system’s services, constraints and goals are established by consultation with
system users. They are then defined in a manner which is understandable by both
users and development staff.

Because software is always a part of a larger system, work begins by analysing
software interface with other elements such as hardware, people and databases
System Design

The systems design process partitions the requirements to either hardware or
software systems and establishes an overall architecture.

Software design involves representing the software system functions so that they
may be transformed into one or more executable programs.
System development






Preliminary investigation
System Analysis
System Design
System development
System implementation
System maintenance
Prepared by Binyamin N. (Noah)
2
System implementation

The individual program units or program are integrated and tested as a complete
system to ensure that the software requirements have been met
System maintenance

Software will undoubtedly undergo change after it is delivered to the customer
(except embedded software).

Change will occur because errors have been encountered, because of external
environment changes (new O.S. Or peripheral devices) or because the customer
requires functional or performance enhancements
3.2 What is programming?


Programming is a five step process for creating that list of instructions.
o
Define the problem
o
Define a solution
o
Code the program
o
Test the program
o
Document the program
Only one of those steps (the step called coding) consists of sitting at the keyboard
typing words into a computer.
First step : Problem definition

Specify program objectives (problem you are trying to solve) and users (internal,
external)

Specify: Output (Hard and softcopy) with users Input (needed, sources…)
Processing requirements (tasks)

Study the feasibility of implementing the program (Budget, Staff, Time, … +
make-or-buy decision)

Document the analysis
Prepared by Binyamin N. (Noah)
3
Second step: Design the program

The program logic is determined through a top-down approach and
modularisation, using hierarchy chart.

Next the program is designed with certain tools: pseudocode and/or flowcharts
with control structures.

Finally, the design is tested with a structured walkthrough
A Hierarchy Chart










Payroll Process
Read Input
Calculate pay
Generate output
Read employee master record
Read individual time card
Generate payroll report
Generate paychecks
Calculate gross pay
Calculate net pay
Second Step: Design the program Top-Down Approach

Top-down program design proceeds by identifying the top element, or module, of
a program and then breaking it down in hierarchical fashion to the lowest level of
detail. The top-down program design is used to identify the program’s processing
steps or modules.

A module (subprogram or subroutine) is a processing step of a program. Each
module is made up of logically related program statements
Second Step : Design the program

Pseudocode is a method of designing a program using English-like statement to
describe the logic and processing flow.

Flowcharts are a chart that graphically presents the detailed series of steps
needed to solve a programming problem.
Prepared by Binyamin N. (Noah)
4
Second Step: Design the program Design Details, Using pseudocode
START
DO WHILE (so as long as) there are records
Read a customer billing account record
IF today’s date is greater than 30 days from date of last customer payment THEN
Calculate total amount due
Calculate 5% interest an amount due
…
ELSE
Calculate amount due
END IF
Print out invoice
END DO
END CONTROL STRUCTURES
Second step : Design the program Do a Structured Walkthrough

In the structured walkthrough, a programmer leads other people in the
development team through a segment of code.

It consists of a formal review process in which others- fellow programmers,
systems analysts and users-scrutinize (“walk through”) the programmer’s work.
They review the parts of the program for errors, omissions, and duplications in
processing tasks
Prepared by Binyamin N. (Noah)
5
Third step : Code the program

Writing the program is called coding.

Coding consists of translating the logic requirements from pseudocode of
flowcharts into a programming language-the letters, numbers and symbols that
make up the program.

It consists of choosing the appropriate programming language and following its
rules, or syntax exactly.
Fourth step : Test the program

Program testing involves running various tests, such as desk-checking and
debugging, and then running real-world data to make sure the program works.

Desk-checking is simply reading through, or checking, the program to make sure
that it’s free of errors and that the logic works

To debug means to detect, locate, and remove all errors (syntax & logic) in a
computer program.

Run real-Word Data: Test with data from the real world, with bad data
(incomplete …), with many users...
Fifth step : Document the program

Documenting the program consists of writing a description of its purpose and
process.

Documentation should be prepared for users, operators, and programmers
(maintenance).
Characteristics of good Programming
It should be Correct /Logical
It should be Understandable to other People
It should be easy to Change
It should be written efficiently
Prepared by Binyamin N. (Noah)
6
Programming Techniques and Code Review
If you have programmed in other languages, hold on to your hats— Visual Basic is unlike
other programming languages. The primary difference is that Visual Basic is fun to work
with. The word fun simply does not apply to many other programming languages. With
Visual Basic, you create most of your programs by clicking and moving your mouse.
Instead of programming, you really build programs. Visual Basic is one of the few
programming tools with which you can efficiently design your program while you create
your program.
This part describes what programming is all about using different programming
techniques.
Example 4.1. An early FORTRAN program.
WRITE (6, 10)
10 FORMAT('** Payroll Calculations **')
WRITE (6, 11)
11 FORMAT('** Enter the employee's ID, hours, and pay rate')
TAXRAT = 0.25
101 READ(5, 102, END=900) IDEMP, HRSWRK, RATE
102 FORMAT(I5, 1X, I3, F5.2)
IF (HRSWRK .GT. 40) GOTO 300
*******COMPUTE REGULAR PAY
GRSPAY = HRSWRK * RATE
GOTO 500
300 OVRHRS = HRSWRK - 40
*******COMPUTE OVERTIME PAY
OTGRS = OVRHRS * RATE *
1.5
GRSPAY = 40.0 * RATE + OTGRS
500 TAXES = GRSPAY * TAXRAT
PAYNET = GRSPAY - TAXES
WRITE (6,503) IDEMP, PAYNET
503 FORMAT('EMP: ', I3, 2X, 'NET PAY:', F6.2)
GOTO 101
Prepared by Binyamin N. (Noah)
7
*******END-OF-JOB PROCESSING
900 END
If you are unfamiliar with FORTRAN programs or with programming in any other
language, you probably will not understand much of what you see in the Example above.
You might, however, be able to tell from some of the words, that the code performs
payroll calculations of some kind. It is true that FORTRAN does not produce extremely
readable code, but the commands such as IF, GOTO, and WRITE, improved programmer
productivity greatly over what programmers had to do before such languages came along.
With high-level languages such as FORTRAN, the 1950s and 1960s saw an incredible
distribution of new software. Programming became more accessible to more people
because of the easier-to-use programming languages. The increased number of programs
brought a tremendous increase in the number of computers sold. Companies, laboratories,
and universities purchased computers. There was no turning back the computer era once
so many people had access to so much computing power. As computer companies sold
more computers, competition produced less expensive and more powerful machines. And
you thought that the 1990s were exciting!
Definition: Syntax refers to the spelling and grammar of languages.
Even though programming languages were easier to learn, there was still much need for
easier programming methods. The computer scientist developed BASIC, the language
that enabled students to write programs because of its easier format and less restrictive
syntax than FORTRAN’s.
Note: BASIC is an acronym for Beginner's All-purpose Symbolic Instruction Code. The
acronym's meaning is almost as long as—and much more difficult to remember than—
the BASIC language itself.
Example below shows the BASIC equivalent of the FORTRAN program that you saw in
Example above. This BASIC example might not be significantly easier to understand
than the FORTRAN code. Nevertheless, the BASIC language is a little cleaner and
slightly less cryptic than its FORTRAN predecessor. Although programming still took
effort, BASIC took some of the rough edges off programming, and it brought more
people to the programming craft.
Example 4.2. A BASIC program with early versions of BASIC Program.
[10] PRINT "** Payroll Calculations **"
[20] PRINT "** Enter the employee's ID, hours, and pay rate"
[30] TAXRAT = .25
Prepared by Binyamin N. (Noah)
8
[40] INPUT IDEMP$, HRSWRK, RATE
[50] IF (IDEMP$ = "") THEN GOTO [160]
[60] IF (HRSWRK > 40) GOTO [70]
[70] REM *******COMPUTE REGULAR PAY
[80] GRSPAY = HRSWRK * RATE
[90]
GOTO [110]
[100] OVRHRS = HRSWRK - 40
[110] REM *******COMPUTE OVERTIME PAY
[120] OTGRS = OVRHRS * RATE * 1.5
[130] GRSPAY = 40 * RATE + OTGRS
[140] TAXES = GRSPAY * TAXRAT
[150] PAYNET = GRSPAY - TAXES
[160] PRINT "EMP: "; IDEMP$; "NET PAY:"; PAYNET
[170] GOTO [20]
[180] END
Well into the 1980s, the rate at which the number of programmers grew remained high.
Despite all new programmers, the programming tools themselves really did not advance
much. Many people developed new programming languages. Despite their "new and
improved" claims, most of the languages retained the textual procedural quality that
FORTRAN and BASIC offered.
Large-scale programming tool improvements did not occur until a hardware breakthrough
occurred: NASA's space efforts developed the microchip, and microcomputers were
born. Now, instead of new and potential programmers, desktop computers opened the
door for millions of would-be programmers. These programmers demanded easier
programming tools.
Efforts were made to improve the friendliness of programming languages like BASIC.
New versions of BASIC, such as Liberty BASIC, QBasic enabled programmers to write
Prepared by Binyamin N. (Noah)
9
more powerful programs with less effort. Programmers could also write programs that
had a less rigid style than those before. The Next Example shows a Liberty BASIC
version of the payroll calculation shown in the previous two examples. As you can see,
the language is getting less strict and more free-form.
Example 4.3. A Liberty BASIC program.
TaxRate = .25
PRINT "** Payroll Calculations **"
PRINT "** Enter the employee's ID, hours, and pay rate"
PRINT "** If you want to exit please press the Enter Key on your keyboard **"
INPUT IdOfEmp$, HrsWorked, Rate
DO UNTIL (IdOfEmp$ = "")
IF (HrsWorked <= 40) THEN
'*******Compute regular pay
GrossPay = HrsWorked * Rate
ELSE
' *******Compute overtime pay
OverTimeHours = HrsWorked - 40
OverTimeGross = OverTimeHours * Rate * 1.5
GrossPay = 40 * Rate + OverTimeGross
END IF
Taxes = GrossPay * TaxRate
PayNet = GrossPay - Taxes
PRINT "Emp: "; IdOfEmp$; " Net Pay:"; PayNet
INPUT IdOfEmp$, HrsWorked, Rate
LOOP
END
Prepared by Binyamin N. (Noah)
10
Just as a recipe has a result, the cooked meal, instructions in a program produce an
important result. The result of the programming effort is the finished program that makes
the computer perform a directed task, such as payroll processing. After entering a
program or loading a program from the disk, you must tell the computer to run, or
execute, the program. The computer then follows the program's instructions and produces
the output.
If you entered the code in the Liberty BASIC Example above into the editor, the
following output might result:
** Payroll Calculations **
** Enter the employee's ID, hours, and pay rate
** If you want to exit please press the Enter Key on your keyboard **
?Emp001
??15
???20
Emp: Emp001 Net Pay:225
?
4.2 Procedural, Structured, and Object-Oriented Programming
Until recently, programs were thought of as a series of procedures that acted upon data. A
procedure, or function, is a set of specific instructions executed one after the other. The
data was quite separate from the procedures, and the trick in programming was to keep
track of which functions called which other functions, and what data was changed. To
make sense of this potentially confusing situation, structured programming was created.
The principle idea behind structured programming is as simple as the idea of divide and
conquers. A computer program can be thought of as consisting of a set of tasks. Any task
that is too complex to be described simply would be broken down into a set of smaller
component tasks, until the tasks were sufficiently small and self-contained enough that
they were easily understood.
As an example, computing the average salary of every employee of a company is a rather
complex task. You can, however, break it down into these subtasks:
Prepared by Binyamin N. (Noah)
11
1. Find out what each person earns.
2. Count how many people you have.
3. Total all the salaries.
4. Divide the total by the number of people you have.
Totalling the salaries can be broken down into
1. Get each employee's record.
2. Access the salary.
3. Add the salary to the running total.
4. Get the next employee's record.
In turn, obtaining each employee's record can be broken down into
1. Open the file of employees.
2. Go to the correct record.
3. Read the data from disk.
Structured programming remains an enormously successful approach for dealing with
complex problems. By the late 1980s, however, some of the deficiencies of structured
programming had become all too clear.
First, it is natural to think of your data (employee records, for example) and what you can
do with your data (sort, edit, and so on) as related ideas.
Second, programmers found themselves constantly reinventing new solutions to old
problems. This is often called "reinventing the wheel," and is the opposite of reusability.
The idea behind reusability is to build components that have known properties, and then
to be able to plug them into your program, as you need them. This is modelled after the
hardware world--when an engineer needs a new transistor, she doesn't usually invent one,
she goes to the big bin of transistors and finds one that works the way she needs it to, or
perhaps modifies it. There was no similar option for a software engineer.
Old-fashioned programs forced the user to proceed step-by-step through a series of
screens. Modern event-driven programs present all the choices at once and respond to the
user's actions.
Object-oriented programming attempts to respond to these needs, providing techniques
for managing enormous complexity, achieving reuse of software components, and
coupling data with the tasks that manipulate that data.
Prepared by Binyamin N. (Noah)
12
The essence of object-oriented programming is to treat data and the procedures that act
upon the data as a single "object"--a self-contained entity with an identity and certain
characteristics of its own
Visual Programming

Visual programming is a method of creating programs in which the programmer
makes connections between objects by drawing, pointing and clicking diagrams.

The goal of visual programming is to make programming easier for programmers
and more accessible to nonprogrammers.

Visual programming enables users to think more about solving the problem than
about handling the programming language
Internet Programming

Programming languages used to build linked, multimedia sites on the World Wide
Web include,
o
HTML (Hypertext Markup Language).
o
VRML (Virtual Reality Markup Language).

Java (Object Oriented),JavaScript and ASP.
Prepared by Binyamin N. (Noah)
Download