Professional Documents
Culture Documents
UCC ProgTechniques-Lecture04
UCC ProgTechniques-Lecture04
Welcome to lecture 4. In this lecture we will examine the process of writing pseudocodes as well as the differences and similarities between flowcharts and pseudocodes.
Pseudocode Concepts Pseudocode is also known as false code. It provides a way of writing an algorithm in a way that is similar to that of writing actual programming statements. It is important to note however, that pseudocode will not execute within a programming language as it does not following the exact syntax (rules) of the language. (ie Pseudocode uses a loose syntax)
I/O operations (PRINT) To send output to the screen, the following terms are often used: Display, Print, Show or Write To display data exactly as it is typed, we use the double quotes eg Print Computer is Black this would display the enter phrase Computer is Black onto the screen We can also display the content of a variable eg assuming the variable name has the value Jane, then Print name would display Jane onto the screen The command Print name + -The Computer is Black would therefore now display the following on the screen: Jane The Computer is Black Assuming variable x has the value 5, and variable fn has the value Mary then what would we see on the screen given the following command?: Write My mother is + fn + and her age is + x Ans: My mother is Mary and her age is 5
1|P age
We will now look at some problems as well as the pseudocode solutions for the problems. Several of the problems were already solved using flowcharts. Hence this exercise will enable you to compare the pseudocode solutions with the flowchart solutions so that you are better able to appreciate the similarities and the differences.
Pseudocode Examples and Solutions Problem 01 Write a pseudocode algorithm that will accept 2 numbers and will display the product of the two numbers with an appropriate message onto the screen
Solution 01
Declare x, y as Integer Print Enter num1: Read x Print Enter num1: Read y Print The product of + x + and + y + is + x * y
2|P age
Solution 02
Declare quantityInFeet, quantityInInches as Integer Print Enter quantity in feet units: Read quantityInFeet quantityInInches = quantityInFeet * 12 Print The quanity + quantityInFeet + converted to inches is + quantityInInches
3|P age
Solution 03
Declare price, gctRevenue, totalPrice as Float constant GCT = .165 Print Enter item price: Read price gctRevenue = price * GCT totalPrice = price +gctRevenue Print GCT revenue earned is + gctRevenue Print Total price to be paid is + totalPrice
The pseudocodes shown here all depict the use of the sequence control stucture
4|P age