Академический Документы
Профессиональный Документы
Культура Документы
Objectives
Example:
Flowchart to display the sum of two numbers
Start
Accept the
First Number
Accept the
Second Number
Stop
Constants
10 15 25
Variables
Example:
Flowchart to display the sum of two numbers using variables
Start
Accept nNum1
Accept nNum2
Display nSum
Stop
Just a minute
Answer:
Variable: Number of letters
Constant: Carrying charge $5
Just a minute
Answer:
Constants: 21, “10, Kingsway Camp”, “Henri”, “185”
Variables: Age, Address, Name
Numeric
Character
Declaring Variables
Example:
Start
Accept nNum1
Accept nNum2
Display nSum
Stop
The first letter of the variable may indicate the data type
used.
The variable name should clearly describe its purpose.
In case of multiple words, the first letter of each word could
be capitalized for better readability.
Using Operators
Arithmetic Operators
Relational Operators
Logical Operators
Just a minute
Answer:
Start
character cltemName
numeric nPrice, nQuantity, nValue
Accept cItemName
Accept nPrice
Accept nQuantity
Stop
Is nNum1 = No
nNum2 ?
Yes
Example:
Accept two numbers and print the larger of the two numbers
Start
numeric nNum1,
nNum2
Accept nNum1
Accept nNum2
Example (Contd.):
A
No
Is Yes
nNum1>nNum2? Display nNum1
No
Display nNum2
Stop
Example:
Print the value of nX only if the value of nX is greater than 10
and nX is an even number
Start
numeric nX
Accept nX
Is
No
nX>10 AND
nX%2=0?
Yes
Display nX
Stop
Example:
Accept the year and then determine whether the year is a leap
year or not. A leap year is one that is divisible by 4, other than
a century year, such as 1900. A century year, which is divisible
by 400, such as 2000, is also a leap year.
To evaluate the given condition, we can interpret this as:
If year is divisible by 4 AND not divisible by 100 OR divisible by
400, it is a leap year.
Start
numeric nYear
Display “Please
enter a year”
Accept nYear
Is
nYear % 4=0 AND
No Display “This is
(nYear % 100 !=0 OR
nYear % 400=0) ? not a leap year”
Yes
Display “This is
a leap year”
Stop
Example:
To decide about the discount percentage on a TV, the sales
person needs to check the type of TV. If the TV is Black and
White [B], the discount will be 5 percent of the selling price. If
the type of TV is colored[C], then he has to verify the size of
TV screen. For 14 inches screen, discount is 8 percent of the
selling price and for 21 inches screen, the discount is 10
percent of the selling price.
Accept cType
Accept nScreen
Is Yes
cType=‘B’? nDiscount=5% of SP
No
Is Yes Is Yes
nDiscount=8% of SP
cType=‘C’? nScreen=14?
No No
Is Yes
nDiscount=10% of SP
nScreen=21?
No
Stop
Exercises
Exercise 1
No
Is Yes
nNum>5? Display “OK”
No
Display “REJECT”
Stop
Exercise 2
Start
numeric nX, nY
Accept nX
Accept nY
Is Yes Is Yes
nX > 100 ? Display “ GOOD”
nX > nY ?
No No
Is No
nY > 100 ?
Yes
Display nY
Stop
Exercise 2 (Contd.)
Exercise 3
Exercise 4
Exercise 5
Summary
Summary (Contd.)