Week 1
Week 1
To understand:
• Concept of programming
• Features of a good program
• Systems development cycle.
CONCEPT OF PROGRAMMING
Programming Language:
- The language used to write code
- A set of rules, syntax, and semantics used to write software.
- Defines how to write instructions that a computer can understand.
- Example: Java, Python, C++, JavaScript.
Program:
The actual software application or code written a programming language
- A set of instructions written in a programming language.
- A software application or a piece of code that performs a specific task.
- Definition: A set of instructions written in a programming language.
- Example: Web browser, Game, Operating System, mobile apps.
Programmer:
The person who writes the code in a programming language
- Responsible for designing, writing, testing, and maintaining software programs.
- May work on a single program or multiple programs.
- Example: Software developer, Coder, Software engineer.
Programming:
- The process of writing code and creating software applications
- The process of writing code in a programming language.
- The act of creating software, including designing, writing, testing, and debugging.
- Involves using programming languages, tools, and techniques to solve problems or create
software applications.
- Example: Writing Java code, Developing an app, Building a website.
Concise
- Programming Language is the tool (language).
- Program is the output (software).
- Programmer is the person (developer).
- Programming is the process (writing code and creating software).
A program is a set of instructions that tells the computer what to do. Computer programming
(often shortened to programming or coding), is the process of writing, testing,
debugging/troubleshooting and maintaining act of instructions (source code) for solving a
problem with the computer. A source code is written in an acceptable computer programming
language. The code may be a modification of an existing source or something completely new.
The purpose of programming is to create a program that exhibits a certain described behavior
(customization). The process of writing source code requires expertise in many different
subjects, including knowledge of the application domain. Alternatively. Programming is the
craft of transforming requirements into something that a computer can execute. Problem solving
on computer is a task of expressing the solution to the problem in terms of simple concepts,
operations and computer code (program) to obtain the results. To achieve this aim, you may
proceed as follows.
1. First, understand the problem clearly:- Decide what you want to be calculated by the
computer. What will be the input data required? (if any). This is the problem formulation.
2. Write the steps of computation that are necessary to arrive at the solution. This is setting up
the algorithm.
3. Prepare a flowchart corresponding to the algorithm.
4. Develop the computer program. Test and run it on the computer. There is an ongoing debate
on the extent to which the writing of programs is an art, a craft or an engineering discipline.
Good programming is generally considered to be the measured application art, craft and
engineering, with the goal of producing an efficient and maintainable software (program)
solution. The discipline differs from may other technical professions in that programmers
generally do not need to be licensed or pass any standardized (or governmentally regulated)
certification tests in order to call themselves “programmers” or even “software engineers”.
WEEK 2
To understand:
• The Concept of Algorithm
• Definition of Algorithm
• Features of an Algorithm
• Methods of representing Algorithm
Concept of Algorithm
An algorithm is a set of instructions to obtain the solution of a given problem. Computer needs
precise and well-defined instructions for finding solution of problems. If there is any ambiguity,
the computer will not yield the right results. It is essential that all the stages of solution of a
given problem be specified in details, correctly and clearly moreover, the steps must also be
organized rightly so that a unique solution is obtained.
A typical programming task can be divided into two phases:
(a) Problem solving phase
In this stage an ordered sequence of steps that describe solution of the problem is produced.
Their sequence of steps can be called anti-Algorithm
(b) Implementation Phase
In this phase, the program is implemented in some programming languages. Algorithm may be
set up for any type of problems, mathematical/scientific or business. Normally algorithms for
mathematical and scientific problems involve mathematical formulars. Algorithms for business
problems are generally descriptive and have little use of formula.
Features of an Algorithm
1. It should be simple
2. It should be clear with no ambiguity
3. It should head to unique solution of the problem
4. It should involve a finite number of steps to arrive at a solution
5. It should have the capability to handle unexpected situation.
Methods of Representing Algorithm
Algorithms are statements of steps involved in solving a particular problem. The steps to the
solutions are
broken into series of logical steps in English related form. Programs are written to solve real life
problems. There can’t be a solution if there is no recognized problem and once a problem exist,
one must take certain step in order to get a desired solution. The following methods could be
used to represent an algorithm.
Methods of English like form
Methods of Flowchart
Methods of Pseudo code
Methods of Decision table
Methods of Data flow Diagram (DFD)
Pseudo code
A pseudo code is the English-like representation of the program logic. It does not make use of
standard symbols like the flowchart. It is a sequential step by step arrangements of the
instructions to be performed to accomplish a task. It is an informal and artificial language that
helps programmers develop algorithms.
Example 1
Write a pseudo code for findings the area of a room.
Solution:
• Begin process
• Input room length
• Input room width
• Multiply length by width to get area
• Print area
• End process
Solution for example 3 (below under pseudo code)
• Step 1: Input M1, M2, M3, M4
• Step 2: Grade ← (M1 + M2 + M3 + M4)/4
• Step 3: If (Grade < 50) then
• Print “FALL”
• Print “Pass”
• End it.
Example 2
Write a Pseudo code for finding the greatest of 3 numbers represented as A, B, and C.
Solution
• Begin process
• Input A,B,C
• If A>B then big = A
• Else big = B
• If big >C then bigst = big
Else bigst = C
Example 3
Write an Algorithm to determine a student’s final grade and indicate whether it is passing or
failing.
The final grade is calculated as the average of four marks.
Solution
• Input a set of 4 marks
• Calculate their average by summing and dividing by 4.
• If average is below 50
Print “Fail”
else
Print “Pass”
WEEK 3
• The Concept of Algorithm
• Definition of Algorithm
• Features of an Algorithm
• Methods of representing Algorithm
English-like form
The English form of representing as algorithm entails breaking down the solution steps of the
problem into single and sequential English words. The steps are represented in English to say
what action should be taken in such a step.
Example 1
Develop an algorithm to obtain a book on computer from your school library located on the
fourth floor of the building. You are to proceed to the library from your ground floor classroom.
1. Start from the classroom
2. Climb the stairs to the 4th floor and reach the library
3. Search a book on computer
4. Have the book issued
5. Return to your classroom
6. Stop.
Note: The above algorithm solution of example 1, has been written in simple and clear English
way.
There is no
Example 2
Develop an algorithm to find the average of four numbers stored in variables A,B,C,D
Solution
1. Start
2. Read values in variables A,B,C,D
3. Calculate the average as (A+B+C+D)/4 and store the result in P.
4. Write the value stored in P
5. Stop.
Example 3
Develop and algorithm to find the average of four numbers stored in variables A, B, C, D.
When the value of variable A is zero, no averaging is to be done.
Solution
1. Start
2. Read values stored in variable A,B,C.D
3. If the value of A is Zero, then jump to step 6
4. Calculate the average of A, B, C, D and store the result in variable P.
5. Write the value of P
6. Stop.
Flowchart
Flowchart is a representation of the algorithm using standard symbols. Each symbols has a new
function.
The Algorithm steps determine which symbol to use to represent it in the flow each step is
linked to another step by using the directional arrows.
Example
Write an algorithm and draw a flowchart to convert the length in feet to centimeter.
Solution
(Pseudocode)
• Input the length in feet (Lft)
• Calculate the length in an (LCM) by multiplying LFT with 30
• Print Length in Cm (LCM)
Flow Chart Symbols and Flow Chart For Mailing Letter
Step 1: Input Lft
Step 2: Lcm ← Lft * 30
Step 3: Print Lcm
Step 4: Stop
WEEK 4
• The Concept of Algorithm
• Definition of Algorithm
• Features of an Algorithm
• Methods of representing Algorithm
Decision table
A decision table is a form of truth table that structures the logic of a problem into simple YES
and No form. It is easily adapted to the needs of business data processing. It is a rectangle
divided into four sections called quadrants. It provides a structure for showing logical
relationships between conditions that exist and actions to be taken as a result of these
conditions. The quadrants of a decision table are called the condition steeb, the condition entry,
the action stub and the action entry respectively.
1. The number of condition is used to determine the number of entries by using the formula,
where n is the number of condition.
2. Halving method is used to form the entries in the condition entry e.g if the number of
conditions in a question is 3, then the no of entries will be 23 =8. Therefore in the condition
entry box, the first row will have 4 Ys and 4 Ns. The second row will have 2Ys and 2Ns by
2.Finally the 3rd row willhave 1Y and 1N into 4
1 Condition stub:- This gives a list of all the conditions that are relevant to the system.
2 Condition entry: - Shows a YES or NO entry (abbreviated to Y for YES and N for NO)
whether listed condition is present or absent.
3 Action stubs: - This quadrant gives a list of all the actions that could be taken by the system,
based on the conditions.
4 Action entry: - This quadrant indicates whether a specific action will be taken or will not be
taken.
Action stub Action entry
The condition entries
i. Y is an indication that the condition is present
ii N is an indication that the condition is not present
iii - or blank is an indication that the condition was not tested.
The action entries
i. X is an indication that the listed action to be taken.
ii. blank is an indication that the action is not to be taken.
Advantages of Decision Tables
1. They are simple, practicable and economical .All that is regarded to developed a decision
table is a piece of paper and a pencil
2. It makes the system designer to express the logic of the problem in direct and concise terms,
which results in the development of an effective and efficient program.
3. It is useful in program documentation i.e decision tables provide a quick and easily
understood overview of the system.
4. It is an excellent communication device to breach the gap between the computer personnel
who are responsible for developing the system and the non data processing personnel who use
the output of the system.
5. Decision tables are easy to update.
6. It is easy to lean how to use decision table.
7. The complexity and the amount of detail that can be handed by a decision table is un-limited.
Disadvantages
1 Total sequence: The total sequence of an operation is not clearly shown in the decision table
i.e no overall picture is given as with flowcharts.
2 Logic: Where the logic of a system is simple flowcharts always serve the purpose better.
Example
A wholesaler gives discount according to the following rules.
i. Irrespective of the value of the sale and whether it is for cash or credit, existing customers get
a 5% discount.
ii. If the sale is for cash, then existing customers receive a 10% discount in total.
iii. If the sale is for over #1000 and for cash then existing customers receive a15% discount in
total.
iv. New customers never receive a discount of any sort.
You are regarded to construct a limited entry decision table to describe the above process.
SOLUTION
Data flow Diagrams
A data flow diagram shows the flow of the data among a set of components. The components
may be tasks, software components, or even abstractions of the functionality that will be
included in the software system. The actors are not included in the data flow diagrams. The
sequence of actions can often be inferred from the sequence of activity boxes.
WEEK 5
Definition of flowchart
Description of flowchart symbols
Solving simple programming table with flowcharts
The flowchart
A flowchart is a pictorial representation of an Algorithm or of the plan of solution of a problem.
It indicates the process of solution, the relevant operations and computations, point of decision
and other information that are part of the solution. Flowcharts are of particular importance for
documenting a program. Special geometrical symbols are used to construct flowcharts. Each
symbol represents an activity. The activity could be input/out of data, computation/processing
of data, taking a decision, terminating the solution, etc. The symbols are joined by arrows to
obtain a complete flowchart.
Example 2
Draw a flowchart to find the average of four numbers stored in variables A,B,C,D. when the
value of A is zero, no averaging is to be done.
Example 3
Write a flowchart to determine a student final grade and indicate whether it is pass or fail. The
final grade is calculated as the average of four marks.
Solution
Start
READ values
For A,B,C,D.
Is
A=0
?
Calculate the average
Write the value of
P
Stop
Start
Input
M1 M2 M3 & M4
Example 4
Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate
its area.
Solution
Pseudo code
• Input the Width (w) and Length(L) of a rectangle
• Calculate the area (A) by multiplying L with W
• Print A.
Algorithm
Step 1: Input W, L
Step 2: A← L * W
Step 3: Print A.
Example 5
Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation.
ax2+ bx + c = 0
Hint: d = SQrt(b2
– 4ac), and the roots are:
X1 = (-b + d)/2a and X2 = (b – d)/ 2a
Solution
Pseudo code
• Input the coefficients (a, b, c) of the quadratic equation
• Calculate d
• Calculate X1
• Calculate X2
• Print X1 and X2
Algorithm
Stop
Input
W,L
A←L*W
Print A
Stop
Step 1: Input a, b, c
Step 2: d ← Sqrt (b * b – 4 * a * c)
Step 3: X1 ← ( - b + d)/ (2 * a)
Step 4: X2 ← (- b – d)/ (2 * a)
Step 5: Print X1, X2
Flowchart
Uses of flowcharts
1 It gives us an opportunity to see the entire system as a whole.
2 It makes us to examine all possible logical outcomes in any process.
3 It provides a tool for communicating i.e a flowchart helps to explain the system to others.
4 To provide insight into alternative solutions.
5 It allows us to see what will happen if we change the values of the variable in the system.
Start
Input
a, b, c
d ← Sqrt + (b * b – 4*a*c
X1 ← (-b + d)/ (2*a)
X2 ← (-b – d) / (2* a)
Print
X1, X2
Stop
ADVANTAGES OF USING FLOWCHART
1. Communication flowcharts are visual aids for communicating the logic of a system to all
concerned.
2. Documentation: flowcharts are a means of documentation because:
3 The analyst/ programmers may leave the arrangement or they may forget the logic of the
program.
4 Changes to the procedure are more easily catered for (modification).
5 Flowchart can be understood by new staff coming to the company
6 Analysis: flowcharts help to clarify the logic of a system i.e the overall picture of the
organization can be seen.
7 Consistency: A flowchart is a consistent system of recording. It brightens @ the relationships
between different parts of a system.
DISADVANTAGES OF USING FLOWCHART
1. Complex logic:- Where the logic of a problem is complex, the flowchart quickly becomes
clustered and lacks clarity.
2. Alterations:- If alterations are required the flowchart may require redrawing completely.
3. Reproduction:- As the flowchart symbols cannot be typed, reproduction of flowchart is often
a problem.
WEEK 6
To understand:
* Design algorithm for problems involving.
• Strictly sequence control structure
• Selection control structure
• Iteration control structure
(b) Double alternative: This structure has the form ie IF condition holds, then module A
executed; otherwise module B is executed.
2. Calculations
2.1 Calculate interest = deposit * rate * years
2.2 Calculate ending balance = deposit + interest
3. Output
3.1 Print interest and ending balance
Modular flowchart plan for the problem
Modular Hierarchy plan for the problem
Many programmers who write modular programs prefer to plan their programs with hierarchy
chart.
A hierarchy chart is used to plan and show program structure. It is constructed much like an
organization chart. As shown the solution below, level A shows the entire program, which is
broken down into major program functions on the B level. The modules can be broken into
smaller
and smaller parts until the coding for each function becomes straightforward. Many
programmers
use a hierarchy chart to plan the overall structure of a program. Then, when the individual
modules
are identified, flowcharting or pseudo code will be used to plan the details of the logic.
WEEK 8
• Identify the problem and confirm it solvable.
• Design algorithm for the chosen method of solution with flowcharts or pseudo codes.
• Code the algorithm by using a suitable programming language.
• Test run the program on the computer.
MACHINE LANGUAGE
Machine Code or machine language is a low-level programming language that can be
understood directly by a computer’s central processing unit (CPU). Machine code consists of
sequences of binary numbers, or bits, which are usually represented by 1s and 0s, and which
form the basic instructions that guide the operation of a computer. The specific set of
instructions that constitutes a machine code depends on the make and model of the computer’s
CPU. For instance, the machine code for the Motorola 68000 microprocessor differs from that
used in the Intel Pentium microprocessor.
Writing programs in machine code is tedious and time-consuming since the programmer must
keep track of each specific bit in an instruction. Another difficulty with programming directly in
machine code is that errors are very hard to detect because the program is represented by rows
and columns of 1s and 0s.
Advantages of Machine Language
1) Less code is produced
2) Storage is saved
3) User has direct control of machine instruction
4) Execution is faster as no translation is needed
5) The programmer knows all the registers and instruction that use them.
Disadvantages of Machine Language
1) Cumbersome ie, tedious and difficult to learn
2) Programmer’s fluency is affected, thereby making the programs developed inefficient.
3) The developed programs are error prone and difficult to debug (correct)
4) The performance of the system is unreliable.
ASSEMBLY LANGUAGE
Assembly language is type of low-level computer programming language in which each
statement corresponds directly to a single machine instruction. Assembly languages are thus
specific to a given processor. After writing an assembly language program, the programmer
must use the assembler specific to the microprocessor to translate the assembly language into
machine code. Assembly language provides precise control of the computer, but assembly
language programs written for one type of computer must be rewritten to operate on another
type. Assembly language might be used instead of a high-level language for any of three major
reasons: speed, control, and preference. Programs written in assembly language usually run
faster than those generated by a compiler; use of assembly language lets a programmer interact
directly with the hardware (processor, memory, display, and input/output ports). Assembly
language uses easy-to-remember commands that are more understandable to programmers than
machine-language commands. Each machine language instruction has an equivalent command
in assembly language. Assembly language makes programming much easier, but an assembly
language program must be translated into machine code before it can be understood and run by
the computer. Special utility programs called assemblers perform the function of translating
assembly language code into machine code.
Like machine code, the specific set of instructions that make up an assembly language depend
on the make and model of the computer’s CPU. Other programming languages such as Fortran,
BASIC, and C++, make programming even easier than with assembly language and are used to
write the majority of programs. These languages, called high-level languages, are closer in form
to natural languages and allow very complicated operations to be written in compact notation.
Assignment
The difference between run-time, logical and syntax errors?
• Students should identify the differences from the above explanations.
Program maintenance
Program/software maintenance is the modification of a software product after delivery to
correct faults, to improve performance or other attributes, or to adapt the product to a modified
environment. This international standard describes the 6 software maintenance processes as:
1. The implementation processes contains software preparation and transition activities, such as
the conception and creation of the maintenance plan, the preparation for handling problems
identified during development, and the follow-up on product configuration management.
2. The problem and modification analysis process, which is executed once the application has
become the responsibility of the maintenance group. The maintenance programmer must
analyze each request, confirm it (by reproducing the situation) and check its validity, investigate
it and propose a solution, document the request and the solution proposal, and, finally, obtain all
the required authorizations to apply the modifications.
3. The process considering the implementation of the modification itself.
4. The process acceptance of the modification, by checking it with the individual who submitted
the request in order to make sure the modification provided a solution.
5. The migration process is exceptional, and is not part of daily maintenance tasks. If the
software must be ported to another platform without any change in functionality, this process
will be used and a maintenance project team is likely to be assigned to this task.
6. Finally, the last maintenance process, also an event which does not occur on a daily basis, is
the retirement of a piece of software.
Categories of Program maintenance
E.B. Swanson initially identified three categories of maintenance: corrective, adaptive, and
perfective.
• Adaptive maintenance: Modification of a software product performed after delivery to keep a
software product usable in a changed or changing environment.
• Perfective maintenance: Modification of a software product after delivery to improve
performance or maintainability. Preventive maintenance: Modification of a software product
after delivery to detect and correct latent faults in the software product before they become
effective faults.
Difference between program maintenance and debugging
A common perception of maintenance is that it is merely fixing bugs. However, studies and
surveys over the years have indicated that the majority, over 80%, of the maintenance effort is
used for non-corrective actions. Key findings shows that program maintenance is really
evolutionary developments and that maintenance decisions are aided by understanding what
happens to systems (and software) over time.
While Debugging is a very important task in the software development process, because an
erroneous program can have significant consequences for its users. Some languages are more
prone to some kinds of faults because their specification does not require compilers to perform
as much checking as other languages. Use of a static analysis tool can help detect some possible
problems.
WEEK 12
THE CONCEPT OF GOOD PROGRAMMING PRACTICE
Structured Programming is a general term referring to programming that produces programs
with clean flow, clear design, and a degree of modularity or hierarchical structure. Benefits of
structured programming include ease of maintenance and ease of readability by other
programmers. Structured Programming is one step beyond modular programming with
guidelines for “good” modules and “poor” modules. The structured programming guidelines
also define “proper” flow of control and coding standards (such as indentation). In many large
programming projects where statistics have been kept, it has been shown that structured
programming has many demonstrable advantages over the old style, unstructured programs,
such as:
1. Programs are more reliable. Fewer bugs appear in testing and later operation.
2. Programs are easier to read and understand
3. Programs are easier to test and debug.
4. Programs are easier to maintain.
Most commercial programming shops report that at least 50 percent of programmer time is
spent making changes and correction in existing programs rather than developing new programs
(some report more than 90 percent maintenance). Anything that will save time in correction and
maintenance can save a company considerable money. It is easy to see why most commercial
stops hiring programmers insist on structured programming techniques. The current definition
of structured programming includes standards for program design, coding and testing that are
designed to create proper, reliable, and maintainable software. These standards include coding
guidelines and rules for flow of control and module formation.
Structured Coding Guidelines
The structured coding guidelines are designed to make programs more reliable and easier to
understand.
1. Use meaningful variable names
2. Code only one statement per line.
3. Use REMarks to explain program logic.
4. Indent and align all statements in a loop.
5. Indent the THEN and ELSE actions of an IF statement.
Flow of Control
In 1964, Italians Bohm and Jacopini proved mathematically that any program logic can be
accomplished with just three control structures. Within a few years, studies were done declaring
the GOTO statement to be harmful to good programming. In fact, in comparisons of selected
large programming projects, there was a direct correlation between the number of GOTO
statements and program bugs found. BASIC was not designed as a structured language, but
some of the current additions to the language now permit the programmer to adhere to the three
“proper” constructs. All programming can be done with combinations of these three construct.
Iteration – This is the loop structure. The BASIC statement learned for looping are the
WHILE/WEND.
Others include;
• Looping
• Do...Loop Statement
• For...Next Statement
Visual Basic allows a procedure to be repeated as many times as long as the processor could
support. This is generally called looping.
Do...Loop Statement
Repeats a block of statements while a condition is True or until a condition becomes True.
Syntax
Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop
Or, you can use this syntax:
Do
[statements]
[Exit Do]
[statements]
Loop [{While | Until} condition]
The Do Loop statement syntax has these parts:
Remarks
Any number of Exit Do statements may be placed anywhere in the Do…Loop as an alternate
way to exit a Do…Loop. Exit Do is often used after evaluating some condition, for example,
If…Then, in which case the Exit Do statement transfers control to the statement immediately
following the Loop.
When used within nested Do…Loop statements, Exit Do transfers control to the loop that is one
nested level above the loop where Exit Do occurs.
Example
This example shows how Do...Loop statements can be used. The inner Do...Loop statement
loops 10 times, sets the value of the flag to False, and exits prematurely using the Exit Do
statement. The outer loop exits immediately upon checking the value of the flag.
Dim Check, Counter
Check = True: Counter = 0 ' Initialize variables.
Do ' Outer loop.
Do While Counter < 20 ' Inner loop.
Counter = Counter + 1 ' Increment Counter.
If Counter = 10 Then ' If condition is True.
Check = False ' Set value of flag to False.
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately.
For...Next Statement
Repeats a group of statements a specified number of times.
Syntax
For counter = start To end [Step step]
[statements]
[Exit For]
[statements]
Next [counter]
The For…Next statement syntax has these parts:
Remarks
The step argument can be either positive or negative. The value of the step argument determines
loop processing as follows:
After all statements in the loop have executed, step is added to counter. At this point, either the
statements in the loop execute again (based on the same test that caused the loop to execute
initially), or the loop is exited and execution continues with the statement following the Next
statement.
Tip Changing the value of counter while inside a loop can make it more difficult to read and
debug your code.
Any number of Exit For statements may be placed anywhere in the loop as an alternate way to
exit. Exit
For is often used after evaluating of some condition, for example If...Then, and transfers control
to the statement immediately following Next.
You can nest For...Next loops by placing one For...Next loop within another. Give each loop a
unique variable name as its counter. The following construction is correct:
For I = 1 To 10
For J = 1 To 10
For K = 1 To 10
...
Next K
Next J
Next I
Note If you omit counter in a Next statement, execution continues as if counter is included. If a
Next
statement is encountered before its corresponding For statement, an error occurs.
Example
This example uses the For...Next statement to create a string that contains 10 instances of the
numbers 0 through 9, each string separated from the other by a single space. The outer loop
uses a loop counter
variable that is decremented each time through the loop.
Dim Words, Chars, MyString
For Words = 10 To 1 Step -1 ' Set up 10 repetitions.
For Chars = 0 To 9 ' Set up 10 repetitions.
MyString = MyString & Chars ' Append number to string.
Next Chars ' Increment counter
MyString = MyString & " " ' Append a space.
Next Words
Example
For counter=1 to 10 display. Text=counter
Next
Example
For counter=1 to 1000 step 10
counter=counter+1
Next
Example
For counter=1000 to 5 step -5
counter=counter-10
Next
One Entry, One Exit.
The primary rule for program modules is the each module must have only one entry point and
one exit point. So even though BASIC will allow a GOSUB to a line number within a
subroutine and will allow multiple RETURN statements, such violations of the “one-entry, one
exit” rule should be avoided.
The “Black Box” Concept
A “black box” (program module) is designed to accomplish a task. Generally, some data is
input to the module, a transformation occurs, and data is output from the module . the details of
what happens within the “black box” are not important to the overall program. What is
important is that for a given input, the module will reliably produce the correct output. That
module could be replaced by another – perhaps in another language such as assembler – without
changing the rest of the program. It is important that each module “stand alone.”
Module Cohesion
Choosing the correct statements to combine into module is an important skill for programmers
to develop.
“Good” or “bad” module design is often an elusive concept when beginning to modularize
programs.
Cohesion refers to the internal strength of a module. It is an indication of how closely related
each of the statements in a module are to one another. As cohesion is increased, module
independence, clarity, maintainability, and portability are increased.
Module Coupling
Coupling refers to the connections, or interfaces, between modules. As a general rule, modules
should be loosely coupled; that is, what goes on inside one module should not affect the
operation in other modules. The control for execution of program modules must “come from
above.” Looking at a hierarchy chart, a lower level module cannot determine what a higher
level module should do – or even a module at the same level. For example, do not allow the
detail read routine to determine that it is time to do final total calculations. That decision must
be made by the mainline.
When a decision will determine what function to perform, place that decision at as high a level
as possible.
Good programming practice
Good Programming Concept or Style makes code/program easier to maintain and modify.
Maintaining and modifying code is made much easier by following a few often-overlooked
techniques.
Whether the original programmer or someone else needs to make a change in the code the job is
much easier if the original programmer used lots of comments, gave the variables and constants
descriptive names, and sketched out the basic structure of the program at the very beginning in
pseudo-code.
Using Comments in Code
The use of comments can mean the difference between code which any competent programmer
can maintain or modify and a program that even the original programmer has trouble figuring
out. Every routine should start with at least one comment that documents the purpose of the
routine and any nonobvious dependencies or effects that the routine may have on other portions
of the program.
In a development environment in which several programmers will be contributing code, adding
a comment identifying the person who wrote the code will definitely help others to know who
to ask if a question should arise.
Using Descriptive Names for Variables, Constants and Functions
It can be very tempting to use short names for variables and constants but it is not a good
programming practice. A name such as DateOfBirth is much easier for other programmers to
understand than dob. Global variable names can all start with a lower case "g" so that any
programmer looking at the code will instantly know which entities are local and which are
global. Likewise, a lower case "k" can be the first letter of constants. This type of self-
documenting code greatly reduces the need for comments and some typical errors.
Using Pseudo-code in Comments
When first developing the structure of a program it can be very helpful to write out the different
routines in pseudo-code. This is language which resembles a cross between English and the
programming language that the code will eventually be written in.
Using pseudo-code allows the programmer to concentrate on the conceptual aspects of the
program without being distracted by syntax rules. The pseudo-code can also be the basis of the
comments so it can server two purposes.
Using Modular Coding
Whenever possible, the lines of a routine should fit entirely on one screen of the editor. By
keeping routines short, it is easier to comprehend them and see errors. Having short routines
also forces the programmer to break each task into distinct sub-tasks, each of which is easier to
maintain and modify in the future.
Modular coding also has the advantage of creating reusable routines that can be used in other
programs.
Once a routine is debugged and verified it is easier to copy and paste it into another program
than to write it all over again.
Following these simple suggestions will make a programmer's code easier to maintain and
modify. It may seem like more work, but in the end the net result is greater efficiency and fewer
mistakes.
To understand:
* Employ program documents technique HIPS, data flow diagram, pseudo-cal.
• Explain graphic user interface, GUI.
• Define interactive processing.
WEEK 13
Program documentation concepts
Program documentations
This is the act of keeping/maintaining all materials that serve primarily to describe a
system/program and make it more readily understandable rather than to contribute in some way
to actual operation of the system. Documentation is frequently classified according to purpose;
thus for a given system there may be requirements documents, design document, and so on.
Why is program documentation important?
1) The main purpose of program documentation is to describe the design of your program. The
documentation also provides the framework in which to place the code. as coding progresses,
the code is inserted into the framework already created by the program documentation.
2) Documentation is important to tell other programmers what the program does and how it
works. In the "real world" and in some classes here at BGSU, programmers often work in teams
to develop code. Documentation helps others on the team to understand your work.
3) Maintenance and debugging are needed sooner or later for most programs and these are
frequently done by someone other than the original programmer. Documentation can help the
programmer who is making the modifications understand your code.
4) Documenting your program during development helps you to maintain your sanity.
When should program documentation be done? When designing your program, you must spend
time thinking about how to structure your program, what modules are needed, and the
algorithms and processes you will use in the modules. You must think about what sort of data
structures and objects (e.g., arrays, files or linked lists) are needed. This thinking must be done
before you start coding, or you will find yourself wasting time writing useless code that is full
of errors. It is very important to record this creative process so that the programmers that follow
you do not duplicate work that you have already done. Before writing the code, you should
write the documentation to describe the design of each component of your program. Writing
documentation for the modules before writing the code helps you define exactly what each
module should do and how it will interact with other modules. Focusing on the design and the
steps needed to solve the problem can help prevent errors in the completed program.
WEEK 14
Object oriented (00) program
Object-oriented languages are outgrowths of functional languages. In object-oriented languages,
the code used to write the program and the data processed by the program are grouped together
into units called objects. Objects are further grouped into classes, which define the attributes
objects must have.
A simple example of a class is the class Book. Objects within this class might be Novel and
Short Story. Objects also have certain functions associated with them, called methods. The
computer accesses an object through the use of one of the object’s methods. The method
performs some action to the data in the object and returns this value to the computer. Classes of
objects can also be further grouped into hierarchies, in which objects of one class can inherit
methods from another class. The structure provided in object oriented languages makes them
very useful for complicated programming tasks.
Features of OOP
Object-oriented programming (OOP) languages, such as C++ and Java, are based on traditional
high-level languages, but they enable a programmer to think in terms of collections of
cooperating objects instead of lists of commands. Objects, such as a circle, have properties such
as the radius of the circle and the command that draws it on the computer screen. Classes of
objects can inherit features from other classes of objects. For example, a class defining squares
can inherit features such as right angles from a class defining rectangles. This set of
programming classes simplifies the programmer’s task, resulting in more “reusable” computer
code. Reusable code allows a programmer to use code that has already been designed, written,
and tested. This makes the programmer’s task easier, and it results in more reliable and efficient
programs.
Object-oriented programming began with Simula, a programming language developed from
1962 to 1967. Simula introduced definitive features of OOP, including objects and inheritance.
Graphical user interface (GUI) is a feature that allows the user to select commands using a
mouse. GUIs became a central feature of operating systems such as Macintosh OS and
Windows.
Objects oriented programming languages
The most popular OOP language is C++, VB, JAVA, PASCAL, COBOL, Java, an OOP
language that can run on most types of computers regardless of platform. In some ways Java
represents a simplified version of C++ but adds other features and capabilities as well, and it is
particularly well suited for writing interactive applications to be used on the World Wide Web.
Java
Java is an object-oriented programming language. Java facilitates the distribution of both data
and small applications programs, called applets, over the Internet. Java applications do not
interact directly with a computer’s central processing unit (CPU) or operating system and are
therefore platform independent, meaning that they can run on any type of personal computer,
workstation, or mainframe computer. This cross-platform capability, referred to as “write once,
run everywhere,” has caught the attention of many software developers and users. With Java,
software developers can write applications that will run on otherwise incompatible operating
systems such as Windows, the Macintosh operating system, OS/2, or
UNIX.
To use a Java applet on the World Wide Web (WWW)—the system of software and protocols
that allows multimedia documents to be viewed on the Internet—a user must have a Java-
compatible browser, such as Navigator from Netscape Communications Corporation, Internet
Explorer from Microsoft Corporation, or Hot Java from Sun Microsystems. A browser is a
software program that allows the user to view text, photographs, graphics, illustrations, and
animations on the WWW. Java applets achieve platform independence through the use of a
virtual machine, a special program within the browser software that interprets the byte code—
the code that the applet is written in—for the computer’s CPU. The virtual machine is able to
translate the platform-independent byte code into the platform-dependent machine code that a
specific computer’s CPU understands.
Applications written in Java are usually embedded in Web pages, or documents, and can be run
by clicking on them with a mouse. When an applet is run from a Web page, a copy of the
application program is sent to the user’s computer over the Internet and stored in the computer’s
main memory. The advantage of this method is that once an applet has been downloaded, it can
be interacted with in real time by the user. This is in contrast to other programming languages
used to write Web documents and interactive programs, in which the document or program is
run from the server computer.
Visual Basic
Step in Developing Applications
The visual Basic development environment makes building an application a straight forward
process. There are three primary steps involved in building a visual Basic application.
(2) Draw the user interface by placing controls on the form.
(3) Assign properties to controls.
(4) Attach code to control events (and perhaps write other procedures)
Note:
(2) These same steps are followed whether you are building a very simple application or one
involving many controls and many lines of code.
(3) The event – driven nature of visual Basic allows you to build your application in stages and
test it at each stage. You can build one procedure, or part of a procedure, at a time and try it
until it works as descried. This minimizes errors and gives you, the programmer, confidence as
your application takes shape.
(4) As you progress in your programming skills, always remember to take above sequential
approach to building a visual Basic application Build a little, test a little, modify a little and test
again. You will quickly have a completed application.
- Microsoft VB is the fastest and easiest way to create applications for Microsoft windows.
- The visual part refers to the method used to create the graphical user interface (GUI).
- The Basic part refers to the BASIC Beginners All – Purpose symbolic construction code
Language.
With VB an individual can build simple applications in minutes. VB enables you to write object
oriented programmes or simple programs.
WEEK 15
VB editions:- Learning editions
Professional Edition
Enterprises edition
How windows work
Windows is an GUI operating system. With GUI it easily recognized graphic icons be selected
using the mouse and commands chosen from menus, This is much easier for the user than
typing in the specific lines of code that were required by MS-Dos in order to perform basic
operations. In GUI operating system, more than one application can be open at the same time.
Processor time is shared between computing tasks and this called multitasking.
The Visual Basic environment
The Visual Basic environment is made up of several windows. The initial appearance of the
windows on your screen will depend on the way your environment has been set up.
The tool bar The Visual Basic tool bar functions like the tool bar in any other Microsoft
application. It provides shortcuts for many of the common operating commands. It also shows
you the dimensions and location of the form currently being designed.
The tool box The tool box gives you access to the controls that you use on a form.
A control is an object such as a button, label or grid. Controls are used on forms to
display output or get input. Each control appears as a button in the tool box. If the control you
are looking for is not in the toolbox, select Components from the Project menu. If the tool box
is not displayed on your screen, or if at any time during the exercises you close it, choose
Toolbox from the View menu.
The form designer window
This window is where you design the forms that make up your user interface.
If the form designer window is not displayed on your screen, or if at any time during the
exercises you close it, choose Object from the View menu.
The properties window :
A form, and each control on it, has a set of properties which control its characteristics such as
size, position and color.
The properties window lists all the properties a control has and their value. The default value of
a property can be changed by setting the property value using the properties window when you
design your application or changed by assigning a new value in code while your application is
running. If the properties window is not displayed on your screen, or if at any time during the
exercises you close it, choose Properties Window from the View menu.
A form file contains both the description of the screen layout for the form and the program code
associated with it. If the project explorer window is not displayed on your screen, or if at any
time during the exercises you close it, choose Project Explorer from the View menu.
The form layout window
Move the form in the screen in this window to set the position of your
form when your application is running. You may wish to close the
form layout window to allow more space for the properties window. To
open the window again, select Form Layout Window from the View
menu.
Visual Basic shows you sample code that uses the property or control.
The Help Menu
When you choose the first topic on the Help menu, Microsoft Visual Basic Topics, Visual Basic
displays a help dialog box. This dialog box contains the usual Windows-like help tools. You
can open and close the book icons on the Contents page to read about different Visual Basic
topics. You can search for a particular topic in the index by clicking the Index tab. To locate
every occurrence of a particular help reference word or phrase, you can click the Find tab to
build a comprehensive help database that returns multiple occurrences of topics.
Example :
Get an instant definition for help links with a dotted underline.
Pop-up definition, Hyperlinks Close the help window by clicking the window's Close button.
Opening Application
To open a project, you can do one of two things:
• Click File menu , Open project…
• Click the tool and specify the project you want to open.
Then select Hello project and press Open.
The project window will display the file “Hello.frm” from your project.
Creating Simple application ( Wizard )
You start the application wizard from the New Project dialog box or by choosing New Project
from the File menu. Click the VB Application Wizard icon to start the wizard. This Figure
shows the application wizard's opening screen.
Example
Assuming that you started the application wizard in the previous section, follow these steps to
build your first application:
1- Click the Next button to display the Interface Type dialog box. The wizard can generate one
of three types of user interfaces for the application you're generating:
− MDI (Multiple Document Interface) lets you create a program window that contains
embedded windows called child windows.
− SDI (Single Document Interface) lets you create a program with one or more windows that
exist at the same level (not windows within windows).
− Explorer Style lets you create programs that somewhat take on the Books Online appearance,
with a summary of topics or windows in a left pane and the matching program details in the
right pane.
2- The MDI option should already be selected. If not, click the MDI option.
3- Click Next to display the menu selection dialog box. You can select certain menu options
that will appear on your application's menu bar. By using the dialog box's options, you can help
ensure that your application retains the standard Windows program look and feel. (You can add
your own menu options after the wizard generates the program's initial shell.) For now, leave
these options selected: File, Edit, Window, and Help.
4- Click Next to display the wizard's Resources dialog box. A resource might be a menu, a text
string, a control, a mouse cursor, or just about any item that appears in a program.
5- Click Next, you'll bypass the Internet connectivity dialog box because you don't need to add
such connectivity to your first application shell.
6- Determines which forms appear in your application:
• A splash form is an opening title form that your users see when they first run your application.
• A login form requests the user's ID and password, in case you want to add security features to
your application.
• The options dialog box gives users the ability to modify certain application traits.
• The About box is accessed from most Windows Help menus and provides your program
description and version.
8. Check the About Box but leave the other options unchecked.
9. Click the Next button twice to display the final application wizard dialog box. (You'll bypass
the database access dialog box because you won't be retrieving database data in this first
application.)
10. Click the Finish button. The wizard generates the application before your eyes. You'll see
the wizard generating forms and titles; without the wizard, you would have to perform these
steps yourself. When finished, the application wizard displays a dialog box to tell you that the
application is completed.
11. Click OK to close the final application wizard dialog box. A summary report appears, to
describe the generated program.
Your form will appear like a window from any other Microsoft application.
- Specify the location and the name of the project, then click OK.
Saving your application The last step in this chapter is to save your application so that you can
use it for the exercises later in the book.
Visual Basic first asks you to save the form and then the project file. Remember that each
represents a separate file.
Specify the filename for the form as hello. frm. The file extension “frm” indicates that the file is
a form file.
Always take care to ensure that you save all the files that make up a project.
List of Computer Programming Languages
ADA Augusta ADA Byron (Lady Lovelace) 1979Derived from Pascal, used primarily
by the military.
ALGOL ALGOrithmic Language 1960First structured procedural programming
language, used mainly for solving math problems.
APL A Programming Language 1961Interpreted language using a large set of special
symbols and terse syntax. Used primarily by mathematicians.
BASIC Beginners All-Purpose Symbolic Instruction Code 1965Very popular high-level
programming language, frequently used by beginning programmers.
C Predecessor was Bell Laboratory's 1972 B Programming Language 1972 Compiled,
structured, programming language commonly used in many workplaces because its
programs are easy to transfer between different types of computers.
C++ Advanced version of C. Developed at ATT Bell Labs. 1985C++ is used in numerous
fields, such as accounting and finance systems, and computer-aided design. Supports
objectoriented programming.
COBOL Common Business-Oriented Language 1959 English-like programming
language, emphasizes data structures. Widely used, especially in businesses.
FORTH FOURTH-Generation language (4 GL) 1970Interpreted, structured language,
easily extended. Provides high functionality in limited space.
Fortran FORmula TRANslation 1954Initially designed for scientific and engineering
uses, a highlevel, compiled language now used in many fields. Introduced several
concepts such as variables, conditional statements, and separately compiled subroutines.
HTML HyperText Markup Language 1989Designed for publishing hypertext on the
Internet.
JAVA Sun Microsystems developers drank a lot of coffee when coding for this. 1990
Originally developed for use in set-top boxes, transitioned to the World Wide Web in
1994. LISP LISt Processing 1960A list-oriented programming language, mainly used to
manipulate lists of data. Interpreted language, often used in research, generally
considered the 'standard' language for Artificial Intelligence (AI) projects.
LOGO Derived from Greek logos, meaning word 1968 Programming language often
used with children. Features a simple drawing environment and several higher-level
features from LISP. Primarily educational.
MODULAr Language, designed as secondary phase of Pascal (Niklaus Wirth devised
both) 1980 Language that emphasizes modular programming. High-level language based
on Pascal, characterized by lack of standard functions and procedures.
Pascal Blaise PASCAL, mathematician and inventor of first computing device
1971Compiled, structured language, based on ALGOL. Adds data types and structures
while simplifying syntax. Like C language, it is a standard development language for
microcomputers.
PERL Practical Extraction and Report Language 1988 It is a text-processing language
that looks like a combination of C and several Unix text processing utilities.
PILOT Programmed Inquiry,Language Or Teaching 1969 Programming language used
primarily to create applications for computer-aided instruction. Contains very little
syntax. PL/1 Programming Language One 1964Designed to combine the key features of
Fortran, COBOL, and ALGOL, a complex programming language. Compiled, structured
language capable of error handling and multitasking, used in some academic and research
environments.
SGML Standard Generalized Markup Language 1986 Designed as a meta language, it is
used as an international standard for the description of marked-up electronic text.
SQL Structured Query Language 1986 Designed to be used for creating complex
databases and accessing data in a relational database.
VB Visual Basic 1990 Sometimes called the Rapid Applications Development system, is
used to build applications quickly. XML Extensible Markup Language 1977Used for
creating arbitrarily-structured documents and Web pages; it is commonly associated with
the Internet.
COURSE CODE:- COM 113
COURSE TITLE:- INTRODUCTION TO PROGRAMMING
COURSE OUTLINE
1. Concept of programming (Features of a good program)
2. Concept of Algorithms and flowcharting.
3. Principles of designing algorithms for common programming problem.
4. General modular program design principles.
5. Stages of Program Development/procedure in solving programming problems.
6. Levels of programming language.
7. Concept of debugging and maintaining program.
8. Good programming practices.
9. Concept of object oriented programming