















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
















Problem solving lifecycle PURPOSE OF PROGRAM PLANNING Various stages in program development Before a problem to be solved by a computer, it needs preparation. In spite of their impressive capabilities, computers still have to be told exactly what to do, in a step-by-step fashion. The process of achieving the required level of detail is called problem analysis. Problem analysis can be divided into several more or less distinct parts. 1. Problem identification and study : This step involves the identification of the problem and identification of the input, output and processing requirements of the problem. 2. Find a solution : Once the study is complete, the programmer can easily develop a solution to solve the problem. There may be even more than one solution to solve a' problem. In such cases the best solution is selected. In some cases no satisfactory solution method may be known. In this case a method must be developed, or the problem has to be simplified.
3. Develop an algorithm : When a solution method has been selected, it must be reduced to the level of detail that computer understand. This is usually done in stages. 4. Program coding : Once the algorithm is ready it must be coded in a high level language to execute it by the computer. 5. Program testing and debugging : After developing a program, it must be tested before the implementation of the program in the real application area. The program is tested by giving sample data ( test data ) and checked the output against the known results. If it is not matching, then the programmer must check the program for errors and debug the program till it gives the correct result.
6. Program implementation : Once the program is ready and error free, it can be implemented in the real application area. 7. Program maintenance : Once the program is implemented, the user may find more errors that was not visible in the test phase. These errors must - be eliminated whenever it occurs. In addition to this, after using the software, the user may require certain modification or additions to the program. These modifications and debugging must be carried out by the programmer throughout the life of the program. 8. Documentation : At each stage of the problem analysis the analyst must record each and every conclusion he reached. These records are useful for the future modifications and debugging of the program Hierarchy Charts In programming, a hierarchy chart (also known as a structure chart ) is a diagram that represents the hierarchical structure of modules or functions within a program. It visually breaks down a system into smaller, manageable components, showing the relationships between them. Key Concepts of a Hierarchy Chart in Programming:
Top-down and Bottom-up approaches in Programming In programming, the top-down and bottom-up approaches are two fundamental methods for software development and problem-solving. Each approach has its own set of principles and use cases. Both have their distinct methodologies and are used in different scenarios depending on the requirements and the nature of the project. Top-down Design Model: The top-down approach, also known as stepwise refinement, starts with the highest-level design and breaks it down into smaller, more detailed parts. The process continues until the smallest, most specific tasks are defined. Breaking problems into parts help us to identify what needs to be done.Mainly used by structured programming language such as COBOL, Fortran, C, etc. Advantages : ļ· Clarity and Control : The design process is systematic and organized. ļ· Easier Debugging : Problems can often be isolated to specific modules or layers. ļ· Good for Large Projects : Ideal for large systems where the overall structure must be well-defined before diving into the details. Disadvantages :
ļ· Risk of Incompleteness : Some details might be overlooked until the lower levels are defined. ļ· Complexity : It can be challenging to break down complex systems in a way that maintains simplicity. Bottom-Up Design Model: In this design, individual parts of the system are specified in detail. The parts are linked to form larger components, which are in turn linked until a complete system is formed. Object-oriented language such as C++ or java uses a bottom-up approach where each object is identified first. Mainly used by object oriented programming language such as C++, C#, Python. Advantages : ļ· Reusability : Modules developed in isolation can often be reused in different parts of the system. ļ· Early Testing : Since each module is built and tested independently, you can verify the functionality early in the development process. ļ· Adaptability : Easier to adjust or replace components without affecting the entire system. Disadvantages : ļ· Integration Challenges : Assembling modules into a coherent system can be complex. ļ· Lack of Big Picture : Developers might lose sight of the overall system architecture, leading to a less organized final product. ļ· Time-Consuming : Integrating and testing smaller components can be time- consuming and might require significant refactoring.
flowcharts. In this standard convention the following shapes are used for various blocks in a flowchart. Flowcharting Symbols. Average of Three Numbers
o In Python: input("Enter your name: ") o In C: scanf("%d", &variable); Output Statements : Used to display data to the user. ļ· Examples : o In Python: print("Hello, World!") o In C: printf("Hello, World!\n");
2. Decision-Making /Branching Statements These statements allow the program to make decisions and execute different code blocks based on certain conditions. Eg:if,if-else 3.Looping/Iteration Statements These statements are used to execute a block of code repeatedly as long as a condition is true. Eg:for,while,do-while THE PROGRAM CONCEPT Program A program is a group of closely related and interdependent activities. A computer program is a series of organized instructions that directs a computer to perform tasks. A programming language is a set of words, symbols and codes that enables humans to communicate with computers. Hundreds of
ļ· Problem Solving : Different languages provide various tools and abstractions to solve specific types of problems effectively. ļ· Software Development : They are the foundation of all software, enabling the creation of applications, websites, games, and more. ļ· Innovation and Technology : Advances in computer languages often lead to new programming paradigms and technologies, driving the evolution of computing. Computer languages are essential tools that enable humans to create, control, and interact with software and machines, forming the backbone of the digital world. Types of Computer/Programming languages Since a digital computer is a programmable device, the user must instruct the computer according to his requirements. The programmer must use some languages that can be understandable by the computer. These languages are called programming languages. Machine Language /Low-Level Language/Binary language: Digital computers work only on binary digits 1 and 0. So before anything to be done by the computer the user must provide data and his instructions in a format that can be understandable by the computer, i.e., in the binary format. The instructions in the binary format are called as machine language programs. A machine language instruction is represented as a string of binary digits, which identifies the operations to be performed and the data, etc. to be used. A user must convert all his programming requirements to the binary string. Each instruction in a machine language consists of an op-code and an operand. Op-code is the instruction and operand is the data on which the instruction to be operated.
Advantages
Disadvantage ļ· spends a lot of time analyzing and processing the program ļ· the computer hardware interprets (executes) the resulting code Advantage ļ· program execution is fast 2.Interpreter It is also a translator. It takes one statement of the high level language program, translate it into machine language instructions and execute the resulting machine language instruction immediately. The input to an interpreter is a source program and output is the result of program execution and not object program. Advantages
1.Assembler An assembler is a translator that converts assembly language code, which is a low-level, into actual machine code that the CPU can execute. ie it Convert assembly code into machine code 2.Compiler A compiler is a program that translates the entire source code of a high-level programming language (like C, Java, or C++) into machine code. Characteristics: ļ· Translates the entire program before execution. ļ· Generates an executable file (e.g., .exe in Windows). ļ· Provides error messages for the entire program after the compilation process. Examples : ļ· GCC : A widely-used compiler for C and C++.
a key component in the software development and compilation process. Characteristics of good Programming Reliability- A program must work reliable. it should perform the task properly. Speed - A program must execute the specified task quickly. The time taken by the program to perform a given task should be as minimum as possible. Programming time and cost - The maximum output is obtained within minimum amount of time and reduced cost. Ease of use and Clarity - A program must be easily understood to others. Error tolerance - A program should respond to errors quickly, if any. Proper error messages should be displayed at proper time. Extensible - A program should be extended. Simplicity - Keeping things as simple as possible enhances the clarity and accuracy of programs. Efficiency - A program should efficiently utilize memory. Generality - Considerable amount of generality should be added to a program with additional programming efforts. Naturalness - A good language for an application area should be natural for programming applications of that area. That is ,it should provide appropriate operators, data structures, control structures and a natural syntax to facilitate programmers to code their problems easily and efficiently. Abstraction - Abstraction means the ability to define and then use complicated structures or operations in a ways that allows programmers to ignore many of the details. Structured Programming Support - A good programming language should have necessary features to allow programmers to write their programs based on the concepts of structured programming. This property greatly affects the ease with
which a programmer can write ,test and maintain programs. Compactness - In a good programming language, programmers should be able to express the intended operations concisely without loosing readability. Locality- A good programming language should be such that while writing a program, a programmer need not jump around visually as prepares the text of the program. This allows the programmer to concentrate almost solely on the part of the program around the statement currently working. Extensibility- A good programming language should also allow extension through simple, natural and elegant mechanisms. Suitability to its environment- A good programming language must also be suitable to its operating environment. A language for real-time application must be interactive in nature. PROGRAM TESTING AND DEBUGGING As long as human beings program computers, computer program will have errors. Program errors are known as bugs and the process of detecting and correcting these errors is called debugging. In general testing is the process of making sure that program performs the intended task and debugging is the process of locating and correcting program errors. Types of Program Errors Generally, the following two types of errors occur in a computer program: Syntax Errors .- Syntax errors occur when the rules or syntax of a programming is not followed. Such program errors typically involve incorrect' punctuation, incorrect word or undefined terms, or misuse of terms.eg the statement C = (a + b gives syntax error. the missing closing parenthesis) that should be placed in the appropriate place on the logic of the program. Logic Errors. Logic errors occur when we make errors in logic of the program.