Documente Academic
Documente Profesional
Documente Cultură
VB: i = 10
Pascal: i := 10;
VB: ‘comment
Pascal: {Comment}/(*Comment*)
DECLARING VARIABLES
Program test;
Uses crt;
Var i : integer;
s : string;
c : char;
b : boolean;
r : real; Output?
Begin
i := 0;
i := (i * 3) + 5;
Writeln(i);
End.
USING VARIABLES
Program test;
Uses crt;
Var i : integer;
j : integer;
Begin
i := 7;
j := 3;
i := i + j;
Writeln(i);
End.
SIMPLE PROBLEM EXAMPLE Pascal
Fees are charged to attend the cinema as
follows: Balcony - $8.00, House - $7.00.
Input the number of persons sitting in the
balcony and the number sitting in the house.
Calculate and print the total revenue Declare all
variables, group by
collected. type, separate with
commas
BASIC
• Use of semicolons
• Write vs Writeln (Read)
APPOINTMENT CLOCK
1. A customer pays a monthly fee of $37.50 for the telephone
service and $3.50 per minute for long distance calls.
Input the number of minutes for long distance calls.
Calculate and print the total bill.
2. Input the length and width of a room. Calculate and
print the cost of carpeting the room. One square meter of
carpet costs $45.00.
3 o'clock appointment
Skip
Discuss, share, solve
Present to audience
DECISION MAKING
if - then statem An if - then statement consists of a boolean expression
ent followed by one or more statements.
If condition Then S
Begin
a := 100;
(* check the boolean condition *)
If( a < 20 ) Then
(* if condition is true then print the following *)
Writeln('a is less than 20' )
Else
(* if condition is false then print the following *)
Writeln('a is not less than 20' );
Writeln('value of a is : ', a);
Readln;
End.
Program ifelse_ifelseChecking;
Var
{ local variable definition } IF-ELSE-IF EXAMPLE
a : integer;
Begin
a := 40;
(* check the boolean condition *)
If (a = 10) Then
(* if condition is true then print the following *)
Writeln('Value of a is 10' )
Else If ( a = 20 ) Then
(* else if next condition is true *)
Writeln('Value of a is 20' )
Else If( a = 30 ) Then
(* else if next condition is true *)
Writeln('Value of a is 30' )
Else
(* if none of the conditions is true *)
Writeln('None of the values is matching' );
Writeln('Exact value of a is: ', a );
Realn;
End.
WORD OF CAUTION…
When using more than one
statement in TRUE or FALSE
If i = 10 Then part of IF construct
If j = 10 Then • Enclose statements inside
Writeln(‘i = 10 and j = 10’) Begin-End block and use
semicolons as normal
Else
Writeln(‘i = 10 and j <> If condition Then
10’); Begin
Else statement 1;
Writeln(‘i <> 10 and j <> 10’); statement 2;
End;
Wrong semicolon
Else
(Syntax Error)
Begin
statement 1;
statement 2;
End;
CONDITIONAL PROBLEM EXAMPLE
A technician charges fees as follows: 2 hours or less at $90.00 per hour, up to 6 hours at
$75.00 per hour and over 6 hours at $60.00 an hour. Read the number of hours worked
then calculate and print the fee charged.
Analysis
o 2 scenarios
• Use one If with Else If – Else
• Use three If
OR
Formatting
APPOINTMENT CLOCK
1. A bonus of $150.00 is given to employees who were absent for less
than 4 days in a year. The bonus is added to the salary to arrive
at the total income. If the total income is greater than $2,000.00, a
tax of 5% is deducted. Input the days absent and the salary.
Output the total income, the tax deducted and the income less tax.
2. A customer gets a 10% discount if the total spent is greater than
or equal to $1,000.00. Otherwise, the discount amount is 5% of
the total. Input the price and quantity of items purchased.
Calculate and print the total amount due, the amount of
deduction and the final amount after the deduction.
9 o'clock appointment
Discuss, share, solve
Present to audience