Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture Notes 8/30/05 Program Design & Intro to Algorithms.

Similar presentations


Presentation on theme: "Lecture Notes 8/30/05 Program Design & Intro to Algorithms."— Presentation transcript:

1 Lecture Notes 8/30/05 Program Design & Intro to Algorithms

2 Important Links  www.cs.unr.edu/~alinawww.cs.unr.edu/~alina  WebCT – www.webct.unr.eduWebCT

3 Homework for Thursday  Login to WebCT. Picture. Introduction.  Download a copy of the syllabus and read it.  Write an algorithm for a problem from class.  Read Chapter 1 in “C++ Programming”.  Read Chapters 1 – 3 in “Simple Program Design”

4 Main Objectives of This Course  Develop problem solving skills  Learn to program using C++

5 Algorithms * Informally - a general method for solving a problem; a recipe. * Our book - a step-by-step problem-solving process in which a solution is arrived at in a finite amount of time. *According to Webster.. al.go.rithm - a rule or procedure for solving a mathematical problem that frequently involves repetition of an operation.

6 Program Development  Define the problem  Outline the solution  Develop the outline into an algorithm  Test the algorithm for correctness  Code the algorithm into a specific programming language  Run the program on the computer – test and debug  Document and maintain the program

7 Algorithms  Algorithm is required to be: * Well defined -- it is clearly and unambiguously specified. * Effective -- its steps are executable. * Finite -- it terminates after a bounded number of steps. * Must produce a correct solution 100% of the time.

8 Steps in Program Development 1. Define the problem Input Processing Output

9 Steps in Program Development 2. Outline the solution This is a rough draft of the solution. The outline may include:  Major processing steps involved.  Major subtasks  Major Control Structures  Major variables and record structures  The mainline logic.

10 “Find an average of 3 numbers” Outline - obtain three numbers from the user - calculate the average - display the result

11 Steps in Program Development 3. Develop an outline into an algorithm The algorithm represents the precise steps to be taken and the order in which they are to be carried out.

12 “Find an average of 3 numbers” Algorithm: Prompt user for 3 numbers Prompt user for 3 numbers Get 3 numbers Get x, y and z Add numbers together OR Sum = x+y+z Divide the sum by 3 Average = sum/3 Display the result Display Average

13 Steps in Program Development 4. Test the algorithm for correctness  Very important step!!  Check for logical errors, create test data and test your algorithm.

14 “Find an average of 3 numbers” Test Algorithm (Desk check or Trace): Get 3 numbers Add numbers together Divide the sum by 2 Display the result

15 Steps in Program Development 5. Code the algorithm into a specific programming language  C,  C++,  Java,  Fortran,  Cobol,  Basic,  etc…

16 “Find an average of 3 numbers” C++ (code segment): ….. cout<<“Enter three numbers”: cin >> x >> y >> z; sum = x+y+z; avg = sum/3.0; cout<< “The average is “<< avg; …..

17 Steps in Program Development 6. Run the program on a computer – test and debug The most fun and the most frustrating part of the program development. Two main types of errors:  Syntax errors (the program will not run)  Logic errors (the program will run but will not produce correct results)

18 Steps in Program Development 7. Document and maintain the program This is NOT the last step. You should document throughout the process of developing your program.  External documentation (algorithm, test data, etc…)  Internal documentation (commenting your code)

19 “Find the average of 3 numbers for 4 sets of data.”  Define the problem  Outline the solution  Develop the outline into an algorithm  Test the algorithm for correctness

20 Structured Programming Top down development:  Look at the problem as a whole  Outline general solution  Break down into main components  Functional decomposition This systematic, disciplined approach to program design results in a higher precision of programming.

21 Structured Programming Structure Theorem Any computer program can be written using the following three control structures: * Sequence * Selection (If-Then-Else) * Repetition (DoWhile)

22 Pseudocode  Pseudocode standard which we will follow in this class: - Statements are written in simple English; - Each instruction is written on a separate line; - Each set of instructions is written from top to bottom, with only one entry and one exit; - Groups of statements may be formed into modules, and that group given a name.


Download ppt "Lecture Notes 8/30/05 Program Design & Intro to Algorithms."

Similar presentations


Ads by Google