Lecture Slides 2
Lecture Slides 2
Operators in BASIC
An operator is a symbol which tells the computer to perform certain mathematical and
logical calculation.
Types of operator
Mathematical Operators
1.Relational Operators
2.Logical Operators
1. Mathematical Operators
3. Logical Operator
OR Logical OR
The commonly used QBASIC statements are: LET, PRINT, INPUT, CLS, END and REM. In
QBASIC, the LET statement is used to assign a value to a variable. The PRINT command is
used to display any message or value on the screen. The INPUT statement in QBASIC is used
to accept the data item from the user. REM statement is a non-executable statement and
stands for remarks. CLS statement is used to clear the screen. END statement is used to end
the program execution.
INPUT STATEMENTS
These are statements that are
used for feed/supply data unto
the computer system.
• Two Types:
• Input Method
• Read & Data Method
INPUT STATEMENTS cont’d
INPUT Method
This is used where the program given is a
closed problem (e.g. values not specified).
e.g. INPUT A
OR
INPUT “Enter value for A: ”, A
Here the value of A is expected to be inputted.
cont’d
Programming Example
Code in QBasic to solve:
(i) Z = x2 + w
y
(ii) F = b2
4ac
INPUT STATEMENTS – Illustration I
Solutions
5 CLS
10 REM
15 INPUT “Enter value for X: ”, x
20 INPUT “Enter value for W: ”, w
25 INPUT “Enter value for Y: ”, y
30 Let Z = ((x*x) + (w/y))
35 PRINT “The answer is: ”, Z
40 END
INPUT STATEMENTS – Illustration I - Output
INPUT STATEMENTS – Illustration II
Solutions
5 CLS
10 REM
15 INPUT “Enter value for A: ”, a
20 INPUT “Enter value for B: ”, b
25 INPUT “Enter value for C: ”, c
30 Let F = ((b^2) / (4*a*c))
35 PRINT “The answer is: ”, F
40 END
INPUT STATEMENTS – Illustration II - Output
INPUT STATEMENTS cont’d
READ Method
This is used where the program given is an open problem (e.g.
values specified).
e.g. READ A
DATA 7
OR
READ A, B, C
DATA 7, 15, 87
Solutions
5 CLS
10 REM
15 READ t, u, r
20 DATA 15, 210, 11
30 Let V = (t + (u-r))
35 PRINT “The answer is: ”, V
40 END
INPUT STATEMENTS – Illustration I - Output
INPUT STATEMENTS – Illustration II
Solutions
5 CLS
10 REM
15 READ u, s, t
20 DATA 210, 14, 15
30 Let W = ((u/(t^2)) + ((s^2)/(t^2)))
35 PRINT “The answer is: ”; W
40 END
INPUT STATEMENTS – Illustration II - Output
Did you notice any different in the outputs (this slide page 42 – using PRINT with
Semicolon ; and the previous one, slide page 40 – using PRINT with Comma ,?
OUTPUT STATEMENTS
These are statements that are used
to fetch/retrieve/show to screen,
inputted or stored data from the
computer system.
Press F5 to RUN
OR
Press F5 to RUN
OR