LBEPS Session 11
LBEPS Session 11
Problem Solving
Objectives
Solution:
While writing a pseudocode that accepts two numbers and displays their
sum and product, you need to use the following variables:
nFirstNumber
nSecondNumber
nSum
nProduct
3.1 Let’s Practice (Contd.)
Solution:
While writing a pseudocode that accepts the product name and
quantity as input and displays the total price using the unit prices already
stored in the system, you need to use the following variables:
nProductName
nQuantity
nTotalPrice
In addition, you need to use the following constant:
nPrice
Data Types
Direct assignment:
Assigns values to variables by using the equal to (=) sign.
Syntax:
variable_name = value
For example:
begin
numeric nHeight, nAge, nCounter
character cCode
nHeight = 172
nAge = 35
nCounter = nAge + 10
cCode = ‘XYZ’
end
Assigning Values to
Variables (Contd.)
Accept statement:
Assigns values to variables by using the accept keyword that
gets the value from a user.
Syntax:
begin
…
accept variable_name
…
end
For example:
begin
character cName
numeric nAge
display ‘Enter your name:’
accept cName
Assigning Values to
Variables (Contd.)
Which one of the following variables does not comply with the
variable naming conventions?
1. nQuantity
2. nUnit Price
3. nProductName
4. nCost
Solution:
2. nUnit Price
3.2 Let’s Practice
Solution:
cName
cStreet_Address
customerName
3.2 Let’s Practice (Contd.)
Solution:
begin
numeric nNum1, nNum2, nProduct
accept nNum1
accept nNum2
nProduct = nNum1 * nNum2
display ‘The product of ‘ + nNum1 + ‘ and ‘ + nNum2
+ ‘ is ‘ + nProduct
end
3.2 Let’s Practice (Contd.)
Solution:
begin
numeric nCelsius, nFahrenheit
accept nCelsius
nFahrenheit = (9/5) * nCelsius + 32
display ‘The temperature in Fahrenheit is ‘ +
nFahrenheit
end
Using Operators
* High
+
Low
-
Relational Operators
High
NOT
AND
Low
OR
Logical Operators (Contd.)
Calculate
Discount
Logical Operators (Contd.)
Several tools are available that let you create pseudocodes and
view their output.
You will use a tool called Scratch for this purpose.
Scratch allows you to execute and debug pseudocode.
Scratch has its own syntax and semantics that need to be
followed to ensure the creation of error free pseudocode.
Scratch (Contd.)
Game
Scratch (Contd.)
Bouncing Ball
Just a Minute
Solution:
2. (2+2-2)>(3+3-5)
Summary