Qbasic Unipo Tutorial - 092759-1
Qbasic Unipo Tutorial - 092759-1
a) What does BASIC means? f) How many types of variables are used in QBASIC?
Ans: BASIC is the Ans: Two types of variables are used in QBASIC. They are
abbreviation of Beginner’s called Numeric Variables and String Variables.
All-Purpose Symbolic
Instruction Code. It is a g) What is a constant?
language which was Ans: A Constant is a quantity whose value cannot be changed;
invented to teach students it cannot be changed like a Variable. There are Numeric
a fundamental concept of Constants and String Constants.
programming.
h) What is an array?
b) List any 5 basic rules of a Ans: Such collection of contiguous memory collections is
QBASIC program?
called array which can store data of same type.
Every QBASIC program
should have the following i) What are reserved words or Key words?
rules: Ans: IN QBASIC some words have fixed meanings and cannot
Every program statement be used as a variable, such words are called Key Words or
must begin with line
reserved Words. Such as, IF, THEN, NEXT, FOR
number. .
Every program should end j) What is a Screen statement?
with an END statement. Ans: In QBASIC programming Screen statement is used to
There should be no change the text mode into graphic mode or to change graphic
repetition of lines.
mode into text mode.
Every statement should be
separated by (: ) colon. Say True or False for the following
1. The QBASIC editor ignores comment lines.
c) What is a Flow Chart? TRUE
Flowchart is the pictorial 2. QBASIC is a case sensitive programming
representation of an language. FALSE
algorithm. We can present 3. In QBASIC, variables may be declared with a
the flow of data in visual DIM statement. TRUE
form with a Flowchart. The 4. The PRINT command can be used to print
following symbols are used both numbers and letters. TRUE
in a Flow chart.
5. Line numbers are optional in QBASIC.
TRUE
d) What is an Algorithm?
An Algorithm is a finite set
Question 2
of steps which, if followed,
A. What is a variable?
accomplish a particular
Variable
task. A variable is the name of a location in the computer memory
where a number or a string is stored. In the example above X, Y,
e) What are logical errors? and Dist are numerical variables.For example,
Such errors are called n% is an integer variable
Logical Errors that are x! is a single-precision variable.
caused in a program due to a$ is a string variable.
B. Simplify the following arithmetic operator
B. What does it means I 100 + (1 + 250 / 100) ** 3
when each of the following
types is placed after a variable? II 1.0 + 2.0 * 3.0 / (6.0*6.0 +
5.0*44.0) ** 0.25
! % &
# $
i) single precision variable 100 + (1 + 250 / 100) ** 3
ii) integer variable 100 + (1 + [250 / 100]) ** 3
iii) long variable 100 + (1 + 2) ** 3
iv) double variable 100 + ([1 + 2]) ** 3
100 + 3 ** 3
v) string variable
100 + [3 ** 3]
100 + 27
127
Write a function
that will return a value to this
equation. 1.0 + 2.0 * 3.0 / ( 6.0*6.0 + 5.0*44.0) **
0.25
Input x 1.0 + [2.0 * 3.0] / (6.0*6.0 +
Input y 5.0*44.0) ** 0.25
result = (5 * x + 25 * y) / 1.0 + 6.0 / (6.0*6.0 + 5.0*55.0) **
25 0.25
1.0 + 6.0 / ([6.0*6.0] + 5.0*44.0) **
squareroot = 0.25
SQRT(result) 1.0 + 6.0 / (36.0 + 5.0*44.0) ** 0.25
print squareroot 1.0 + 6.0 / (36.0 + [5.0*44.0]) **
end 0.25
1.0 + 6.0 / (36.0 + 220.0) ** 0.25
1.0 + 6.0 / ([36.0 + 220.0]) ** 0.25
1.0 + 6.0 / 256.0 ** 0.25
Write a program to input the 1.0 + 6.0 / [256.0 ** 0.25]
length, width, and high of wall 1.0 + 6.0 / 4.0
then compute the number of 1.0 + [6.0 / 4.0]
bricks in wall ,if you know the
brick sides is (24x8x12cm). 1.0 + 1.5
2.5
Solution
REM Program for compute C. Write a program to compute the real roots of a
bricks number equation AX2+BX+C=0
Input "the wall length"; L Solution
Input "the wall width"; W REM Program for compute roots of equation
Input "the wall high"; H Input A,B,C
V=L*W*H X1=(-b+ SQR(b^2-4*a*c)) /(2*a)
N=V/(24x8x12) X2=(-b-SQR (b^2-4*a*c)) /(2*a)
?"bricks number is"N Print" the first root is";X1
Print “the second root is";X2
2m C= 2*pi*r
arks Print"the circumference is";C
‘Arith
metic Question 6
with
Variabl Write a program to compute the summation for even
es numbers from 0 to N.
LET
AGE = Solution Input N S=0 : I=0 5 S=S+I I=I+2 If I < N then 5
23
PRINT Print S
"You
have
lived
more Write a program to input any number then determine if
than", the number is odd or even.
AGE * Solution
365,
“days"
Input X
END If (x/2)=int(x/2) then print "x is even"
If (x/2) <>int(x/2) then Print "x is odd" Or
Input X If x mod 2 =0 then
print "x is even" ci) X% = 4 `the value of X is 4
If x mod 2 <> 0 then print Y% = 2 `the value of Y is 2
Z% = 6 `the value of Z is 6
"x is odd"
? X% * Y% * Z% `prints the result for X * Y * Z
The Civil Engineering Student
Association is preparing for its ii) X% = 5 `the value of X is 5
yearly fund-raising awards. CESA Y% = 6 `the value of Y is 6
members raise money by selling Z% = 2 `the value of Z is 2
magazine subscriptions. Each Result = X% * Y% * Z% `Multiplies the value of the
subscription costs $25. Each CESA integers
member who raises at least $1000 PRINT result `prints the result for X * Y * Z
receives an award plaque and a $50
gift certificate. Each member who iii) INPUT a%, b%, c%
sells less than $1000 but are at least
$500 gets only an award plaque. iv) INPUT x%, y%, z%
Those whose sales are less than 500 PRINT x%, y%, z%
receive only a certificate thanking
them for their participation. Write a v) INPUT x%, y%, z%
program that prompts the user to PRINT “The product is:” x% * y% * z%
enter a member’s name and the
number of subscriptions that
member sold. The member’s total
sales should be calculated. The
write BASIC statements demonstrating the following in-built
program should then display the
total sales along with the type of
award that member will receive.
Question 7
a. Machine Language:-
Consist mainly of bits and codes
Assembly Language:-
Combination of codes and alphabets
Low Level Language:-
Alphanumeric Nemomics, e.g C
High Level Language:-The
human language e.g QBASIC,
FORTRAN, JAVA, C++
bi) False, commentsonly
make the program more readable
ii) Control (if)
iii) True
iv) True
v) True
functions: