Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2 – part a Brent M. Dingle Texas A&M University

Similar presentations


Presentation on theme: "Chapter 2 – part a Brent M. Dingle Texas A&M University"— Presentation transcript:

1 Chapter 2 – part a Brent M. Dingle Texas A&M University
CPSC Pascal Chapter 2 – part a Brent M. Dingle Texas A&M University

2 Chapter 2 Some history of Computer Science
Some basic concepts of programming A short introduction to Pascal Some style conventions for programming.

3 Back in the day You ever wonder why there are some computer stores named Babbages ? Around 1822 Charles Babbage developed an analytical engine. Which was very similar in design to today’s computers. This would be a good topic to investigate on your own.

4 Ada Augusta Ada Augusta was friend and colleague to Charles Babbage.
She was the daughter of the poet Byron and eventually the countess of Lovelace. She is often referred to as the first computer programmer.

5 Algorithms An algorithm is a set of instructions that leads to the solution of a problem. Synonyms for algorithm are: Recipe Method Directions Routine

6 Program A program is an algorithm expressed in a language that a computer can understand. Languages which a computer can understand are thus called programming languages.

7 Word History – algorithm
As a side note, the word algorithm was once closely related to the word algebra. This is interesting only to the extent that programming languages can be related to algebraic spaces (in simplistic terms).

8 Expressing Algorithms
There are a number of ways to express an algorithm. Sometimes algorithms are expressed in mathematical terms, sometimes in plain English, sometimes in pseudocode, and there are other ways. If an algorithm is ‘good’ then no matter how it is expressed it should be possible to show that it is equivalent (i.e. the same) and successfully solves the proposed problem regardless of how it is expressed.

9 Sample algorithm to count red cars in a list.
Get the list of cars. Set a counter to zero. For each car in the list do the following: Get the color of the ‘current’ car. If the color is red then add 1 to the counter. Declare the number of red cars to be the value of the counter.

10 Discussion of algorithm - input
Notice the algorithm requires input or data – specifically it requires that a list of cars be given along with their color. Most algorithms will require some form of input or data on which to perform some type of operation.

11 Discussion of algorithm – output
The algorithm also provides feedback to the user – specifically it states the number of red cars found in the list. This feedback is referred to as output. Most algorithms will provide some form of feedback, or output. Usually this feedback is an answer to a problem or question.

12 Discussion of algorithm – termination
Notice that the above algorithm eventually ends – when it gets to the end of the list of cars. Not all algorithms end. Algorithms that do NOT end are sometimes referred to as partial algorithms. Algorithms that end are referred to as total algorithms.

13 Program Design – 2 Phases
Problem solving phase Implementation phase

14 Problem solving phase This is where the algorithm to solve the problem is developed. This may be done in a variety of ways, but the general rules for doing so stay the same.

15 Problem solving phase Number One Rule
Be certain the task is completely and precisely specified (i.e. the problem is well defined). Identify the expected input (where it comes from, in what form is it, etc) to the program. Identify the desired output (form, content, restrictions, etc) of the program. Understand exactly what must be done with/to the input to produce the output.

16 Problem solving phase 3 Steps
If you follow the Number One Rule you will find the below 3 steps of the problem solving phase easier to perform. Problem Definition Algorithm Design Desktop Testing

17 Problem solving phase Step 1 – Problem Definition
Determine if the problem is well defined (and if a solution exists). If it is not gather the necessary information to make it well defined: Ask questions Collect data Restate the problem etc. Write down the problem as it is understood !

18 Problem solving phase Step 2 – Algorithm Design
State what processing needs to be done. Identify variables needed, substeps necessary, etc. Write it down in a step-by-step form: Flow chart English Pseudocode Whatever works for you. DOCUMENT THIS PROCESS !!!

19 Problem solving phase Step 3 – Desktop Testing
Test your algorithm. Do this In your head On a piece of paper Using someone else, etc. Conduct multiple tests ! Try to find cases where the algorithm will NOT work. Repeat steps 2 and 3 (and 1) as often as needed until a ‘good’ algorithm is created.

20 Implementation phase 2 Steps
Coding the algorithm as a program. Testing the program.

21 Implementation phase Step 1 – Coding
At this point, if you did the problem solving phase correctly, you have a ‘good’ algorithm. All you need to do is write the algorithm in a language that the computer can understand, in our case the language will be Pascal. This step takes practice, practice, practice. =)

22 Implementation phase Step 2 - Testing
Test your program ! Test it thoroughly ! Run it using various data/input. Try to get it to break. Ask someone else to test it. Document all cases that are known to cause it to fail – fix them (if possible).

23 Sample Problem Pretend someone tells you: “I want a program that will take the first derivative of my math equations.” What questions would you ask to aid in achieving the Number One Rule? (think about this before going to the next slide)

24 Sample problem - some questions
What type of equations? Polynomial? Trigonometric? How many variables? Derivative with respect to which variable? Will fractions be allowed as coefficients? Are any variables raised to fractional powers? Or to roots (e.g. square root of x)? Can you think of any more… ?

25 Moving on… Now we will begin a brief discussion on the Pascal language. We will look at its history and some of the commands it uses.

26 Pascal – the language Pascal is a high level, general purpose language. It was developed by Niklaus Wirth (and colleagues) in the late 1960s and early 1970s. Notice the dialect of Pascal we will be using is Turbo Pascal, which is slightly different than standard Pascal.

27 Pascal – the name Pascal the language was named after the mathematician Blaise Pascal. While Blaise Pascal did not create a computer, he did create a rather sophisticated adding machine. He also contributed a bit to the development of Math – ever heard of Pascal’s triangle?


Download ppt "Chapter 2 – part a Brent M. Dingle Texas A&M University"

Similar presentations


Ads by Google