CPPM - 104 PDF
CPPM - 104 PDF
CPPM - 104 PDF
Semester - I
By:
Bhavsar Jenish
104-CPPM
Flowchart
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. Flowchart uses boxes of different shapes to denote different types of instructions. The actual instructions are written within these boxes using clear and concise statements. These boxes are connected by solid lines having arrow marks to indicate the flow of operation, that is, the exact sequence in which the instructions are to be executed. Since a flowchart shows the flow of operations in pictorial form, any error in the logic of the procedure can be detected easily. Once the flowchart is ready, the programmer can forget about the logic and can concentrate only on coding the operations in each box of the flowchart in terms of the statements of the programming language. This will normally ensure an error-free program.
Terminal Box: The terminal symbol, as the name implies, is used to indicate the starting (BEGIN), stopping (END), and pause (HALT) in the program logic flow. It is the first symbol and the last symbol in the program logic. Input/ Output Box: The input/output symbol is used to denote any function of an input/output device in the program. If there is a program instruction to input data from an input device or we want to output the results to any output device, are indicated in the flowchart with an input/output symbol. Processing Box: A processing symbol is used in a flowchart to represent arithmetic and data movement instructions. Thus, all arithmetic processes such as adding, subtracting, multiplying and dividing are shown by a processing symbol. Decision Box: 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. During execution, the appropriate path is followed depending upon the result of the decision.
2.
3.
4.
5.
6.
Connector: There are instances when a flowchart becomes too long to fit in a single page and the use of flow lines becomes impossible. Thus, whenever a flowchart spreads over more than one page, it is useful to utilize the connector symbol as a substitute for flow lines. This symbol represents an entry from, or an exit to another part of the flowchart. A connector symbol is represented by a circle and a letter or digit is placed within the circle to indicate the link. 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. The normal flow of flowchart is from top to bottom and left to right.
Rules for Flowcharting: 1. First formulate the main line of logic, and then incorporate the details. 2. Maintain a consistent level of detail for a given flowchart. 3. Do not give every detail on the flowchart. A reader who is interested in greater details can refer to the program itself. 4. Words in the flowchart symbols should be common statements and easy to understand. 5. Be consistent in using names and variables in the flowchart. 6. Go from left to right and top to bottom in constructing the flowchart. 7. Keep the flowchart as simple as possible. The crossing of flow lines should be avoided as far as possible. Flow-lines must be in one-direction only. 8. Properly labelled connectors should be used to link the portions of the flowchart on different pages.
104-CPPM
Advantages of Flowcharting: 1. 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. 2. It analyses the problem effectively. 3. Flow-chart is a road-map to efficient coding. 4. It assists in reviewing and debugging of a program. 5. It provides effective program documentation. Disadvantages of Flowcharting: 1. Flowcharts are very time-consuming and laborious to draw. 2. Redrawing a flowchart, if there are any changes, is tedious. 3. There are no standards determining the amount of detail that should be included in a flowchart. Flowchart supports the following logic structures: 1. Sequencing: This logical structure is used for performing instructions one after another in sequence. Hence, for this logic instructions are written in the order, or sequence, in which they are to be performed. The flow is from top to bottom. Branching / Selection: It is non-sequential logic which is also known as Decision logic. Statement may or may not be executed based on some condition. The condition is written inside the decision box in the flow chart. If the condition is true a particular path is followed otherwise another path is executed. Iteration/ Looping: When one or more conditions may be executed several times, depending on some condition, we use looping. We can use the same decision box to check the execution times i.e. the number of times the statements are executed. Loops can be fixed or variable.
2.
3.
Programming
Programming is a process that starts with a problem that a program is to solve. The first step in the process is for the programmer to thoroughly understand that problem --- to understand what information will be given to the program or what information the program needs (this is called the input) and what answers (and in what format) the program should produce (this is the output). The programmer then proceeds to design an algorithm to solve the problem and translates that algorithm into a programming language. At this point the programmer types the program into the computer and tests it to see if it works correctly.
104-CPPM
Two phases involved in the design of any program: 4. Problem Solving Phase: In the problem-solving phase the following steps are carried out: i. Define the problem ii. Outline the solution iii. Develop the outline into an algorithm iv. Test the algorithm for correctness 5. Implementation Phase: The implementation phase comprises the following steps: i. Code the algorithm using a specific programming language ii. Run the program on the computer iii. Document and maintain the program
104-CPPM
3. High Level Language: High level language programs are written in English language. The programs cannot be executed directly. It needs to be converted to machine level language for execution. It requires a translator called Compiler or Interpreter for converting high-level to machinelevel language. E.g.: BASIC, FORTRAN, PASCAL, C, COBOL, etc. They are also known as Procedure-oriented languages. Programmer needs to specify complete instructions inorder to perform a task. Advantages: 1. Easier to program. 2. Easy to write and understand. 3. Portable i.e. Machine independent. 4. Easy to locate and correct errors Disadvantages: 1. Takes more execution time. 2. Compute cannot understand directly it requires translator (Compiler/Interpreter).
Structured Programming
Structured programming (sometimes known as modular programming) is a subset of procedural programming that enforces a logical structure on the program being written to make it more efficient and easier to understand and modify. Structured programming frequently employs a top-down design model, in which developers map out the overall program structure into separate subsections. A defined function or set of similar functions is coded in a separate module or sub-module, which means that code, can be loaded into memory more efficiently and that modules can be reused in other programs. After a module has been tested individually, it is then integrated with other modules into the overall program structure. The reason for the evolution to structured programming is the need for well organized programs that are: (a) Easier to Design (d) Easy to Test and Debug (b) Easy to Read and understand (e) Combine with other programs (c) Easy to Modify (f) More Reliable Examples of Structured Programming Languages: C, Ada and Pascal. The Structure Theorem: It is possible to write any computer program by using only three (3) basic control structures, namely: 1. Sequential 3. Repetition (looping, DoWhile) 2. Selection (if-then-else)
Compiler
A program which translates a high-level language program into a machine language program is called a compiler. It checks all kinds of limits, ranges, errors etc. But its program execution time is more, and occupies a larger part of the memory. It has low speed and low efficiency of memory utilization. 6
104-CPPM
Interpreter
An interpreter is a program which translates one statement of a high-level language program into machine codes and executes it. In this way it proceeds further till all the statements of the program are translated and executed. A compiler is nearly 5 to 25 times faster than an interpreter. An interpreter is a smaller program as compared to the compiler. It occupies less memory space. It can be used in a smaller system which has limited memory space. Compiler Scans the program line by line and translates immediately. Syntax errors for each line are to be solved and then translated. Once all the lines are checked and translated, the program is executed. It is quicker and easier to make changes in the program and thus development time can be reduced. They use less memory space and reliable for smaller systems.
Interpreter Scans the entire program first and then translates the whole program. List of errors which are generated for the whole program are to removed and then the program is executed. Changes in program needs recompilation hence it takes more time. They use more memory space.
Editor An editor is a simple computer program which allows users to create, change, or edit programs. There are four types of editors:
1. Linkage Editor: The linkage editor is a utility program which adapts a program that has just been assembled or compiled into a particular computer environment. 2. Text Editor: A text editor is a software program that creates and manages text files. 3. Line Editor: A line editor allows lines of text to be entered and edited only by entering commands which refer to a particular line or block of text. 4. Screen Editor: A screen editor allows the programmer to position the cursor anywhere on the screen and insert or delete text.
1. 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. 2. 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. 3. Runtime Errors: Runtime errors occur 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 something like dividing a number by zero which results in a very large value of quotient. It may also be any other instruction which a computer is not able to understand.