Anda di halaman 1dari 35

Introduction to programming INTRODUCTION TO PROGRAMMING..................................................................................1 Development of computer programming languages....................................................................1 Introduction .............................................................................................................................1 a) Machine language ................................................................................................................

1 b) Assembly language(Low level language)............................................................................2 c) High Level languages...........................................................................................................4 Features of high level languages...........................................................................................5 A set of rules must be obeyed when writing a source program. These rules which govern the structure of the statements in the language constitute what is called syntax of the language.. 5 Program written in a high level language must be translated into machine code before it can be executed...............................................................................................................................5 Types of high level languages..............................................................................................5 a) Commercial languages.................................................................................................5 b) Scientific languages......................................................................................................6 c) Special Purpose Languages..........................................................................................6 d) Multi-purpose languages:.............................................................................................7 Advantages ..............................................................................................................................8 d) Fourth generation languages (4GLs)..................................................................................9 e) Fifth generation languages ................................................................................................11 Factors to be considered in choosing a programming language.............................................11 Programming Paradigms ...........................................................................................................12 (a) Structured Programming ..................................................................................................12 (b) Unstructured programming...............................................................................................13 (c) Object oriented programming...........................................................................................13 (d) Visual programming........................................................................................................16 PROGRAMMING DEVELOPMENT AND DESIGN..............................................................17 (a) Structured programming design concepts.........................................................................17 (i)Monolithic programming................................................................................................17 (ii) Modular programming................................................................................................18 (iii) Top- down programming.............................................................................................18 (iv) Bottom-up....................................................................................................................20 (b) Program development cycle..............................................................................................22 (c) Program specification ...........................................................................................................23 Characteristics of a good program .............................................................................................24 Programming errors....................................................................................................................25 Design tools................................................................................................................................25 a) Algorithm...........................................................................................................................25 b) Pseudo code........................................................................................................................26 Prepared by lisalitsa 1

Introduction to programming c) Flowcharts..........................................................................................................................28

Prepared by lisalitsa

Introduction to programming

INTRODUCTION TO PROGRAMMING Definitions Computer programming is the aspect of translation of users ideas in to a form that can be understood by the computer by the use of an acceptable tool called computer programming language. A computer program is a set of coded instructions for the computer to obey and process data. Programming language is set of instructions or a tool used for writing computer programs. NB the purpose of computer programming is to solve the users needs i.e. developing instructions for the computer with the aim of solving a particular user problem. This enables the computer to accept and manipulate data and print results automatically. Development of computer programming languages. Introduction Primary function of programming languages is to provide instructions to the computer system so that it can perform a processing activity. Each programming language uses a set of symbols that have special meaning. Each language has its own rules called syntax of the language. The language syntax dictates how the symbols should be combined into statements capable of conveying meaningful instructions to the CPU. Programming languages can be grouped into the following major categories: a) Machine language They are the most basic level of programming languages. In the early stages of computer developments, all program instructions had to be written using binary codes( Os and 1s) , unique to each computer. This type of programming involves the difficult task of writing instructions in the form of strings of binary digits (ones & zeros) or other number systems. In this type of programming language data and instructions were all made in Os and 1s which made it difficult to locate and differentiate. Programmers must have a detailed knowledge of the internal operations of the specific type of CPU they are using. For this reason programming work was left to hardware engineers who had internal knowledge of the computer. They must write long series of detailed instructions to accomplish even simple processing tasks. Programming in machine language requires specifying the storage locations (memory address) for every instruction and item of data used. Execution of instructions was done in the order in

Prepared by lisalitsa

Introduction to programming which they occurred in the main storage. These requirements make machine language programming a difficult and error-prone task. A machine code instruction is made up of two parts: i.) The operation code: ii.) Operand code: Advantages i.) The instructions written using this language are executed very fast because no translation required. ii.) There is efficient use of the C.P.U as this instructions do not occupy large memory space Disadvantages i.) Both data and instructions are expressed in binary digits hence difficult to differentiate ii.) The programs are lengthy and time consuming iii.)The programs are machine dependent hence difficult to be executed by different machine iv.) Programs are error prone. b) Assembly language(Low level language) Assembly languages are the next level of programming languages. They were developed to reduce the difficulties in writing machine languages programs. Programs were written using symbols to represent the instructions (symbolic representation of machine code). Assembly languages are frequently called symbolic languages, because symbols are used to represent operation codes and storage locations. Convenient alphabetic abbreviations called mnemonics ( memory aids) and other symbols are used to represent operation codes, storage locations, and data elements example Sub for subtraction com for computer add for addition e.t.c. the symbolic address are used in place of machine address. Comments can be incorporated in the programs statements to make it easier to be understood by the human programmer. It become possible to include macros and subroutines on programs. A macro is a single instruction written as part of a program and generates many machine code instructions. The use of assembler languages requires language translator programs called assemblers, which allow a It instructs the computer on what to be done It instructs the computer on the address of the memory

location whose contents are to be worked upon.

Prepared by lisalitsa

Introduction to programming computer to convert the instructions of such languages into machine instructions. The process of translating a program is as follows: The assembler translates the symbolic operation codes into machine code and symbolic address into actual machine address. This is done on the basis of one to one mapping. During the process it includes the necessary linkages for closed sudroutines and program macros. The assembler allocates areas in the main memory The assembler then indicates any invalid source language instructions. Produces the object program on disk or tape. It then produces a printed listing of the source code together with comments

NB Assembler languages are still widely used as a method of programming a computer in a machine-oriented language. Most computer manufacturers provide an assembler language that reflects the unique machine language instruction set of a particular line of computers. This feature is particularly desirable to systems programmers, who program system software (as opposed to applications programmers, who program applications software), since it provides them with greater control and flexibility in designing a program for a particular computer. They can then produce more efficient software that is, programs that require a minimum of instructions, storage, and CPU time to perform a specific processing assignment. Advantages a) In an assembly language, alphabetic abbreviations that are easier to remember are used in place of the actual numeric addresses of the data. b) It is readable both by man and machine c) These programs run faster because they are machine specific and closer to machine code. d) It is concise with few instructions and consequently needs smaller storage space for the code. e) It is quite efficient with translation time, execution time and storage requirements. Disadvantages a) Assembly language is machine dependent hence it is not portable and compatible between various computer systems. b) Assembly language is hard to learn compared to high level languages.

Prepared by lisalitsa

Introduction to programming c) Program takes longer to code due to intricate nature of the language. d) Each computer has a different language and retraining programmers presents a problem whenever a company acquires a new computer. e) It makes stand by arrangements in case of breakdown difficult because work cannot be run on a different computer. f) It lacks debugging aids. c) High Level languages High level languages allow problems to be specific in a human and problem oriented manner. The programs of high level languages are very close to human language or the standard notation of mathematics hence it is easy to learn and use. The instructions of High level languages are called Statements and closely resemble human language. Individual highlevel language statements are actually macro instructions; each individual statement generates several machine instructions when translated into machine language by high-level language translator programs called compilers or interpreters. High-level language statements resemble the phrases or mathematical expressions required to express the problem or procedure being programmed. The syntax (vocabulary, punctuation, and grammatical rules) and the semantics (meaning) of such statements do not reflect the internal code of any particular computer. The development of high level languages was intended to overcome the main limitations of the low level languages. The high level languages are therefore machine independent and problem oriented .i.e. they reflect the type of problem being solved rather than the features of the machine. The machine independence of high level languages means that it is possible to make a program that can be run on different machines i.e. program portable. The portability of a program has the following advantages: i.) A user of a program can easily change to newer or bigger computer without the need of re-writing the program again. ii.) Users of different computers can exchange programs. iii.)Users can develop programs and sell them to different organizations. iv.) Portability has enabled the coming up of software companies which develop and maintain programs for companies and individuals.

Prepared by lisalitsa

Introduction to programming Features of high level languages a) They have extensive vocabulary of words and symbols. b) Programs are written in one language and the statements are translated into many machine instructions. This translation is done by a special program called compiler or interpreter. c) Libraries of macros and subroutines can be incorporated. d) Because they are problem oriented the programmer is able to work at least to some extend independent of the machine. A set of rules must be obeyed when writing a source program. These rules which govern the structure of the statements in the language constitute what is called syntax of the language. Program written in a high level language must be translated into machine code before it can be executed. Types of high level languages High level languages can be categorized into the following groups a) Commercial languages These are programming languages that were created to be used in commercial firms .i.e. in business. The most common commercial language is COBOL( COmmon Business Oriented Language. It is the most widely used programming language for business applications. COBOL has an extensive file handling facilities e.g. movement and processing. The language resembles English. .i.e. it incorporates common English terms such as MOVE ADD Another example of commercial language is RPG : (Report Program Generator). A problemoriented language that generates programs that produce reports and perform other data processing tasks. It is a popular language with many business minicomputer users. Example COBOL ( Procedure Division) 3GL PROCEDURE DIVISION. MAIN. PERFORM INITIALIZATION. PERFORM PROCESS-RECORDS UNTIL END-OF-FILE. PERFORM END-OF-JOB. INITIALIZATION

Prepared by lisalitsa

Introduction to programming OPEN INPUT IN-FILE. OPEN OUTPUT OUT-FILE. PERFORM READ-RECORDS. PROCESS-RECORDS. ADD SCORES TO STORE-SCORE. ADD 1 TO STORE-NUMBER. MOVE NAME-IN TO NAME-OUT. MOVE SCORE TO SCORE-OUT. WRITE OUT-REC FROM PRINTER-LINE AFTER ADVANCING 1. PERFORM READ-RECORD. END-OF-JOB. DIVIDE STORE-NUMBER INTO STORE-SCORE GIVING AVERAGE. WRITE OUT-REC FROM AVERAGE-LINE. AFTER ADVANCING 2 LINES. CLOSE IN-FILE. CLOSE OUT-FILE. STOP RUN. READ-RECORD. READ IN-FILE. AT END MOVE Y TO EOF-FLAG.

b) Scientific languages These are programming languages that are used for scientific and engineering purpose e.g. ALGOL : (ALGOrithmic Language). An international algebraic language designed primarily for scientific and mathematical applications. It is widely used in Europe in place of FORTRAN. FORTRAN : (FORmula TRANslation). The oldest of the popular high-level languages. It is still widely used for scientific and engineering applications. These programming languages have extensive mathematical and computation ability. They also have a large library of inbuilt mathematical functions. c) Special Purpose Languages These are programming languages intended to be tailor made language for particular type of problem e.g machine control, simulation and control of experiments e.g o Coral 66 o IRTB(Industrial Real Time Basic ) used for real time applications. o Modular 2it was developed for development of computer systems.

Prepared by lisalitsa

Introduction to programming o Ada : Named after Augusta Ada Byron, considered the worlds first computer programmer. Developed for the U.S. Department of Defense as a standard high-order language to replace COBOL and FORTRAN. d) Multi-purpose languages: These are languages used to solve both business and scientific problems. Examples include the following: APL : ( A Programming Language). A mathematically oriented interactive language. It utilizes a very concise symbolic notation designed for efficient interactive programming of analytical business and scientific applications. BASIC : (Beginners All-Purpose Symbolic Instruction Code). A simple procedure-oriented language widely used for end user programming. C : A mid-level structured language developed as part of the UNIX operating system. It resembles a machine-independent assembler language and is presently popular for system software programming and development of application software packages. Pascal : Named after Blaise Pascal: Developed as a powerful successor to ALGOL, and designed specifically to incorporate structured programming concepts. PL/1 : (Programming Language/1). A general-purpose language developed to combine some of the features of COBOL, FORTRAN,ALGOL, and other languages. It is a flexible language used for business and scientific applications. Example of programs: WHAT ARE THE AVERAGE EXAM SCORES FOR STUDENTS IN MIS 200? BASIC 10 REM AVERAGE EXAM SCORE PROGRAM 20 LET COUNTER = 0 30 LET TOTAL = 0 40 OPEN STUDDATA FOR INPUT AS #1 50 INPUT #1, SCORE 60 WHILE SCORE <> 9999 70 LET COUNTER = COUNTER +1 80 LET TOTAL = TOTAL + SCORE 90 INPUT #1, SCORE 100 WEND 110 LET AVERAGE = TOTAL/COUNTER 120 PRINT AVERAGE SCORE IS , AVERAGE 130 END Pascal PROGRAM averagescore {infile, outfile} VAR score, sum, average, count: real;

Prepared by lisalitsa

Introduction to programming Infile, outfile: text BEGIN Sum: = 0, 0, count, 0, 0; REPEAT Read{infile, score} Sum: = sum + score; Count: = count + 1.0 UNTIL eof {infile} Average: = sum/count; Write{outfile. Average score is average} END Advantages 1) They are problem oriented languages that can be used to solve any problem. 2) They are human readable language, easy to learn with English like statements. 3) They are machine independent languages which can run in many computer i.e. they are portable 4) High-level languages have less rigid rules, forms, and syntaxes, so the potential for error is reduced 5) They encourages mobility among programmers because the languages syntax for most computers is uniform with manuals easy to follow 6) High level languages have programming and debugging aids suitable even for non computer specialists to use when designing programs or systems. 7) Most software widely used, such as applications systems and operating systems sold on the software market are written in high level languages Disadvantages 1) It requires a lot of coding. The programs are lengthy even for smaller problems. 2) 3) High-level language programs are usually less efficient than assembler language programs. High-level language programs require a greater amount of computer time for translation into machine instructions. 4) Sometimes, human words and phrases may have different meanings in different contexts due to many company software developers.

Prepared by lisalitsa

Introduction to programming Compilation and Interpretation In compilation a program called a compiler takes the source program and translates into machine code in interpretation a program called interpreter maintains control over both translation and execution. It takes an input the source program and interleaves translation and execution so that the generated code corresponds to the source program. This means that each statement is translated and executed before the next statement is translated and executed Advantages of compilation over interpretation 1. In compilation the translation is separated from the execution. Therefore no execution time is spent performing translation from source code to object code. 2. In compilation each source language statement in translated into machine language at ounce while in interpretation translation occurs each time the statement is executed therefore there is a translation and execution and translation of the statement for the many times the statement is executed. 3. During optimization the compiler analyzes groups of statement or subprograms in the source programs and improves the efficiency of the target program. Advantages of interpretation 1. Interpretation provides interactive environment where the user can evaluate statement and expression individually this provides immediate feedback. 2. Interpreters usually provide better run-time errors because the source code is available during execution. 3. Interpreters are generally easy to write than compiler. 4. Interpreters can be stored in Read only memory. Assignment Describe the steps involved in translating a program written in high level language to object code using a compiler d) Fourth generation languages (4GLs) This refers to a variety of programming languages that are more non-procedural and conversational than prior languages. They are nonprocedural languages that encourage users Prepared by lisalitsa 9

Introduction to programming and programmers to specify the results they want, while the computer determines the sequence of instructions that will accomplish those results. Users and programmers no longer have to spend a lot of time developing the sequence of instructions the computer must follow to achieve a result. Thus 4GLs have helped to simplify the programming process. Natural languages are 4GLs that are very close to English or other human languages. Research and development activity in artificial intelligence (AI) is developing programming languages that are easy to use as ordinary conversation is ones native tongue. 4GL language contain distinct syntax for controls and data structures 4GL may however represents data structures at a high level of obstruction by eliminating the need to specify algorithms. 4GLs contains the following modules 1) Dialog Editor- creates true windows dialog s with mouse and saves the source code. 2) Form designers Contains powerful forms for designing controls and pages using design assistant. 3) Report Designers- Creates relational reports that include graphics, multiple fonts and complex formatting with ease. 4) Menu Editor - uses the best easiest and the fastest menu editor with integrated drag and drop and when done the menu is saved in source code. 5) Icon Bar Editor Creates icon bars for your application. 6) Macro Recorder uses super object basic language etc. Other features are E-mail, template, encryption and object oriented programming. Examples of 4GLS are Paradox, FoxPro, Access, Dbase, Clipper system c, Sycero, Jacksons pof and Oracle. Advantages and disadvantages There are major differences in the ease of use and technical sophistication of 4GL products. For instance, INTELLECT and CLOUT are natural query languages that impose no rigid grammatical rules, while SXQL and FOCUS requires concise structured statements. However, the ease of use of 4GLs is gained at the expense of some loss in flexibility. It is frequently difficult for an end user to everride some of the prespecified formats or procedures of 4GL. Also the machine language code generated by a program developed by a 4GL is frequently much less efficient (in terms of processing speed and amount of storage capacity needed) than a program written in a language like COBOL. Major failures have been reported in some large transaction processing applications programmed in a 4GL. These applications

Prepared by lisalitsa

10

Introduction to programming were unable to provide reasonable response times when faced with a large amount of realtime transaction processing and end user inquires. However 4GLs have shown great success in end user and departmental applications which do not have a high volume of transaction processing. e) Fifth generation languages Some people use 5GLs to describe languages using artificial intelligence techniques to accomplish results for users. Some also refer to Tool kits ( appeared in mid 1998) as 5GLs. They combine rules-based code generation, component visual programming techniques, reuse management and other advances. 5th GL LISP, PROLOG and Object oriented languages, were for use in the 5th generation super computers initially by the Japanese. These languages are designed to generate program code with fewer instructions than the prior languages. Programs and applications based on these languages can be developed in much shorter time. The programs are concerned with what the result will be rather than how it will be arrived at. Simple features of this language can be employed by end user. The languages are designed as productive tools for professional programmers.

Factors to be considered in choosing a programming language 1. Are programmers familiar with the language. Programmers experience is considered. Best known frequently used is usually selected. 2. Whats the nature of the application or type of application being developed. 3. Easy of learning & use of the language. 4. Features or facilities available in a programming language. 5. Does the language support structured programming concepts? Cobol, PL/1, ALGOL & Pascal are better able to support structured programming than most existing Basic or Fortran dialects. 6. Is satisfactory translating software available? A language is a humanly convenient set of rules, conventions, and representations used to convey information from human to machine. A good language & efficient translator yields satisfactory results. 7. Language used in other programs within the organization.

Prepared by lisalitsa

11

Introduction to programming 8. How often will the application be processed? The faster the possible programming time is (with high-level or 4Gl), the more economical the approach. An assembly language program written by a clever programmer usually has a shorter production run time and takes less storage space than a program of same application written in high-level language. 9. Will the program be changed frequently? The ease of program modification varies with different languages. High-level languages are easier to modify than assembly language. 10. Is hardware change anticipated during the life of the application? Conversion of standardized high-level languages programs is easier and faster. Machine-oriented programs may have to be completely rewritten. 11. Is the language being supported, improved and updated? Are resources available for support, improvement and updating the language. Programming Paradigms A programming paradigm is a programming technique, way of thinking about programming or view of a program. It is a fundamental style of programming regarding how solutions to problems are to be formulated in a programming language. (Compare with a methodology, which is a style of solving specific software engineering problems).A programming paradigm provides (and determines) the view that the programmer has of the execution of the program. (a) Structured Programming A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having a single entry and a single exit point, and in which control is passed downward through the structure without unconditional branches to higher levels of the structure. Three types of control flow are used: sequential, test, and iteration. structured design entails developing a program as a series of independent sections for the purpose of performing one task .Structured programming involves the use of facilities such as IF, THEN, ELSE REPEAT,UNTIL, WHILE-DO , for DO modules, and functions. Statements. This approach enables program errors to be localized and assist in the maintenance of each section Advantages of Structured Programming 1). Easy to write: Modular design increases the programmer's productivity by allowing them to look at the big picture first and focus on details later. Several Programmers can work on a single, large program, each working on a different

Prepared by lisalitsa

12

Introduction to programming module Studies show structured programs take less time to write than standard programs. Procedures written for one program can be reused in other programs requiring the same task. A procedure that can be used in many programs is said to be reusable 2). Easy to debug Since each procedure is specialized to perform just one task, a procedure can be checked individually. Older unstructured programs consist of a sequence of instructions that are not grouped for specific tasks. The logic of such programs is cluttered with details and therefore difficult to follow. 3). Easy to Understand The relationship between the procedures shows the modular design of the program. Meaningful procedure names and clear documentation identify the task performed by each module Meaningful variable names help the programmer identify the purpose of each variable. 4). Easy to Change Since a correctly written structured program is self-documenting, it can be easily understood by another programmer. (b) Unstructured programming Unstructured programming is a programming paradigm where all code is contained in a single continuous block. This is contrary to structured programming, where programatic tasks can be split in to smaller sections known as functions or subroutines, which can be called whenever they are required. Unstructured programming languages have to rely on execution flow statements such as Goto, used in many languages to jump to a specified section of code. Unstructured source code is notoriously difficult to read and debug, and so is discouraged in programming languages that support any kind of structure. However, unstructured programming is still needed in some scripting languages such as MS-DOS batch files, and for programming CPU intensive algorithms in C or Assembly language, where processing speed is more important than readability.

(c) Object oriented programming

Prepared by lisalitsa

13

Introduction to programming A type of programming in which programmers define not only the data type of a data structure, but also the types of operations (functions) that can be applied to the data structure. In this way, the data structure becomes an object that includes both data and functions. In addition, programmers can create relationships between one object and another. For example, objects can inherit characteristics from other objects. It can also be defined as a programming paradigm that uses "objects" data structures consisting of data fields and methods and their interactions to design applications and computer programs. Programming techniques may include features such as information hiding, data abstraction, encapsulation, modularity, polymorphism, and inheritance. It was not commonly used in mainstream software application development until the early 1990s. Many modern programming languages now support OOP. Fundamental concepts and features i). Objects Objects are the basic run-time entities in an object-oriented system. Programming problem is analyzed in terms of objects and nature of communication between them. When a program is executed, objects interact with each other by sending messages. Different objects can also interact with each other without knowing the details of their data or code. ii). Classes A class is a collection of objects of similar type. Once a class is defined, any number of objects can be created which belong to that class. iii).Data Abstraction and Encapsulation Abstraction refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes. Storing data and functions in a single unit (class) is encapsulation. Data cannot be accessible to the outside world and only those functions which are stored in the class can access it. iv). Inheritance Inheritance is the process by which objects can acquire the properties of objects of other class. In OOP, inheritance provides reusability, like, adding additional features to an existing class without modifying it. This is achieved by deriving a new class from the existing one. The new class will have combined features of both the classes. v). Polymorphism

Prepared by lisalitsa

14

Introduction to programming Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends on the data types used in the operation. Polymorphism is of extensively used in implementing Inheritance. Advantages OOP

Object-Oriented Programming has the following advantages over conventional approaches: i). Simplicity: software objects model real world objects, so the complexity is reduced and the program structure is very clear; ii). Modularity: each object forms a separate entity whose internal workings are decoupled from other parts of the system; iii).Modifiability: it is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods; iv). Extensibility: adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones; v). Maintainability: objects can be maintained separately, making locating and fixing problems easier; vi). Re-usability: objects can be reused in different programs. vii). OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces. Assignment List four disadvantages of OOP Examples

Languages called "pure" OO languages, because everything in them is treated consistently as an object, from primitives such as characters and punctuation, all the way up to whole classes, prototypes, blocks, modules, etc. They were designed specifically to facilitate, even enforce, OO methods. Examples: Smalltalk, Eiffel, Ruby, JADE

Languages designed mainly for OO programming, but with some procedural elements. Examples: C++, Java, Python. Languages that are historically procedural languages, but have been extended with some OO features. Examples: Fortran 2003, Perl, COBOL 2002.

Prepared by lisalitsa

15

Introduction to programming

Languages with most of the features of objects (classes, methods, inheritance, reusability), but in a distinctly original form. Examples: Oberon (Oberon-1 or Oberon-2). Languages with abstract data type support, but not all features of object-orientation, sometimes called object-based languages. Examples: Modula-2 (with excellent encapsulation and information hiding), Pliant, CLU.

(d) Visual programming Visual programming is structured object-oriented programming in GUI, based on ready made objects. It comprises a collection of procedures that responds to other procedures that performs specific tasks such as event procedures and general procedures. It is also event driven programming in that all the activities in the program are triggered by one event or another, such as click and key press. Each object has its own event handling procedures. An event procedure executes when an event associated with the application occurs whereas a general procedure contain code which performs common functions and can be used by other procedures. Procedures can be either public (used throughout the program) or private (limited to the procedures where it is defined). A visual programming language (VPL) is also any programming language that lets users create programs by manipulating program elements graphically rather than by specifying them textually. A VPL allows programming with visual expressions, spatial arrangements of text and graphic symbols used either as elements of syntax or secondary notation. Many VPLs are based on the idea of "boxes and arrows," where boxes or other screen objects are treated as entities, connected by arrows, lines or arcs which represent relations. Visual programming can also be described as the creation of a computer program by utilizing pictorial elements. Traditionally, a program is a sequence of text statements used to achieve a certain result or solve some problem. Programming languages often have particular ways of representing the work to be done thus leading to complexity. Visual programming attempts to make the creation of programs simpler. Visual Programming Language (VPL) is also an application development environment designed on a graphical dataflow-based programming model. Rather than series of imperative commands sequentially executed, a dataflow program is more like a series of workers on an assembly line, who do their assigned task as the materials arrive. As a result VPL is well suited to programming a variety of concurrent or distributed processing scenarios.

Prepared by lisalitsa

16

Introduction to programming

VPL is targeted for beginner programmers with a basic understanding of concepts like variables and logic. However, VPL is not limited to novices. The programming language may appeal to more advanced programmers for rapid prototyping or code development. As a result, VPL may appeal to a wide audience of users including students, enthusiasts/hobbyists, as well as possibly web developers and professional programmers. According to http://ksi.cpsc.ucalgary.ca Advantages and disadvantages of Visual Programming are Advantages of Visual Programming i) People in general prefer pictures over words ii) iii) iv) v) vi) vii) Pictures are more powerful than words as a means of communication, because they can convey more meaning in a more concise unit of expression Pictures do not have the language barriers that natural languages have Falling cost of graphics-related hardware and software have made it feasible to use pictures as a means of communication Human visual system and human visual information processing is clearly optimized for multi-dimensional data Visual style of programming can be easier to understand and generate for humans People are much better at dealing with specific examples than with abstract ideas

Disadvantages of Visual Programming i) Difficulty with large programs and large data, to much information to fit on the screen ii) Lack of functionality iii) Lack of efficiency iv) Unstructured programs v) Static representation of programs that are hard to understand Assignment Research and make notes on Internet based programming. PROGRAMMING DEVELOPMENT AND DESIGN (a) Structured programming design concepts (i)Monolithic programming Monolithic Programming indicates the program which contain a single function for the large program. It is always fight with modular programming to placed the identity in programming world. Modular programming help the programmer to divide the whole program into different Prepared by lisalitsa 17

Introduction to programming modules and each module is separately developed and tested. Then the linker will link all these modules to form the complete program. On the other hand monolithic programming will not divide the program and it is a single thread of execution. When the program size increases it leads inconvenience and difficult to maintain. Disadvantages of monolithic programming: 1. Difficult to check error on large programs. 2. Difficult to maintain. 3. Code can be specific to a particular problem. i.e. it can not be reused. (ii) Modular programming Modular programming is subdividing your program into separate subprograms such as functions and subroutines. Each subprogram represents a major uniquely identifiable component of a program called a module which can be written separately almost identifiable of others but are a coordinated basis. This approach facilities the debugging (detecting errors) and maintenance of a program. It also enables a large program to be developed in a shorter time by a team of programmers thus making the work load lighter. The modules can be used in house keeping input, processing and output functions. In good programming practical program modules form a group of sources code which translates into subprograms such as subroutines procedures or functions? Modular programming has the following advantages. 1) A program can be developed into separate sub programs called modules 2) It facilitates the development a programs by terms of programmers. 3) System modules can be written and tested independently 4) It makes debugging of programs a lot easier because errors are localized in modules. 5) Programs can be developed in a shorter time. 6) Modules ounce compiled can be imported and exported to other programs written in the same language or different languages. (iii) Top- down programming Top-down programming is the opposite of bottom-up programming. It refers to a style of programming where an application is constructed starting with a high-level description of what it is supposed to do, and breaking the specification down into simpler and simpler pieces, until Prepared by lisalitsa 18

Introduction to programming a level has been reached that corresponds to the primitives of the programming language to be used. It can also be defined as Also called "stepwise refinement," it is a software development technique that imposes a hierarchical structure on the design of the program. It starts out by defining the solution at the highest level of functionality and breaking it down further and further into small routines that can be easily documented and coded. i.e. you write first the main function, that calls stubs, then you subdivide these stubs in smaller stubs until a real work has to be done, that you code in the final files. Practicing top-down programming has several advantages:

Separating the low level work from the higher level abstractions leads to a modular design. Modular design means development can be self contained. Having "skeleton" code illustrates clearly how low level modules integrate. Fewer operations errors (to reduce errors, because each module has to be processed separately, so programmers get large amount of time for processing). Much less time consuming (each programmer is only involved in a part of the big project). Very optimized way of processing (each programmer has to apply their own knowledge and experience to their parts (modules), so the project will become an optimized one). Easy to maintain (if an error occurs in the output, it is easy to identify the errors generated from which module of the entire program).

Disadvantages of top-down programming Top-down programming complicates testing. Noting executable exists until the very late in the development, so in order to test what has been done so far, one must write stubs. Furthermore, top-down programming tends to generate modules that are very specific to the application that is being written, thus not very reusable. But the main disadvantage of top-down programming is that all decisions made from the start of the project depend directly or indirectly on the high-level specification of the application. It is a well-known fact that this specification tends to change over time. When that happens, there is a great risk that large parts of the application need to be rewritten.

Prepared by lisalitsa

19

Introduction to programming How does top-down programming work? Top-down programming tends to generate modules that are based on functionality, usually in the form of functions or procedures. Typically, the high-level specification of the system states functionality. This high-level description is then refined to be a sequence or a loop of simpler functions or procedures, that are then themselves refined, etc. In this style of programming, there is a great risk that implementation details of many data structures have to be shared between modules, and thus globally exposed. This in turn makes it tempting for other modules to use these implementation details, thereby creating unwanted dependencies between different parts of the application.

Controlling

(main) program

Subprogram

Subprogram

Subprogram

Subprogram

Subprogram

(iv) Bottom-up Bottom-up programming is the opposite of top-down programming. It refers to a style of programming where an application is constructed starting with existing primitives of the programming language, and constructing gradually more and more complicated features, until the all of the application has been written i.e. you write (or gather) small components that do basic actions that are required to do the full program work. Then you assemble them by custom code, then assemble these parts to write the main method. Advantages of bottom-up programming This brings several advantages:

Prepared by lisalitsa

20

Introduction to programming 1. By making the language do more of the work, bottom-up design yields programs which are smaller and more agile. A shorter program doesn't have to be divided into so many components, and fewer components means programs which are easier to read or modify. Fewer components also means fewer connections between components, and thus less chance for errors there. As industrial designers strive to reduce the number of moving parts in a machine, experienced Lisp programmers use bottom-up design to reduce the size and complexity of their programs. 2. Bottom-up design promotes code re-use. When you write two or more programs, many of the utilities you wrote for the first program will also be useful in the succeeding ones. Once you've acquired a large substrate of utilities, writing a new program can take only a fraction of the effort it would require if you had to start with raw Lisp. 3. Bottom-up design makes programs easier to read. An instance of this type of abstraction asks the reader to understand a general-purpose operator; an instance of functional abstraction asks the reader to understand a special-purpose subroutine. 4. Because it causes you always to be on the lookout for patterns in your code, working bottom-up helps to clarify your ideas about the design of your program. If two distant components of a program are similar in form, you'll be led to notice the similarity and perhaps to redesign the program in a simpler way. Disadvantages of Bottom Up Programming
1. 2.

Components may be coded without having a clear idea of how they link to other None of the system can be tested as a whole until later in a project often causing complications near the end of the project Subprogram Subprogram Subprogram Subprogram

Subprogram

Main program

Prepared by lisalitsa

21

Introduction to programming (b) Program development cycle 1. Problem identification. The task to be performed must be identified fully and clearly, taking into account all the details necessary. Understanding the problem facilitates definition of the users requirement and problem planning. 2. Problem design. These involve identifying the task and arrange them in order to solve the problem. A design tool is chosen to describe the problem logic e.g. a logarithm, flowchart, decision table and tree. The task can be divided into a number of small operations so that each can be implemented by a segment of the program. 3. Program coding/writing. Coding is the process of reducing or converting pseudo-code, a logarithmic instruction, decision tables, flowcharts etc to a series of program statements in a given computer language. These languages to be used depends on the nature of the program. 4. Compile and debug the program.compiling is the process of converting the source program in to objects using a translator such as a compiler or interpreter. Debugging is a process of identifying and removal of errors in a program. This involves the use of debugging aids such as a debugger or tracer. The machine code are precise primitive operation which can only be understood and implemented by a machine. 5. Testing the program. Testing is the process of ensuring that the program is correct or serves the users interest or expectation. Testing is where a program is loaded or submitted with test data that is artificial data and job control statements. Test data should be created by the programmer. This involves reading input, processing the data and outputting the results. Importance of testing The trend towards a high degree of integration of system within an organization requires that each new system, or program, implemented successfully, be well tested. The increased dependency upon computer generated information by all levels within organizational activities, relates organization decision making and problem solving. The increased usage and familiarity within computer based system has resulted in higher expectations by organizational users of the system or Programs

Prepared by lisalitsa

22

Introduction to programming 6 Program documentation. Documentation is the creation and maintenance of significant information about program, system etc in a clear and concise manner or information itself. The purpose of documentation is to build a complete description of the problem you are trying to solve, the method of solving the problem and the computer program which incorporates that program. Documentation also represents a functional description of a program and it serve as a set of specifications to the programmer. It is also used to in program validation. Documentation should take place continuously throughout the programming process there are two categories of documentation internal and external Internal- is technical in nature and is contained in the program itself. It is addressed to the programmer who might be faced with the task of modifying the program at some stage. It contains comments or remarks to make the program easier to read and follow the program logic, especially for non-programmers. External- is a separate documentation with the various contents such as program specification, program listing etc for various users management and other interested parties. 7 Implementation stage. Implantation is the process of putting in place the new written program. It involves the training of users of the program and installation to the users computer. (c) Program specification Program specification is a detailed specification for each program defining the defining the problem of each program designed to each programmer to write program specification involves the following four major steps. (i) Problem definition: To be able to define the problem it is important to understand the problem to enable good planning of the solution. This means the programmer shall establish what program is required to do. (ii) Input: after defining the problem the programmer is required to to decide on the input and data structure to used in solving the problem. It also important to decide on the data format and method of data entry depending on the program requirements. (iii) Processing: The process in the program depend on the information or output requirements and type of data input. Success of processing will entirely be on the program effectiveness. If the data is wrong and program is not effective then the desired output cant be achieved.

Prepared by lisalitsa

23

Introduction to programming (iv) Output: Output format should be specified in program structures and depends entirely on input format and processing. Program specification has the following benefits (i) (ii) (iii) (iv) (v) It provides an opportunity for the analyst to rethink the system design at a detailed low-level. It provides a vehicle for communicating with programmer. It provides a permanent record which describes or documents the activities performed by each program in the system. It serves has a guide for program testing after completion. It provides a guide to the programmers.

Characteristics of a good program a) Integrity: This refers to the accuracy of calculation. It should be clear that all the other program enhancement will be meaningless if the calculation are not carried out correctly b) Clarity: This refers to overall readability of the program with particular logic. If a program is clearly written it shall be possible to any programmer to follow the program logic without an due effort. c) Simplicity: The clarity and accuracy of a program usually enhance by keeping things as simple as possible and consistent with overall problem objectives. d) Efficiency: Its is concerned with execution speed and effectiveness memory utilization. This is important but should not be obtained at expense of clarity and simplicity. e) Modularity: Most large programs can be broken down into a series of identifiable sub-tasks. These sub-tasks will be implanted as separate program modules. f) Generality: The programmer is suppose to make the program as general as possible within measurable limits e.g. you may design a program to read in the values of a parameter other than placing fixed values into the program

Prepared by lisalitsa

24

Introduction to programming Programming errors The following are errors that can be found within a program: a) Syntax error: This are errors encountered when the source program is being compiled from the higher level language to machine code (object code) the compiler or interpreter generates error diagnostic indicating the type of errors in the program. These arrors must be corrected before the further execution of the program is done. Interactive compilers produce errors after every statement which has such errors whereas batch compilers list the errors at the completion of the compilation process. b) Logic errors They are also known as program errors. They represent errors in the logic of the program. They are not signaled by the compiler but the user will have to assess the output of the program in order to determine whether it meets the expectation of the programmer. It is also important to check performance of the program especially where conditions are involed and repetition. When the programmer dry runs the program or assesses the output then this kind of error can be noted and corrected. c) Run time errors These are errors which occur during the execution of the program. They are directed during the validation and verification of the input. For instance the filed of type character is accepted in the field of type numeric or an attempt to divide by zero. Run time errors occur if the data input is not within the boundary of the range. Design tools a) Algorithm A major step in problem solution involves determining how to convert input into desired output, once the program has been designed has been designed. A list of instruction specifying an ordered sequence of operation that produces the answer to a given type problem and terminated after a finite number of steps is called algorithm. Or we can describe an algorithm as a complete set of instructions that constitutes a solution to problem. Algorithms

Prepared by lisalitsa

25

Introduction to programming will vary in number of steps, logical sequence and formula if any is used to solve the problem.. as a rule of thumb an algorithm must have the following properties. i). ii). iii). iv). Example 1 Write an algorithm to solve the following problem (T-32)5/9=Tc Solution 1) Subtract 32 from T 2) Multiply the difference above by 5 3) Divide the product in 2 above by 9 Consists of a finite number of steps that terminate Consists of precise and unambiguous instructions. Be general enough, that is flexible to be applied to any problem Produce results

Example 2 Write an algorithm for calculating the area of a triangle given the height and the base 1) Start 2) Multiply the base and the height 3) Devide the product by 2 4) Output the area. 5) Stop Example 3 Write algorithm that could be used calculate the average mark for ten students 1) Start 2) Add the marks of the ten students to find the total marks 3) Divide the total marks by ten 4) Stop

b) Pseudo code

Prepared by lisalitsa

26

Introduction to programming Pseudo code is a narrative description of the steps involved in the executing a computer program in the order in which they will be executed. It is written in form of an outline with indent showing the basic programming mechanisms of structural programming. Example 1 Write a pseudo code to solve the following problem (T-32)5/9=Tc Solution Program (input, output) Declare variables Input the temperature (T) Calculate TC(TC=(T-32)*(5/9)) Output the TC End Example 2 Write a pseudo code for calculating the area of a triangle given the height and the base Program(input, output) Declare variables Base and Height Begin/start Read/input base and height Calculate area (AREA= *Base* Height) Write/output Area End/stop Example 3 Write a pseudo code that could be used calculate the average mark for ten students Program(input, output) Declare variables totalmarks, marks, average, counter Begin/start Initialize totalmark and counter to zero (counter=0, totalmark=0) Repeat Read/input mark Add mark to totalmark(totalmark=totalmark+mark) Increase counter by one (counter=counter+1) Until counter = 10 Prepared by lisalitsa 27

Introduction to programming Calculate the average(average=totalmark/10) Output the totalamark Output average End/stop c) Flowcharts Flowchart is a graphical representation of a solution to problem which symbols are used to represent operations, data flow and decision. It also shows the relationship mong statements in the program. Its purpose is to show the information flow and tools used in problem solving. Flowchart symbols 1) input-output symbol The input-output symbol is a parallelogram which specifies the particular input/output operation. It is used to enter data into the computer or to print information. 2) Processing symbol

The processing symbol is a general operation symbol encompassing any type of data manipulation or calculation. Operation such as move, multiply, add, subtract, sort, merg manual operation etc 3) Direction symbol An arrow represents the flow direction of execution of defined operation. A flow direction therefore specifies the net single operation, once the current operation has been performed.

4) Decision Symbol The decision symbol is a special diamond symbol that is used to indicate a point in a program where more than one direction of flow may occur after a processing operation.. The

Prepared by lisalitsa

28

Introduction to programming occurrence of two or more paths is called branching and the decision block will specify which of the paths will be taken, once the processing activity is completed

5) Terminator Symbol The terminator symbol represents any symbol at which a program originates or terminates. It specifies the start and stop of execution.

6) Connector The connector is an oval symbol used to represent an exit from one part of the program or an entry into another point. They are connectors are: i). Off page connector Transfers a activity to another page

ii).

On page connector Transfers control/activities on the same page.

7) Manual operation symbol

This symbol represents a work done manually without use of machine or computer. Assignment Prepared by lisalitsa 29

Introduction to programming Research on other symbols used for flowchart Factors to consider when drawing flowcharts a) Spacing Flowchart may be drawn any standard page size, if required leave a adequate margins and gutters on all sides of the page for binding. Leave adequate space between flowchart symbols. b) Labeling Flowchart should be labeled at the top or bottom with the name of the system, system or program to which it relates. c) Sequence of symbols The normal flow of operations is from top to bottom and from left to right. Whenever possible draw the direction of logic or data flow from top to bottom and from left to right, however, the directions may be altered by inserting decision symbols. d) Accuracy The symbols should be drawn to scale as accurately as possible. Although symbols may vary in size, their shape should remain proportional. Use a template. e) Neatness The flowchart should be neatly drawn to convey a meaning. A flowchart over crowded with to many lines becomes difficult to flow. Advantages a) They require less writing b) They are easy to follow onc understand the symbols. c) They are independent of any language. d) They are applicable in may areas e) They are easy to modify Disadvantages a) They are time consuming b) They can be quite messy in complicated systems. c) They take more paper for drawing than an algorithm for the same problem. d) They are no obvious mechanism for progressing from one level of design to the next e.g from system flowchart to program flowchart.. e) They are not easy to read like algorithm f) They call for expertise to draw systems accurately even with the help of a template.

Prepared by lisalitsa

30

Introduction to programming g) They do not contain enough detailed information and therefore it becomes difficult for beginners to understand. Uses of flowcharts (i). Communication tool A flowchart is convenient tool for communication ideas and concepts among engineers, managers, it personnel e.t.c. It provides a concrete visual medium for describing complex plans or problems (ii). Planning tool The flowchart is a flexible tool when planning and designing a new system. It enables designers to draw concisely on paper, the essence of a system and its flow lines. It helps to visualize the relationship and movements that will exists within a system, while it is still in the planning stages. (iii). Define roles A flowchart spells out in pictorial form the role played by the personnel, work stations and process in a system. It points out where the data and forms are generated, the end results or reports are produced and the people, producers and places related to the process. (iv). Demonstrate relationships A flowchart points out relationship that may not be readily obvious from a verbal description. It shows how parts of system relate to each other as well as specifying the sequence of data flow. (v). Document system A flowchart records graphically, formally and permanently the important elements of a system. This facilitates making changes, revision and modifications at a later date. It enhances those unfamiliar with a given system to grasp its major elements easily and quickly. (vi). (vii). (viii). Training tool It is a good tool for training new staff on existing systems and programming standards. Design tool It it used in designing programs and systems Provide an overview of the system. A flowchart gives a birds eye view of the major steps and processes in a system..

Prepared by lisalitsa

31

Introduction to programming Examples of flowcharts Flowchart to add three numbers Start Declare variables Num1 num2 num3 Input num1, num2, & num3 Flowchart to add two numbers Start Declare variables A And B Input A and B

Average=(num1+num2+num3)/3 Output average

Ans = A + B

Output Ans

Stop

Stop

Prepared by lisalitsa

32

Introduction to programming

Flowchart to add ten numbers Start

Flowchart to determine bigger number between two numbers Start

Declare variables Num, counter & sum Initialize sum= o and counter = 1

Declare variables A And B

Input A and B

Input num

Sum=sum + num Counter = counter +1

If A > B

Counter =10

Output A Y

Output B N

Y Output sum Stop

Stop

Prepared by lisalitsa

33

Anda mungkin juga menyukai