Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 3 Computer Programming -1-. The main steps of program development to solve the problem: 1- problem definition : The problem must be defined into.

Similar presentations


Presentation on theme: "Lecture 3 Computer Programming -1-. The main steps of program development to solve the problem: 1- problem definition : The problem must be defined into."— Presentation transcript:

1 Lecture 3 Computer Programming -1-

2 The main steps of program development to solve the problem: 1- problem definition : The problem must be defined into three question : 1- What are the available data or data that represent the input of the program? (input) 2- What is the method or set of processes that lead to get the results from the available data? (process) 3-What are the required results or Output of the program? (output)

3 2-Design solution : - Dividing the problem into small steps - Then identify the solution in a sequence of steps called algorithm. 3-Write the program (source code) : compile the algorithm into a specific programming language. 4- Compilation : When testing program, the compiler may find Syntax errors in the program, in this case must be corrected and then recompile the program again

4 Types of Program Error There are three basic categories of program errors: 1. Syntax Errors 2. Run-time Errors 3. Logic Flaws In the first two cases when an error occurs, the computer displays an 'Error Message', which describes the error, and its cause. In the final case, the program will not show an error message but it will not do what the programmer wanted it to do.

5 1-Syntax Errors : These errors are the easiest to find because they are highlighted by the compiler. Error messages are given. This type of error is caused by the failure of the programmer to use the correct grammatical rules of the language. If a program has a syntax error it cannot be translated, and the program will not be executed. 2. Run-time Errors Run-time errors are detected by the computer and displayed during execution of a program. A run-time error occurs when the user directs the computer to perform an illegal operation, eg: Dividing a number by zero, Assigning a variable to the wrong type of variable

6 3. Logic Flaws These are the hardest errors to find as they do not halt the program. They arise from faulty thinking on behalf of the programmer. Programs with logic errors will often compile, execute, and output results. However, at least some of the time the output will be incorrect. Error messages will generally not appear if a logic error occurs, this makes logic errors very difficult to locate and correct.

7 Algorithm and flowchart - An Algorithm : is a finite sequence of instructions that produce the solutions to the problem and is written by any human-language. - An algorithm must ( algorithm constraint ): Be clear. Give the correct solution in all cases should not be associated a specific programming language, but can be converted to any language selected by the programmer.

8 Algorithm Example - write an algorithm that find the perimeter of the rectangle : 1- start 2- input : L and W 3- process : p= 2*(L+W) 4- output : print p 5- End

9 Flow chart Flowchart : A graphical representation of the sequence of operations in a program. Programmer prepares flowchart before coding. Note : Different symbols are used to draw each type of flowchart.

10 Flowchart Symbol NameSymbol بداية – نهاية Start - End مدخلات – مخرجات Input - Output معالجة Processing القرار و التفرع Decision and branching خط التدفق Flow Line

11 p= 2*(L+w) start End print p Flowchart Example : -Draw flowchart that find the perimeter of the rectangle. Input L,W

12 Example 1 : - write an algorithm and flowchart for finding the average of two numbers. Algorithm : Flowchart : average= (A+B)/2 input A and B start End print average 1-start 2-input: A and B 3-process : average = (A+B)/2 4- output : print average 5- End

13 Example 2 : - Write an algorithm and draw flowchart that reads two values, determines the largest value and prints the largest value. Algorithm : 1-start. 2- input : A,B 3- process : A>=B yes : A= Max No : B=Max 4- output: Max 5- End

14 Max =B End A >=B ? NoYes Start Input A, B Max =A Print Max Flowchart :

15 Example 3 : - Write an algorithm and draw flowchart to calculate the value of each of the variables C, B, A in the following equation: (1) A= X² + 2Y (2) B= 2X – 3A (3) C= A² + XB Algorithm : 1-start. 2- input : X,Y 3- process : A= X² + 2Y B= 2X – 3A C= A² + XB 4- output: A,B,C 5- end

16 Flowchart : Start End A=(X*X) + 2Y C= A + XB B= 2X – 3A Input X,Y print A,B,C

17 Homework Write an algorithm and draw a flowchart : 1) finding Area to the circle when Area = 3.14 * X. 2) finding the value to A and B( when X and y are entered by user) A=X^2+2Y, B=2X-3A.


Download ppt "Lecture 3 Computer Programming -1-. The main steps of program development to solve the problem: 1- problem definition : The problem must be defined into."

Similar presentations


Ads by Google