You are on page 1of 18

Introduction to Computer Programming

In todays IT driven business era, Managers must understand the working of software, which is the driving force of IT. Understanding software programming helps the managers to develop problem solving skills using computers, to know what software development is and what software developer do It helps Managers to be familiar with programming concepts and terminology to facilitate communication with software developers.

Program Development Life Cycle

Problem Definition Requirement Analysis Designing a program model Determining correctness of the program Coding the Program Testing and debugging the program Documenting the program

Problem Definition
Generally the problems in real life are not precise and sometimes may be ambiguous. To obtain solutions for such problems we need to define problem specifically. The problem must be clearly understood as to what must be done rather than how to do it. The problem definition should in users language and should be described from the users point of view. It usually should not be stated in technical computer terms.

Requirement Analysis
An explicit set of requirements is important as they help to ensure that the user rather and not the programmer drives the programs functionality. Only if the requirements are explicit the user can review them and agree to them, which reduce the burden on programmer to guess what the user wants. Specifying requirements adequately is a key to the programs success. Essentially, we must look for three main components
1.What is given as input 2.What is expected as output 3.How to arrive at the solution

A program is required to retrieve motor vehicle registration records from a file upon receipt of a request from an operator at a terminal. The operator will supply a vehicle registration number and the program will display the details of its vehicle and its owner. An error message will be displayed if the program is unable to locate the vehicles record.

Input :-Vehicle Registration number Process :-Using the registration number, search for it , and if found, retrieve the details of the vehicle and its owners name from the disk. Output :- If retrieval was successful, then allow the details of the vehicle to be displayed on the screen but if unsuccessful, indicate the absence of the vehicle registration on the disk and display a suitable error message .

Designing a program model

An algorithm is a formula, a recipe, a step by step procedure to be followed in order to obtain the solution to a problem. To be useful as a basis for writing a program, the algorithm must:
Arrive at a correct solution within a finite time Be clear, precise, unambiguous and Be in a format which lends itself to an elegant implementation in a programming language

Designing a program model

Tools for preparation of an algorithm Flowcharts : Provide a visual and graphical representation of solution Pseudo codes: writing the program logic in a simple step by step manner using a Englishlike vocabulary. Logic depicted using these tools can then be written using any computer programming language.

Determining correctness of algorithm

Different Methods : Dry Run Independent inspection Structured walk-through

Dry Run
It is a manual way of testing an algorithm for its correctness and functionality. In this method, a table is prepared with columns for each variable used in the algorithm and the value of each variable is updated in the table as we proceed through the algorithm, one step at a time. Success of the Dry Run method depends upon the ability to step through the instructions exactly as a computer would execute them.

Dry Run
Step 1 START Step 2 X= 5 Step 3 Y =1 0 Step 4 Z = 0 Step 5 Z = X+Y+(X * Y) Step 6 Y = Y+6 Step 7 Z = Z+Y Step 8 DISPLAY X,Y,Z Step 9 END X Initial Value After step 5 After step 6 After step 7 5 5 5 5 Y 10 10 16 16 Z 0 65 65 81

So the results displayed on the screen would be 5, 16, 81

Independent inspection
In this method the specification and designed solution is handed over to the developer's colleague for comments. The solution is checked by inspection or dry run. This method must be adopted as it brings objectivity in the design of the algorithm. The person who has developed the algorithm will always view it with a bias and may not be thinking of situations that may arise, other than those already taken care of. A person who has not developed the algorithm is in a better position to evaluate the algorithm against all possible occurrences and hence any errors in the algorithm can be taken care of before coding.

Structured Walkthrough
This method involves a presentation of the algorithm to a team of peers. The team points out inconsistencies, better procedures and errors if any in the algorithm. One member takes notes on the action points to be taken by the presenter. Spotting of errors becomes easier while explaining the logic to others. The solution is either accepted completely, or accepted after minor modifications, or rejected completely. T This method is more productive than a dry run or an independent inspection.

Coding the Program

This is the process of converting the algorithm (flowchart/pseudocode) into an actual computer program. Here we choose a programming language(Machine, Assembly and High Level) and using the syntax and semantics of that language, the algorithm expressed in the form of a flowchart/pseudocode is converted into a computer program.

Syntax means the correct way or "grammar" of writing a command and Semantics means the logical meaning of a statement.

Test and debug the Program

Syntax errors occur when a computer language compiler cannot understand a command entered by the programmer. When such an error is encountered the computer rejects the program and prints out an error message. These errors are encountered during compilation and are very easy to correct. In many cases, these errors arise due to spelling mistakes, missing commas, etc. and incorrect syntax. Execution Errors are encountered after error-free compilation, at the time of execution of the program. Execution errors are also called runtime errors. Typical examples are : Infinite loops Correct outputs only for selected data Division by zero

Test and debug the Program

Logical Errors are due to mistakes made by the programmer while coding the program. The computer does not detect logical errors. For example, for calculating the net salary of an employee the formula used may be Net Salary = Basic Salary + Allowances - Deductions

but through oversight, while coding, the formula is written as Net Salary = Basic Salary - Allowances + Deductions This will obviously produce a wrong result. Such errors can be detected only by a dry run.
Note: Compiler converts the entire program into its equivalent machine and hence all the errors are displayed together after the compilation process. Interpreter converts the program line by line and hence the errors are displayed as when they are encountered.

Once the program has been written and debugged, it is ready for use and hence requires documentation or a written procedure of how to run the program, enter data, what problems to expect, how to handle them, etc. Documentation of a program will consist of flowcharts/pseudo codes, program listings and detailed written statements of algorithms and procedures involved. Documentation is necessary for program maintenance. Without proper documentation, it will be difficult to change a program at a later date. It is a mis-held notion that documentation is the last step in the algorithm development stage. In fact, it should be interwoven with the entire phase of the programming process, especially with the design and implementation, because documentation is supposed to enable individuals to understand the logic of programs.