Presentation is loading. Please wait.

Presentation is loading. Please wait.

BBS 514 - Yapısal Programlama (Structured Programming)1 From problem to program In “real world”… Problem in Natural language Top Down Design in pseudo-code.

Similar presentations


Presentation on theme: "BBS 514 - Yapısal Programlama (Structured Programming)1 From problem to program In “real world”… Problem in Natural language Top Down Design in pseudo-code."— Presentation transcript:

1 BBS 514 - Yapısal Programlama (Structured Programming)1 From problem to program In “real world”… Problem in Natural language Top Down Design in pseudo-code Program in computer code (code in almost any computer language.) Requirements: A program that does this and that and the other. It must take data from this source and IMPLEMENT Reduce cognitive load separating design and coding using top-down design The Problem Do this repeat if something then do this else do the other Print “all done” DESIGN The Design (Algorithm) The Program

2 BBS 514 - Yapısal Programlama (Structured Programming)2 Steps of Software Development 1.Problem Understanding –Read the problem carefully and try to understand what is required for its solution. 2.Analysis –Identify problem inputs and outputs. 3.Design –Develop a list of steps (algorithm) to solve the problem –Refine steps of this algorithm. (Divide and Conquer) –Verify that the algorithm solves the problem, i.e. the algorithm is correct. 4.Implementation –Implement the algorithm as a (java) program. –You have to know a specific programming language (java) –Convert steps of the algorithm into programming language statements. 5.Testing and Verification –Test the completed program, and verify that it works as expected. –Use different test cases (not one) including critical test cases.

3 BBS 514 - Yapısal Programlama (Structured Programming)3 Algorithm An algorithm is a design written in pseudo code. (in English, but a formal style) Algorithms contains: –Sequence –Decision –Repetition

4 BBS 514 - Yapısal Programlama (Structured Programming)4 Everyday Algorithms Problem: To drink a glass of milk. Algorithm: 1.Enter the kitchen 2.Get a glass 3.Get the milk from the refrigerator 4.Fill the glass with milk 5.Drink it Refine step 1: 1. Walk to the kitchen door 2. If the door is close then 2.T. Open it 3. Walk into the kitchen Refine step 3: 1. Open the refrigerator 2. Get the milk 3. Close the refrigerator Refine step 4: 1. while the glass is not full 1.1. Pour some milk into the glass

5 BBS 514 - Yapısal Programlama (Structured Programming)5 Area-Circumference Problem Requirements: Design an algorithm to find and report the area and circumference of a circle whose radius the user gives. Welcome to circle computer… Please enter the radius: 5 The area of a circle of radius 5 is 78.55 and its circumference is 31.42 Example interaction

6 BBS 514 - Yapısal Programlama (Structured Programming)6 Area-Circumference Problem To find area & circumference of circle… 1.Print welcome message 2.Ask for & get radius from user 3.Compute area as pi.radius.radius 4.Compute circumference as 2.pi.radius 5.Report area, circumference & radius Identify preconditions & ensure they are satisfied. Once we are sure that this is correct, move on to solve any non- trivial sub-problems.

7 BBS 514 - Yapısal Programlama (Structured Programming)7 Area-Circumference Problem (cont.) Solve… 5.Report area, circumference & radius 1.Print msg “The area of a circle with radius ” 2.Print radius value 3.Print msg “ is ” 4.Print area value and move to next line 5.Print msg “ and its circumference is ” 6.Print circumference value 7.Print blank line Solve… 2.Ask for & get radius from user 1.Ask (prompt) the user to enter radius 2.Get radius value from user

8 BBS 514 - Yapısal Programlama (Structured Programming)8 Calculating the average score of an exam Problem: Calculating the average score of an exam Inputs : Scores of an exam Output: Average score of the exam Algorithm: 1. Set count to zero 2. Set sum to zero 3. while there is an exam sheet do 3.1. Read the score on the sheet 3.2. Add the score on the sheet to sum 3.3. Add one to count 3.4. Move to the next sheet 4. Compute average as sum/count 5. Display average

9 BBS 514 - Yapısal Programlama (Structured Programming)9 Prime Number Problem: Deciding that a given integer number is prime or not. Input : An integer number N Output: A sentence indicating that N is prime or not. Algorithm: 1. Read the number N 2. Test whether N is prime or not 3. Display the result. Refine step 2: 1. set counter to 2 2. set PrimeFlag to true 3. while (counter < N and PrimeFlag = true) do 3.1. if N is divisible by counter then 3.1.T. set PrimeFlag to false 3.2. Increment counter by 1 Refine step 3: 1. if PrimeFlag = true then 1.T. Display that N is prime else 1.F. Display that N is not prime

10 BBS 514 - Yapısal Programlama (Structured Programming)10 Factorial Problem: Calculating N! Inputs: A positive integer N Output: N! Algorithm: 1. Read a positive integer N 2. Calculate NFactorial 3. Display NFactorial Refine step 2: 1. Set NFactorial to 1 2. Set counter to 2 3. while (counter <= N) do 3.1. Multiply NFactorial by counter 3.2. Increment counter by 1

11 BBS 514 - Yapısal Programlama (Structured Programming)11 Types & Layout (of algorithm steps) n.do step while condition indent 1.step 2.step 3.step 4.step Sequence n.if condition then nT step else nF step indent Decision n.while condition do step indent Repetition Any step can be replaced with one of the other types n.for so many times do step


Download ppt "BBS 514 - Yapısal Programlama (Structured Programming)1 From problem to program In “real world”… Problem in Natural language Top Down Design in pseudo-code."

Similar presentations


Ads by Google