Sie sind auf Seite 1von 4

STRUCTURED PROGRAMMING Programming Fundamentals Computer programming - (often shortened to programming, scripting, or coding) is the process of designing, writing,

, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages (such as Java, C++, C#, Python, etc.). When you want a computer to perform a specific task, such as generating a marks sheet or a salary slip, you have to create a sequence of instructions in a logical order that a computer can understand and interpret. This sequence of instructions is called a program and the process of writing programs is called programming. The task of programming involves a lot of effort and careful planning. Without this, the computer will produce erroneous results. The following steps should go into the planning of program: o Defining and analyzing the problem o Developing the solution logically using an algorithm Defining and analyzing the problem Before writing a program, we have to define exactly what Data we need to provide (input) e.g. Suppose we want to write a program to work out the total and average of a students marks in five subjects, we would need to mention the marks in the five subjects as input. Information we want the program to produce (the output) - the elements that should be displayed and those that should not. In the marks example, since the task is to prepare a marks sheet, the marks in all the five subjects, their total and average should be displayed on the screen. Once we know these, we can figure out how to develop the solution. Developing a solution logically-Once you have defined and analyzed the problem, decided on the output and the input, you can go on to develop the solution. The most important aspect of developing the solution is developing the logic to solve the problem. This requires creating a set of step-by-step instructions and/or rules called an algorithm. Each step performs a particular task. Various methods for writing the algorithms include: Use of natural language/plain English Pseudo code Flow charts Coding/programming language The algorithm for the example on finding total marks and average could look like this: 1. Note down the students marks in different subjects. 2. Find the total marks scored by the student. 3. Compute the average marks. 4. Assign grade. 5. Display average percentage of marks and grade. 6. End.

Note: For any computer program to work well, it has to be written properly. Formulating an effective algorithm will make writing an effective program easier. For an algorithm to be effective, it has to have the following characteristics: Finiteness: - An algorithm should terminate after a fixed number of steps. Definiteness: - Each step of the algorithm should be defined precisely. There should be no ambiguity. Effectiveness: - All the operations in the algorithm should be basic and be performed within the time limit. Input: - An algorithm should have certain inputs. Output: - An algorithm should yield one or more outputs that are the result of operations performed on the given input. Programming: The next step after developing an algorithm Once we develop the algorithm, we need to convert it into a computer program using a programming language (a language used to develop computer programs). A programming language is entirely different from the language we speak or write. However, it also has a fixed set of words and rules (syntax or grammar) that are used to write instructions for a computer to follow. Programming languages can be divided into three types: a) Machine language -This is the basic language understood by a computer. This language is made up of 0s and 1s. A combination of these two digits represents characters, numbers, and/or instructions. Machine language is also referred to as binary language. b) Assembly language-This language uses codes such as ADD, MOV, and SUB to represent instructions. These codes are called mnemonics. Though these codes have to be memorized, assembly language is much easier to use than machine language. c) High-level languages-High-level languages such as BASIC, FORTRAN, C, C++, and JAVA are very much easier to use than machine language or assembly language because they have words that are similar to English.

A quick comparison of programming languages Machine Assembly Language Language Time to Since it is A program execute the basic called an language assembler of the is required computer, to convert it does not the require any program translation, into and hence machine ensures language. better Thus, it machine takes efficiency. longer to This means execute the than a programs machine run faster. language

High-level Languages A program called a compiler or interpreter is required to convert the program into machine language. Thus, it takes more time for a computer to execute.

Time to develop

Needs a lot of skill, as instructions are very lengthy and complex. Thus, it takes more time to program.

program. Simpler to use than machine language, though instruction codes must be memorized. It takes less time to develop programs as compared to machine language.

Easiest to use. Takes less time to develop programs and, hence, ensures better program efficiency.

Developing a computer program Follow the steps given below to become a successful programmer: 1) Define the problem: Examine the problem until you understand it thoroughly. 2) Outline the solution: Analyze the problem. 3) Expand the outline of the solution into an algorithm: Write a step-by-step procedure that leads to the solution. 4) Test the algorithm for correctness: Provide test data and try to work out the problem as the computer would. This is a critical step but one that programmers often forget. 5) Convert the algorithm into a program: Translate the instructions in the algorithm into a computer program using any programming language. 6) Document the program clearly: Describe each line of instruction or at least some important portions in the program. This will make the program easy to follow when accessed later for corrections or changes. 7) Run the program: Instruct the computer to execute the program. The process of running the program differs from language to language. 8) Debug the program: Make sure that the program runs correctly without any errors or bugs as they are called in computer terminology. Finding the errors and fixing them is called debugging. Dont get depressed when bugs are found. Think of it as a way to learn. Quality requirements of a good program Whatever the approach to software development may be, the final program must satisfy some fundamental properties. The following properties are among the most relevant: Reliability: - how often the results of a program are correct. This depends on conceptual correctness of algorithms, and minimization of programming mistakes Robustness: - how well a program anticipates problems not due to programmer error. This includes situations such as incorrect, inappropriate or corrupt data, unavailability of needed resources such as memory, operating system services and network connections, and user error. Usability: - the ergonomics of a program: the ease with which a person can use the program for its intended purpose or in some cases even unanticipated purposes. Such issues can make or break its success even regardless of other issues. This involves a wide range of textual, graphical and sometimes

hardware elements that improve the clarity, intuitiveness, cohesiveness and completeness of a program's user interface. Portability:- the range of computer hardware and operating system platforms on which the source code of a program can be compiled/interpreted and run. This depends on differences in the programming facilities provided by the different platforms, including hardware and operating system resources, expected behavior of the hardware and operating system, and availability of platform specific compilers (and sometimes libraries) for the language of the source code. Maintainability:- the ease with which a program can be modified by its present or future developers in order to make improvements or customizations, fix bugs and security holes, or adapt it to new environments. Good practices during initial development make the difference in this regard. This quality may not be directly apparent to the end user but it can significantly affect the fate of a program over the long term. Efficiency/performance:- the amount of system resources a program consumes (processor time, memory space, slow devices such as disks, network bandwidth and to some extent even user interaction): the less, the better. This also includes correct disposal of some resources, such as cleaning up temporary files and lack of memory leaks. Readability of source code Readability refers to the ease with which a human reader can comprehend the purpose, control flow, and operation of source code. It affects the aspects of quality above, including portability, usability and most importantly maintainability. It is important because programmers spend the majority of their time reading, trying to understand and modifying existing source code, rather than writing new source code. Unreadable code often leads to bugs, inefficiencies, and duplicated code. The following factors contribute largely to readability of the source code:

Different indentation styles (whitespace)- an indent style is a convention governing the indentation of blocks of code to convey the program's structure. Comments- a comment is a programming language construct used to embed programmerreadable annotations in the source code of a computer program. Decomposition Naming conventions for objects (such as variables, classes, procedures, etc.)

Subroutine (subprograms) In computer programming, a subroutine is a sequence of program instructions that perform a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed. Subprograms may be defined within programs, or separately in libraries that can be used by multiple programs. In different programming languages a subroutine may be called a procedure, a function, a routine, a method, or a subprogram. The generic term callable unit is sometimes used. As the name subprogram suggests, a subroutine behaves in much the same way as a computer program that is used as one step in a larger program or another subprogram. A subroutine is often coded so that it can be started (called) several times and/or from several places during one execution of the program, including from other subroutines, and then branch back (return) to the next instruction after the call once the subroutine's task is done.

Das könnte Ihnen auch gefallen