Page 96 - 2502_Pakistan-kifayat_C-6
P. 96

Example: If you are creating a calculator program, you need to understand that it should perform basic
        mathematical operations like addition, subtraction, multiplication, and division.

        Key questions to ask while understanding a program:

             What problem does the program need to solve?
             What inputs does the program need?

             What outputs should the program provide?

                                   2. Plan the Solution

                                   Once you understand the problem, it’s time to plan how the program will
                                   solve it. This planning phase involves creating a flowchart or pseudocode to
                                   outline the steps the program will take.

            Flowchart: A diagram that shows the logical flow of the program.
             Pseudocode: A  written  outline  of the  program, using  plain  language  and  structured steps that
           explain what the program will do.

        Example: For a calculator program, a flowchart might show steps like "Start", "Input first number",
        "Input second number", and "Display result".

        3. Write the Code

        After planning, you can write the actual code for the program. You will use a
        programming language like Python, Java, or C++ to translate the steps into
        instructions that the computer can execute.

                                   4. Test the Program
                                   Once the program is written, it's time to test it to make sure it works correctly.
                                   Testing helps identify bugs or errors in the code.

            Test for correctness: Does the program give the right results?

             Test for edge cases: What happens if the user enters unexpected input, like a negative number or
           zero?

        Example: For the calculator, test it with different numbers to ensure the correct sum is displayed, and
        check what happens when users enter invalid input (e.g., letters instead of numbers).

        5. Debug and Fix Errors
        It’s normal to encounter errors during testing. Debugging is the process
        of finding and fixing these errors.

             Syntax errors: Mistakes in the structure of the code (e.g., missing parentheses).

             Logic errors: The program runs without crashing, but it doesn’t give the expected results.
        Use  debugging tools  or insert  print statements  to track values  and  understand  what’s  going
        wrong.






            94  Premium Edition-VI
   91   92   93   94   95   96   97   98   99   100   101