1 / 85

Basics Menu

Basics Menu Learning Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page 2 Problem Solving Steps in the Problem Solving Process . . . . . . . . . . . . . . . . . . page 3

LionelDale
Télécharger la présentation

Basics Menu

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BasicsMenu • Learning Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .page 2 • Problem Solving • Steps in the Problem Solving Process . . . . . . . . . . . . . . . . . .page 3 • Problem Solving Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page 4 • Demonstration of a Program . . . . . . . . . . . . . . . . . . . . . . . . . .page 7 • Languages, Syntax and Semantics • What Do Human Languages Look Like? . . . . . . . . . . . . . . . page 9 • Language Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page 10 • Grammar Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page 11 • Computer Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page 14 • Debugging • Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .page 22 • Syntax Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .page 23 • More About Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page 25

  2. BasicsLearning Objectives Upon completion of this lesson, the student will be able to: 1. Identify the steps in the problem solving process. 2. Illustrate the steps in a flowchart. 3. Sketch an IPO chart and a flowchart for a given problem. 4. Discuss the Edit-Compile-Link-Execute process in creating a program. 5. State the difference between syntax and semantics in the contest of programming. 6. Compare reserved words and user-defined variables. 7. List the different types of errors possible in a program.

  3. BasicsProblem Solving

  4. BasicsProblem Solving IPO Charts – Input Process Output Charts The IPO chart lists the input data, the output produced and the process followed to reach the output from the input.

  5. BasicsProblem Solving IPO Charts – Input Process Output Charts • Input is the data or information supplied to the program by the user or the programmer • Output is the information produced by the program after processing the input. This could be sent directly to a file, printed to the printer, displayed to the user on the screen or channeled as input to another program • The process involves the steps to be followed in order to process the input and produce the correct output IPO charts are used to clearly define the inputs, outputs and processes to be used in the program. As you advance further in the course you will see why this kind of planning is important. As the saying goes “Weeks of programming can save you hours of planning” – author unknown

  6. BasicsProblem Solving Example IPO Chart This is an example of an IPO Chart of a very basic program that adds two numbers and displays the result to the user. Note that the first column contains the input variables, the second column contains the steps of the process and the third column contains the output. This is the standard format of the IPO chart.

  7. BasicsProblem Solving IPO Charts can be created for any program whether it involves the Sequence Instructions are executed sequentially, one after the other. No instruction is skipped or repeated The selection The program makes a decision based on the value in a particular variable. Based on this decision, one logical path or the other is followed or The repetition control structure Some or all of the instructions in the program can be repeated n number of times. n is based on the needs of the application or the user

  8. BasicsProblem Solving Pseudocode Pseudocode is the program instructions written in English-like manner. The following is the pseudocode for the example II. input iPhone price from the user if price < 300 then output “you can afford the iPhone” else output “no luck, dude!” endif

  9. BasicsProblem Solving Problem Solving tools Flowcharts A flowchart is a pictorial representation of the logical flow of control in an algorithm or program. An algorithm is a series of language free, step-by-step instructions detailing the flow of control in a program

  10. BasicsProblem Solving Flowchart Symbols – Start/Stop

  11. BasicsProblem Solving

  12. BasicsProblem Solving

  13. BasicsProblem Solving

  14. BasicsProblem Solving

  15. BasicsProblem Solving

  16. BasicsProblem Solving

  17. BasicsProblem Solving Demonstration Of A Program Video Source: http://youtube.com/watch?v=K5HdaQ5b9cQ An old story says one of the first computer programs failed to work because of a moth in a relay. We say we “debug” programs to this day!

  18. BasicsProblem Solving

  19. BasicsProblem Solving

  20. Language Language, Syntax and Semantics Sentences are a sequence of words that convey some meaning to another person 2. Words are the basic building blocks of our language – we learn their definitions and spelling 3. Punctuation marks are special sequences of characters (not words) we use in our sentences 4. Grammar rules tell us how to order the words and punctuation to convey our desired meaning We call words and punctuation marks Tokens 5 5. Just a fancy word for a basic language component And you use tokens to say what you want to say!

  21. BasicsProblem Solving

  22. BasicsProblem Solving

  23. BasicsProblem Solving

  24. BasicsProblem Solving

  25. BasicsProblem Solving Language, Syntax and Semantics - Statements, Identifiers, Punctuation marks • Sentences in a program are called statements • Statements are formed using identifiers and punctuation marks that follow the rules of the language. Identifiers are reserved by the language or defined by the programmer • Words are called identifiers in the program. • Special marks for things like math operators, parentheses, end of statement etc. • An identifier that has a predefined meaning is a reserved word • Words created by the programmer to name some place in the program or some piece of data being manipulated

  26. BasicsProblem Solving Language, Syntax and Semantics - Identifiers Some names in your program are reserved by the language you are using. Other names you choose to name data in your program. Reserved words are language specific names used for a variety of purposes: Cout – used to direct output to the screen Cin – used to read information from the keyboard

  27. BasicsProblem Solving Language, Syntax and Semantics - User Defined Variables • User defined names you choose according to language rules: • Names must start with a letter, not a digit • Names might be case-sensitive depending on the language you use • No blanks allowed in your names • No special characters except for an underscore • Variable names should be meaningful and descriptive, yet succinct • (none of these are allowed: %$#@!)

  28. BasicsProblem Solving Debugging - Errors There are two main reasons that a program will not execute or do what it is supposed to do – either you have made a mistake in the usage of the language or you have a mistake in the logic. In either one of these scenarios, there is an error, or mistake, in the program. The errors of language are called Syntax errors and the errors of logic are runtime errors.

  29. BasicsProblem Solving

  30. BasicsProblem Solving Debugging - Sample Syntax Errors • error C2146: syntax error : missing ';' before identifier 'outfile' Error executing cl.exe. • error C2065: 'cout' : undeclared identifier • error C2065: 'end1' : undeclared identifier • fatal error C1004: unexpected end of file found Some common types of syntax errors you may get in a C++ program are shown above. Read on to see a brief explanation 1. A semicolon is missing on the line before the one the editor will be pointing to. C++ requires each executable statement to end with a semicolon. The first number you see C2146 is the error message number. You can refer to the manual of the programming environment to see explanations of error messages. Each message is referred to by a unique number 2. An undeclared variable has been found in the program. A variable must be declared before it can be used. If it an identifier that is found in a preexisting library, then that library must be included in the program. The first number you see C2065 is the error message number. You can refer to the manual of the programming environment to see explanations of error messages. Each message is referred to by a unique number 3. An undeclared variable has been found in the program. A variable must be declared before it can be used. If it an identifier that is found in a preexisting library, then that library must be included in the program. The first number you see C2065 is the error message number. You can refer to the manual of the programming environment to see explanations of error messages. Each message is referred to by a unique number 3. The source code has come to an unexpected end. This is probably because you are missing an ending brace somewhere. The first number you see C1004 is the error message number. You can refer to the manual of the programming environment to see explanations of error messages. Each message is referred to by a unique number

  31. BasicsProblem Solving Debugging - Should you correct syntax errors? The compiler will be unable to create an executable file if a program has syntax errors. If you have a syntax error, you must fix the error before you recompile. It does not serve any purpose to recompile without fixing the error. That would be the same as continuing to drive a car with a flat tire in the hope that the tire will fix itself!! In order to see where the compiler thinks the error is occurring, double click the error message and the cursor will be positioned on the line where the alleged error is. Be aware that the error may be occurring one or more lines before the place the compiler points you to. Also, you should know that sometimes one simple error can generate multiple error messages. Once you fix the single error all the error messages will go away.

  32. BasicsProblem Solving Debugging - Warning Errors There are fatal syntax errors and warning errors. Warning errors will not stop the execution of the program. However, a program should not have warning errors either. A warning error means that the potential exists for something to go wrong in the program at some later point of time. This picture is of a low tire pressure warning light from a Cadillac – a warning that something may go wrong as you continue driving down the road

  33. BasicsProblem Solving Debugging - Logical Errors Your program compiles, links and executes fine. However, you get bad results. As an example, you are writing a program that converts from feet to inches. You compile it – hurray! It compiles. Then you run it and try to convert 12 feet to inches. You should get 144 inches as a result. However, much to your misery, you get 1 inch as a result. What is the reason? There is an error in the logic of your program. In this case your program needs to calculate the inches as follows: Result = feet * 12; The number of feet entered by the user multiplied by 12. However, you wrote the statement as follows: Result = feet / 12; You divided instead of multiplying!

  34. BasicsProblem Solving Debugging -Reasons for Logical Errors Logical errors always occur as a result of poor design and planning

  35. BasicsProblem Solving Debugging - Run Time Errors Run time errors are the hardest to detect. These could be errors in the program, in your machine or in the interface of the program with the machine. All possible error sources must be examined although most run time errors result from defective programming

  36. BasicsProblem Solving Group / Pair Practice 1. Break up into groups of 3 or 4 based on the instructions given by your professor Scenario: You have just returned from a great class! You are hungry and decide to bake a healthy, low-fat cake. You reach into your pantry and find a conveniently placed box of cake mix. You turn it over and start to read the directions. 2. Identify the inputs into the recipe. 3. Describe the cake making process. Create a flowchart or write the pseudocode of this process. 4. List the outputs. 5. Describe what could go wrong in the inputs, the process and the output.

  37. BasicsProblem Solving Quick Check QUIZ!

  38. TRY AGAIN!

  39. CORRECT!

  40. BasicsProblem Solving Quick Check QUIZ!

  41. TRY AGAIN!

  42. CORRECT!

  43. BasicsProblem Solving Quick Check QUIZ!

  44. TRY AGAIN!

  45. CORRECT!

  46. BasicsProblem Solving Quick Check QUIZ!

  47. TRY AGAIN!

  48. CORRECT!

  49. BasicsProblem Solving Quick Check QUIZ!

  50. TRY AGAIN!

More Related