590 likes | 724 Views
Principles & Techniques of Programming. Compiled by : S. Agarwal Lecturer & Systems Incharge St. Xavier’s Computer Centre St. Xavier’s College, Kolkata. Program Definition
E N D
Principles & Techniques of Programming Compiled by : S. Agarwal Lecturer & Systems Incharge St. Xavier’s Computer Centre St. Xavier’s College, Kolkata. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Program Definition A program is a collection of instructions that tell the computer what to do. A program is called software, hence, program, software and instructions are synonymous. A program is written in a programming language and is converted into the computer’s machine language by software called assemblers and compilers. They are just like translators. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
A program is made up of • Instruction • Buffers • Constants • Instruction are the directions that the computer will follow and a particular sequence of instructions is called the program’s logic. • Buffers are reserved spaces in the computer memory that will accept and hold the data while it is being processed. • Constants are fixed values within the program that are used for comparing. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Characteristics of good Programe • Programming style consists of three important qualities: • Readability • Portability • Maintainability Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Readability You should write the source code or the program in high level language that it is readable to you and to others. This includes aesthetic formatting, meaningful variables names and consistency within and across the source files. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Portability Write the code using high level language so that it is easy to transfer the program to other machines as well. If possible avoid nonstandard features and also use the standard library runtime routines rather than writing your own and thus save time. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Maintainability As you write the program, think about how you might want to change or extend it in future. For example, put data structure definitions in header files where changes will automatically broadcast to all source files that include the header file. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Poor programming style Good programming style Sharing data among functions by making the data global Sharing data by passing arguments Creating numerous special-purpose functions Creating fewer functions Using GOTO statements Using structured control flow statements Writing redundant code sequentially Using functions for code sequences that are used repeatedly Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Introduction to flowcharts A flowchart is a graphical representation of the sequence of operations in an information system or program. Program flowcharts show the sequence of instructions in a single program or subroutine. Since a flowchart shows the flow of operations in pictorial form, any error in the logic of the procedure can be detected easily. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Flowchart Symbols Processing A processing symbol is used in a flowchart to represent arithmetic and data movement instructions. Flow lines Flow lines with arrowheads are used to indicate the flow of operation, that is, the exact sequence in which the instructions are to be executed. Decision The decision symbol is used in a flowchart to indicate a point at which a decision has to be made and a branch to one of two or more alternative points is possible. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Terminal (begin / end) This symbol is used to start or end a flowchart. Input / Output This symbol is used to denote any kind of input or output. Connector If a flowchart becomes very long, the flow lines start crisscrossing at many places that causes confusion and reduces the clarity of the flowchart. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Rules for Writing Flowcharts • First formulate the main line of logic, then incorporate the details in the flowchart. • Maintain a consistent level of detail for a given flowchart. • Do not give every detail on the flowchart. A reader who is interested in greater details can refer to the program itself. • Words in the flowchart symbols should be common statements and easy to understand. • Be consistent in using names and variables in the flowchart. • Go from left to right and top to bottom in constructing the flowchart. • Keep the flowchart as simple as possible. The crossing of flow lines should be avoided as far as possible. • If a new flowcharting page is needed, it is recommended that the flowchart be broken at an input or output point. Moreover, properly labeled connectors should be used to link the portions of the flowchart on different pages. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Advantages of Flowcharts Conveys Better Meaning Since a flowchart is a pictorial representation of a program, it is easier for a programmer to understand and explain the logic of the program to some other programmer. Analyses the Problem Effectively A macro flowchart that charts the main line of logic of a software system becomes a system model that can be broken down into detailed parts for study and further analysis of the system. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Effective joining the part of a System A group of programmers are normally associated with the design of large software systems. Each programmer is responsible for designing only a part of the entire system. So initially, if each programmer draws a flowchart for his part of design, the flowcharts of all the programmers can be placed together to visualize the overall system design. Any problem in linking the various parts of the system can be easily detected at this stage and the design can be accordingly modified. Flowcharts can thus be used as working models in the design of new programs and software systems. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Efficient Coding Once a flowchart is ready, programmers find it very easy to write the concerned program because the flowchart acts as a roadmap for them. It guides them in proceeding from the starting point of the program to the final point ensuring that no steps are omitted. The ultimate result is an error free program developed at a faster rate. Systematic Debugging Even after taking full care in program design, some errors may remain in the program because the designer might have thought about a particular case. These errors are detected only when we start executing the program on a computer. Such type of program errors are called bugs and the process of removing these errors is known as debugging. A flowchart is very helpful in detecting, locating and removing mistakes (bugs) in a program in a systematic manner. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Systematic Testing Testing is the process of confirming whether a program will successfully do all the jobs for which it has been designed under the specified constraints. For testing a program, different sets of data are fed as input to that program to test the different paths in the program logic. Flow charts help in selecting tests data for confirming the proper working of the logic. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Limitations of Flowcharts Takes More Time to Draw Flowcharts are very time consuming and laborious to draw with proper symbols and spacing, especially for large complex programs. Difficult to Make Changes Owing to the symbol-string nature of flowcharting, any changes or modifications in the program logic will usually require a completely new flowchart. Redrawing a flowchart is tedious and many companies either do not change them or produce the flow chart by using a special package designed. Non-standardization There are no standards determining the amount of detail that should be included in a flowchart. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Concepts of DBMS A database collectively refers to one or more files that are maintained, accessed and manipulated by one or more users. A database management system (DBMS) is a set of software programs that control the relationship, storage and retrieval of data (fields, records and files) in a database. It enables individuals to define, manipulate and extract information from database. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
What is Database Management System (DBMS)? • A database system involves four major components: • Data (facts, figures & statistics) • Hardware (circuits, memory, devices etc.) • Software (application programs) • Users (programmers, end-users & DBA) Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Aim of Database Management System The main aim behind a database management system is to handle data collectively. This enables us to access information easily, quickly, economically and accurately. Various drawbacks of the conventional data file processing environment are discussed in the next few slides. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Data Redundancy Data elements like employee_name, employee_code, address, etc. are used in various applications. Since data is required by multiple applications, it is stored in different data files resulting in repetition of data. This may lead to inconsistency across different files. In DBMS, data is stored only at one place practically eliminating redundancy and resulting in improvement of the system performance. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Interactive Data Entry and Updating DBMS provides a way to interactively update (modify) data in a database, as well as interrogate it. This capability allows even a beginner to work with a database very effectively. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Ease of Learning and Use A major feature of a database management software package is its user friendliness. In other words documentation is adequate and clearly presented. Structural Query language and Report Writers allow users to interactively interrogate the database and analyze it. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Data Independence Data independence is a primary concept of database management. In DBMS package, data is stored in a such a way so as to allow changes to the database structure without affecting the programs that access data. Data independence in DBMS separates data entry from data processing. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Data Security and Integrity Data security is provided by using passwords. This prevents unauthorized users from accessing the database. Users are allowed access to the whole of database or subsets of database, called Subchema. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Increased Productivity In organizations when the same database is used by several departments, DBMS provides an easy-to-use query language that enables users to get instant answers to their questions. This reduces the requirement of specially written programs and their frequent modifications according to the changing needs. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Recovery from Failure DBMS have a provision to recover database in the event of hardware / software failure. A backup utility of database is used to obtain backup at regular intervals. Such a utility forms an integral part of a Database Management System. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Performance This objective emphasizes on the reduction of response time to the inquiries made by the users of data. The satisfactory response time is governed by the nature of the user database dialogue. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Relational Database In relational model of data structuring, all data and relationships are represented in two-dimensional tables called a relation. This table manages data in more than one file at one time. Files are treated as tables with rows and columns and not as lists of records. Relational database thus sets data in a table or rows and columns. Relational model of database differs very much from the hierarchical or network counterparts. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Advantages of Relational Database • The relational database structure can be efficiently used even with a computer that has limited memory and processing capability. • Relational database is very useful for small databases. • Relational database is much easier to use because it enable a computer system to accommodate a variety of inquiries in an efficient manner. • Relational database is only concerned with the data and not with the structures which improves performance. Hence the processing time and storage space is comparatively large in relational database but the user is not required to know the intricacies of the structure design thus making RDBMS easy to use and learn. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Phases of Database Design • Designing a database file involves three major steps: • Data definition • Data refinement • Establishing relationships between the fields Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Data Definition The first phase of Database Design is the data definition. Before you actually create database structure, you must list down all the important fields which you are going to make use of. Data Refinement During this phase, you may refine the list of fields just created so that the fields form an accurate description of the types of data that you will need in the desired database. Establishing Relationship between Fields Drawing relationships among different fields helps to find the importance of each type of field. It is particularly important that you determine which, if any relationships between data fields will call for the use of more than one databases. Relational capability means that the data within one database can be linked, or related, to the data in another database. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Keywords used for file processing Updation of file: Updation is the process of modifying a master file with current information according to a specified procedure. Searching a file: Searching is a function or mode that enables the user to locate a record in a sequential file. Insertion in the file: Insertion is the process of adding data or text or record in a file at the indicated location. A record is inserted in a sequential file at the end of the file. The file is then sorted or rearranged in a particular order, either ascending or descending. Inserting record in a sequential file is quite a cumbersome process. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Report production and file updation The output of a computer system is the primary contact between the system and most users. The quality of this output and its usefulness determines whether the system will be used, so it is essential to have the best possible output. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Methods of outputting information • There are four principal methods of outputting information : • Printing • Screen display • Microfilm • Synthetic speech method Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Output design • Type of output • Content • Format • Location required • Frequency • Response time required • Volume statistics • Sequence • Post-printing requirements Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Types of output • Outputs can be categorized as follows: • External outputs: These go outside the organization (e.g. invoices, orders, tax returns) and therefore call for special attention as they may directly effect the organization’s business relations with its customers. • Internal outputs: These remain within the organization but still require careful consideration because they may affect the operational efficiency of the total system. • Computer operations output: These are required within the computer services department (e.g. usage statistics, control reports, etc.) Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Form Design • Before introducing a new form, its need must be firmly established. It may be that the transfer of information can be achieved in other ways using forms already in existence. A new form must be justified by assessing the following: • Means to obtain information most efficiently. • Means to disseminate information most efficiently. • Means to store information. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Pseudocodes Pseudocodes is an abbreviated form of expression that makes use of both the English language and certain programming language control words such as IF-THEN – ELSE as well as END – IF. Pseudocode is a program analysis tool that is used for planning program logic. It is an imitation of actual computer instructions written in ordinary natural language such as English. The user describes in plain English language, the sequence of steps necessary to solve a particular problem. Sentences are generally written one per line. Indentation is used in the IF statement to outline which actions are to be taken if a condition is true and which are to be taken if the condition is not true. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Modular Programming In industry and commerce, the problems that are to be solved with the help of computers need thousands or even more number of lines of code. The importance of splitting up the problem into a series of self-contained modules then becomes obvious. A module should not exceed about 100 or so lines and should preferably by short enough to fit on a single page. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Advantages of modular design • Some modules will be standard procedures used again and again in different programs or parts of the same program. • Since module is small, it is simpler to understand it as a unit of code. It is therefore easier to test and debug, especially if its purpose is clearly defined and documented. • Program maintenance becomes easier because the affected modules can be quickly identified and changed. • Modules can be tested independently, thereby shortening the time taken to get the whole program working. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
advantages of modular design continued ……. • In a very large project, several programmers may be working on a single program. Using a modular approach, each programmer can be given a specific set of modules to work on. This enables the whole program to be finished sooner. • More experienced programmers can be given a more complex module to write and the junior programmers can work on the simpler modules. • If a programmer leaves part way through a project, it is easier for someone else to take over a set of self contained modules. • A large project becomes easier to monitor and control. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Characteristics of Structured Programs • In general terms, structured programming is the development of computer programs that are well organized. • The programs are based on top-down modular design. In other words, the problem at hand is analysed or broken down into major components, each of which is again broken down if necessary. Therefore, the process involves working from the most general down to the most specific. The design of the modules is reflected in hierarchy charts. • Each module has one entry point and one exit point. The GOTO statement is never used to jump from one module in the program to another. (Pure structured programs do not use GOTO). Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Characteristics of Structured Programs continued ……….. • A rule of thumb is that the modules should not be more than one half page long. If they are longer than this, they should preferably be split into two or more submodules. • Two-way decision statements are based on IF..THEN, IF..THEN..ELSE and nested IF statements. • Loops are not custom designed with the use of the GO TO statement, but are based on the consistent use of WHILE..WEND and FOR..NEXT. In WHILE..WEND, the loop is based on the truth of a condition and in FOR..NEXT, on a counting process and the number of repetitions that can easily be predicted. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Once a program has been typed in, different types of errors may show up. • These include: • Syntax / semantic errors • Logic errors • Runtime errors Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Syntax/Semantic errors Syntax is a set of rules governing the structure of and relationship between symbols, words and phrases in a language statement. A syntax error occurs when a program cannot understand the command that has been entered. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Logic errors Logic refers to a sequence of operations performed by a software or hardware. Software logic or program logic is the sequence of instructions in a program. Logic errors are the errors that have been entered in the instructions created because of the mistake made by a programmer. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Runtime error Runtime error occurs when a program is run on the computer and the results are not achieved due to some misinterpretation of a particular instruction. This could be some thing like dividing a number by zero which results in a very large value of quotient. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Program Testing It is the job of the programmer to test, as far as possible, that all parts of the program work correctly. It should be realized that complete testing is not possible except in the case of the most trivial program; one can never be completely certain that all errors have been removed, but sufficient tests can be performed to give a reasonable measure of confidence in the program. Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net
Methods of Testing • FUNCTIONAL TESTING • Does the logic work properly? • This means, answering the following: • Does the program work as intended? • Can it be made to crash? • LOGIC TESTING • Is the necessary logic present? • This means answering the following: • Are there any functions missing? • Does the program or module do everything specified? Compiled by : S.Agarwal, Lecturer & Systems Incharge, St. xavier's Computer Centre, Kolkata : sxcc@vsnl.net