Basics Menu Learning Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . page 2 Problem Solving Steps in the Problem Solving Process . . . . . . . . . . . . . . . . . . page 3
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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
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.
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.
IPO Charts – Input Process Output Charts
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
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.
IPO Charts can be created for any program whether it involves the
Instructions are executed sequentially, one after the other. No instruction is skipped or repeated
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
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”
output “no luck, dude!”
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
Flowchart Symbols – Start/Stop
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!
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!
Language, Syntax and Semantics - Statements, Identifiers, Punctuation marks
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
Language, Syntax and Semantics - User Defined Variables
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.
Debugging - Sample Syntax Errors
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
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.
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
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!
Debugging -Reasons for Logical Errors
Logical errors always occur as a result of poor design and planning
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
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.
on completing Basic problem solving