Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture Notes 1/20/05 Pseudocode.  Pseudocode standard which we will follow in this class: - Statements are written in simple English; - Each instruction.

Similar presentations


Presentation on theme: "Lecture Notes 1/20/05 Pseudocode.  Pseudocode standard which we will follow in this class: - Statements are written in simple English; - Each instruction."— Presentation transcript:

1 Lecture Notes 1/20/05 Pseudocode

2  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.

3 How to Write Pseudocode 6 basic computer operations:  receive information  put out information  perform arithmetic  assign a value to a variable or memory location  compare two variables and select one of two alternative actions  repeat a group of actions

4 Receive Information A computer generally gets information in one of the following ways:  From a file  Pseudocode -> “Read”  From a keyboard  Pseudocode -> “Get”

5 Receive Information Examples:  Get file name  Read first line from the file  Get number of students  Read the names of the students from the file

6 Put Out Information A computer generally outputs information in one of the three ways:  Print on a printer  “Print”  Write to a file  “Write”  Display on a monitor  “Display”

7 Put Out Information Examples:  Print “Hello everyone!”  Write “My first homework” to hw_1.txt  Display average_age

8 Perform Arithmetic Either actual mathematical symbols or words can be used:  Multiply Length by Width to compute Area  Area = Length * Width

9 Perform Arithmetic Symbols that will be used in this class: Addition + Subtraction - Division/ Multiplication* Modulus% Parentheses () Also can use the words : Compute and Calculate

10 Example Write the pseudocode for calculating the average age of the students in our class. Prompt the user for number of students Get number of students Prompt for all of the ages Get the ages of all students Add all ages together to obtain Total_Age Divide Total_Age by the number of students Display the result

11 Compare Two Variables and Select One of Two Actions Examples:  If it starts to rain, I’ll go inside the building.  If the car starts, I’ll drive. Otherwise I’ll take a bus.  If you are tall enough, you can go on this ride. Otherwise, you have to wait till next year. Special keywords IF, THEN, ELSE, ENDIF

12 Compare Two Variables and Select One of Two Actions Example: IF Age > 0 THEN Add 1 to number_students ELSE Display “Age must be positive” ENDIF

13 Repeat a Group of Actions Examples:  Shake the vending machine until the candy bar falls down.  Wash your hands until they are clean. Special keywords: WHILE and ENDWHILE

14 Repeat a Group of Actions Example: set Total_Age and Age to zero set number_students to 0 WHILE number_students < 60 get next student’s age and store it in AGE Total_Age = Total_Age + Age add 1 to number_students ENDWHILE display Total_Age

15 Homework for Tuesday  Picture.  Provide the defining diagram, solution algorithm and a desk check for a problem (find in online).  Read Chapter 2 in “C++ Programming”.


Download ppt "Lecture Notes 1/20/05 Pseudocode.  Pseudocode standard which we will follow in this class: - Statements are written in simple English; - Each instruction."

Similar presentations


Ads by Google