




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Lecture notes for university students
Typology: Lecture notes
1 / 152
This page cannot be seen from the preview
Don't miss anything!





























































































On special offer
BIT 2201: Computer Programming Methodology Page 11
or doing integrals in a non-numerical fashion is relatively limited. The Algorithm can also be represented using Pseudo-code Step 3. Code the Program: The steps in an algorithm, translated into a series of instructions to the computer, comprise the computer program. There are many languages in which computer programs can be coded, each with its own syntax, vocabulary, and special features. Step 4. Debug the Program: Most programs of any length don't work properly the first time they are run and must therefore be debugged." Often, during the debugging phase, errors and ambiguities in the original statement of the problem reveal themselves, calling for basic revisions in the solution algorithm. Step 5. Run the Program: After the program has been fully debugged you run it, possibly using many sets of input data. This step may take anywhere from a few seconds to many hours depending on the complexity of the problem and the speed of the computer. Step 6. Analyze the Results: Often the output from a computer program requires considerable further analysis. In some cases, even though the program worked perfectly, you may find that you solved the “wrong" problem. There is an acronym well known to computer users: GIGO, which stands for “garbage in, garbage out."
1.2.1. Problem Algorithm An Algorithm is a logical sequence of discrete steps that describe a complete solution to a given problem in a finite amount of time independently of the software or hardware of the computer. It is the set of rules that define how a particular problem can be solved in finite number of steps. Algorithms are very essential as they instructs the computer what specific steps it needs to perform to carry out a particular task or solve a problem. Every algorithm should have the following five characteristics: Input, Output, Definiteness, Effectiveness and Termination. An Algorithm has the following properties; It must be precise and unambiguous It must give the correct solution in all cases It must eventually end.
Efficiency and Analysis of the Algorithm The efficiency of an Algorithm means how fast it can produce the correct results for the given problem. The Algorithm efficiency depends upon its time complexity and space complexity. The complexity of an algorithm is a function that provides the running time and space for data, depending on the size provided by us. Two important factors for judging the complexity of an Algorithm are; space complexity which refers to the amount of memory required by the algorithm for it execution and generation of the final output and time Complexity which refers to the amount of computer time required by an algorithm for its execution, which includes both the compile time and run time. The compile time of an algorithm does not depend on the instance characteristics of the algorithm. The run time of an algorithm is estimated by
BIT 2201: Computer Programming Methodology Page 12
determining the number of various operation, such as addition, subtraction, multiplication, division, load and store executed by it.
The analysis of an algorithm determines the amount of resources, such as time and space required by it for its execution. Generally, the algorithms are formulated to work with the inputs or arbitrary length. Algorithm analysis provides theoretical estimates required by an algorithm to solve a problem. The steps of an Algorithm, they can be presented using Flow charts and pseudo-codes.
1.3. Flow Charts A flow chart is a traditional means of showing in diagrammatic form, the sequence of steps to be undertaken in solving a problem. Flowcharts or flow diagrams are important tools in writing a computer program. A flowchart allows you to plan the sequence of steps in a program before writing it. The flowchart serves as a visual representation which many programmers find indispensable in planning any program of at least moderate complexity.
1.3.1. Elements of a Flowchart. A flowchart consists of a set of boxes, the shapes of which indicate specific operations. The separate boxes are connected with arrows to show the sequences in which the various operations are performed. We use these standard symbols:
Shape Name Description Rectangle Process symbol: Used to represent any kind of processing activity. Details are written in the box
Diamond: The decision Symbol: Used where a decision has to be made in selecting the subsequent path to be followed.
Used to show the flow/ path of ma sequence of symbols. Vertical line without arrow head are assumes t flow top to bottom. Horizontal lines without arrow heads are assumed to flow left to right. Every operation box must have at least one incoming or outgoing arrow. Any arrow leaving a decision box must be labeled with the decision result which will cause that path to be followed.
Calculate wages
Is the transaction a credit?
BIT 2201: Computer Programming Methodology Page 14
Pseudo code assumes that programming procedures no matter how complex may be reduced to a combination of controlled sequences, selection, or repetition of basic operations. This gives rise to the control structures found in pseudo-code.
1.5. Program Control Structures Control Structure Pseudo code Flow Chart Sequence: In the absence of selection, or repetition, program statements are executed in the sequence in which the appear in the program
1 st^ Instruction
2 nd^ Instruction
3 rd^ Instruction
Selection Part of decision making and allows alternative actions to be taken according to the conditions that exist at particular stages in program execution
condition THEN actions ELSE actions ENDIF Or
a). Actions b). Actions c). Actions d). Actions ENDCASE
Repetition also called “looping” There are many programming problems in which the same sequence of statements needs to be performed again and again for a definite or indefinite number of times
condition DO Actions ENDWHILE
actions UNTIL condition
No Yes
No
Yes
a b c
No
BIT 2201: Computer Programming Methodology Page 15
1.6. Programming Methods 1.6.1 Top-down and Bottom-up methodology A top-down approach (is also known as step-wise design) is essentially the breaking down of a system to gain insight into its compositional sub-systems. In a top-down approach an overview of the system is formulated, specifying but not detailing any first-level subsystems. Each subsystem is then refined in yet greater detail, sometimes in many additional subsystem levels, until the entire specification is reduced to base elements. A top-down model is often specified with the assistance of "black boxes", these make it easier to manipulate. However, black boxes may fail to elucidate elementary mechanisms or be detailed enough to realistically validate the model.
Top - down-design starts with a description of the overall system and usually consists of a hierarchical structure which contains more detailed descriptions of the system at each lower level. The lower level design details continue until further subdivision is no longer possible, i.e., until the system is described in terms of its "atomic" parts. This method involves a hierarchical or tree-like structure for a system as illustrated by the following diagram:
At the top level, we have that part of the system which deals with the overall system; a kind of system overview or main top-level module.
Top down programming method process
Advantages of the Top-Down Design Method
BIT 2201: Computer Programming Methodology Page 17
1.6.2. Structured programming Method Structured programming is a special type of procedural programming. It provides additional tools to manage the problems that larger programs were creating. Structured programming requires that programmers break program structure into small pieces of code that are easily understood. It also frowns upon the use of global variables and instead uses variables local to each subroutine.
Structured programming was developed during the 1950s after Edgar Dijkstra‟s insightful comments into the harmful nature of the GO TO statement. Dijkstra and others subsequently created a set of acceptable structures in programming that would enable development without GO TO statements. These structures produced programs that were easier to read by humans, easier to debug and easier to test. These structures have become some of the founding principles of modern programming methods.
Although the principles of structured programming have had a profound effect on the programming world, it was not until the 1970s that an actual language was created for teaching structured programming. Pascal was developed especially for this purpose, though it is much derided as a toy language, and appears to have never been used in commercial development. It appears that existing languages such as COBOL and FORTRAN were changed to accommodate Dijkstra‟s structures, or that programming included these structures through more indirect methods.
Later generation languages such as C are fully-fledged structured programming languages; these are from the third generation and procedural, in that they are both written and executed step-by-step. C, in its turn, has formed the foundation for the object-oriented language C++.
The three structures allowed in structured programming are sequence , selection , and iteration. Structures are also thought of in terms of substitution and combination, i.e. structures can be substituted or combined with other structures as long as the result equals a sequential structure. Structured programming also pays attention to design and testing with emphasis on a top-down approach. The top-down approach uses modularity as a means to ensure that the program is both legible and manageable, and also that these modules can be tested as they are developed. This is beneficial as it ensures that all modules should be tested and that bugs can be found in the modules that have most recently been added or altered.
Structured programming also places emphasis on program documentation, which can be in the form of a chart or the structured coding/listing. This documentation allows for subsequent updating of modules, making these modules easier to locate in the program. Modularity also ensures greater opportunity for re- use of modules during development.
BIT 2201: Computer Programming Methodology Page 18
1.7. Programming Aims Good programming principles and practice aim at producing a program with the following characteristics;
1.8. Programming Paradigms A programming paradigm is a pattern of problem solving thought that underlies a particular genre of programs and languages. Four distinct and fundamental programming paradigms have evolved over the last three decades;
1.8.1. Imperative programming; The oldest and the most well-developed, it emerged with the first computers in the 1940s and its elements directly mirror the architectural characteristics of modern computers as well. The program and its variables are stored together and the program contains a series of commands that perform calculations, assign values to variables, retrieve input, produce out, or redirect control elsewhere in the series.
Procedural abstraction is an essential building block for imperative programming as are assignments, loops, sequences, conditional statements and exception handling. Imperative languages also support variable declaration and expressions. The predominant imperative programming languages include Cobol, Fortran, C Ada and Perl.
Commands are normally executed in the order they appear in the memory, while conditional and unconditional branching statements can interrupt this normal flow of execution. Originally the commands included assignment statements, conditional statements and branching statements. The assignments statements provided the ability to dynamically update the value stored in the memory location, while conditional and branching statements could be combined to allow a set of statements to be either skipped or repeatedly executed. The main features of Imperative programming includes;