Professional Documents
Culture Documents
5 CLS
10 REM
15 END
OR
2 CLS
4 REM
6 END
GARBAGE IN & OUT IN QBASIC
To feed/supply data unto the computer
system using QBasic, we make use of any of
the following two commands:
i. INPUT statement
ii. READ&DATA statement
Press F5 to RUN
OR
To save:
OUTPUT STATEMENTS – Illustration I cont’d
Filename Giving:
Press F5 to RUN
OR
BIO-DATA Quiz
HE was born and brought up in Lagos.
He hails from Kwara.
He settles down in Ondo.
Who is He?
Solution I
5 CLS
10 REM
15 Print “BIO-DATA Quiz”
20 Print “_____________”
25 Print “He was born and brought up in Lagos.”
30 Print “He hails from Kwara.”
35 Print “He settles down in Ondo.”
40 Print
45 Print “Who is He?”
50 END
Solution I - Output
Class Exercise II
• 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
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
(ii) W = u + s3
t2 t 2
INPUT STATEMENTS – Illustration I
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 ,?
HOME TAKE 1
Solve:
(1) Write a QBasic program that
inputs your scores in ACC101,
ACC103 and ACC105. Computes:
i. Their Sums
ii. Their Average
HOME TAKE 3
Given:
Temp = 32 – f +w
5m
…ALGORITHM…
…PSEUDOCODE
…PART 2…