Professional Documents
Culture Documents
OVERVIEW:
There are two facts that dive human reasoning and thoughts. Basically, human beings cannot
speak or write in computer language and computers cannot speak or write in human language,
therefore an Intermediate language had to be developed to allow people to communicate with
the computers. These intermediate languages are known as programming language which allows
computer programmers (Users) to direct the activities of the computer. Thus, programming
languages are structured around unique set of rules that direct the computer to perform a specific
task. A typical instruction in a programming language consists of two parts:-
1. An operation code
2. Some operands
The operation code tells the computer what to do such as add, subtract, multiply and divide. The
operands tells the computer the data items involved in the operations. E.g. considering the
instruction a = b + 5, the = and + are operation codes while a, b and 5 are operands. Some
computer uses many types of operation codes in their instruction format and may provides several
methods for doing the same thing.
Summary:-
An input instruction directs the computer t accept data from a specific input device and store it in
a specific location. An output instruction tells the computer to move a piece of data from a
computer storage location and record it on the output screen. All of the basic arithmetic operations
can be operated by the computer. Branch instruction causes the computer to alter the sequence
of execution of instruction within the programme. Logic instructions allow the computer to change
the sequence of execution of instruction, depending on conditions built into the programme by the
programmer.
Programming languages which means the primarily means of human vs computer communication
which have evolved the early stage programmers enter instruction into the computer in a language
similar to that used in the application software. Computer programming language can be classified
into the following categories:
i) Machine Language
ii) Assembly Language
iii) High level symbolic Language
iv) Very high level symbolic Language
Summary:-
Machine language programmes allows the programmer to take advantage of all the features and
capabilities of the computer system for which it was designed. A machine language is computer
dependent. Thus, it is the first generation computers language.
Assembly language is as well known as the low level programming language. This allows the
programmer to remember the operations codes easily than when expressed strictly as binary
numbers. It must be translated into a machine language using a system software programme
called an assembler. They are the second generation computers languages.
High level language are machine independent, i.e. it can run on a variety of computers. Its
instructions do resemble English language statements and the mathematical symbols are the
symbols used in ordinary mathematics. Examples are fortran, basic, cobol, pascal, algol, ada and
pi/i. They are the third generation computers language. Very high level language are the fourth
generation computers language that allow the user to specify what they require, rather, than
describing the procedures by which requirements are met. It also offers the user an English-like
set of commands and simple control structures in which to specify general data processing or
numerical operations.
Basic programming language is an easy- to-go use friendly language whose instructions
resembled elementary algebraic formular augmented by certain English Language keywords
such as input, read, print, Goto, if, then and so on.
DEFINITION:
QBASIC is one of the many versions or dialects of the basic language which retains the user
friendly environment characterizes by the implementation of basic language. This means that
QBASIC runs on the windows to facilitate the storing of coded programmes in the secondary
memory for retrieval with the ability to support real integer and string data typed. It also contains
necessary tools that are required for the manipulation of matrices, graphs and images.
The story goes that the students were having difficulty learning FORTRAN so the professors
decided that creating a language from scratch would be an excellent teaching tool for the
students. The result was BASIC, which was eventually placed in the public domain.
On the contrary, QBASIC is a programming language invented and modified by Bill Gates and
Hitler designed to make a program that would launch missiles from outer space in hopes of
destroying the cancer that is killing /b/. Unfortunately, since the earliest versions of QBASIC could
only display text, they had to settle for a word processing program that could WRITE SHIT ON
YOUR SCREEN instead.
Bill Gates and Paul Allen had something different in mind. In the 1970's when M.I.T.S.'s Altair
personal computer was being conceived Allen convinced Gates to help him develop a Basic
Language for it. When M.I.T.S. answered with interest, The future of BASIC and the PC began.
Gates was attending Harvard at the time and Allen was a Honeywell employee. Allen and Gates
licensed their BASIC to M.I.T.S. for the Altair. This version took a total of 4K memory including
the code and data used for a source code. Gates and Allen then ported Basic to other various
platforms and moved back to their hometown of Seattle where they had attended grade school
together. It was at this time that the Microsoft Corporation began it's reign in the PC world.
LOADING QBASIC
Loading QBASIC is very easy depending on your computer. It is commonly found in all
computers except vista. But one can purchase it from CD ROM and install it.
Method: 1
Loading through Ms. DOS
Click start button
Click run
Type cmd and select Ok
Type cd\ and press enter
Type qbasic and press enter key ones
Note:
If Ms. DOS display invalid command, it means QBASIC is not installed on your computer. But if
QBASIC screen pop-up appear, two choices will be shown.
Alternatively:
Method: 2
Loading through Windows Desktop
Double click on QBASIC or SHORTCUTS TO QBASIC
Double click QBASIC and choose to run if available
In addition, one will find the menus of QBASIC display after the title bar.
QBASIC MENU
Diagram:
Below the menu is the blue painted area called the process. QBASIC process is the desktop
where the user operates the demand and coded programmes but the user will not see the
outcome / result displayed. It is expected that the user sees the outcome of his coded programme
on the Black & White screen called the output.
Down below the process screen (blue painted) space is the line of Immediate
IMMEDIATE LANE:
Diagram:
The immediate line cannot process any data, therefore it is no go area. Nothing works there. It
is useless going there to type or code your program.
OUTPUT SCREEN
Diagram:
At the output screen the user is prompt to press any key to return back to the process when the
user have finished viewing the outcome of his/her programme via the message Press any key to
continue
1. Rem Statement:
Rem is a special keyword known as remark. Sometimes when a programmer write long
programme, he or she will like to leave notes inside their programme so that they can remember
why they did certain things. So to leave a note that explains certain things, use remark. QBASIC
knows that when it sees Rem it does not have to do what you wrote after it on that line.
2. Cls Statement:
Cls means clear screen. If you run a programme from QBASIC, everything that was on the screen
before you started QBASIC will show (i.e. written on the screen), that is why we need the keyword
cls.
3. List Statement:
List statement is used to examine the programme and correct errors before it is executed. This is
because QBASIC displays and execute programmes line-by-line according to the numbers used.
4. Print Statement:
Print is one of the most useful and powerful commands in QBASIC that causes the information
typed between the double quote ( ) to be sent to the screen or visual display unit end result
where the users sees or runs the programme to get the final results.
In addition, when Print is typed on the line number without double quote (i.e. line number bearing
print), QBASIC will provide one empty space between such line and the next line at the output.
5. Input Statement:
This statement allows information to be typed using the keyboard of the computer in generating
the needed data before the final answer will appear at the output. The computer executes this
input statement by using a representative question mark ( ? ) waiting for the data (i.e. figures) at
the output screen to be typed in.
7. Let Statement:
This statement will cause the arithmetic expression on the right hand side typed before an equal
sign ( = ) be stored as the result (answer that belongs to) the variable at the left of the equality
sign.
8. End Statement:
This statement stops the execution of the programme. That is to say, end statement tells the
computer that the written/coded programme done on QBASIC blue painted space (process) has
come to an end.
9. Dim Statement:
Dim means dimension. It is the statement used to reserved different locations of stored values
when many locations are involved in a programme by using just one variable.
ELEMENTS OF QBASIC
Every programming language consists of some important elements which are required to make a
programme be executed. Therefore elements are those typing that are required to make a coded
programme function properly, before running it to see your answers. These elements can involves
character sets, keywords, constants, variables, operators and expressions.
CHARACTER SETS:
These are typing required when coding a programme which can be type in alphabets both in
smaller and capital letters, numbers that ranges 0 to 9, and infinity. Special symbols and signs
are also part of character set in which each performs meanings and various functions and makes
your program of standard.
Examples of special symbols and signs used as a character set in QBASIC is shown below:-
Signs Signs Signs Signs
+ > s
- < %
* , ( $
/ ; ) !
\ : . #
^ = ? Blank space
CONSTANTS
They are the data or the values stored inside variable coded on qbasic program that cannot
changed during the program execution except for numbers. The data may be a letter, words,
numbers, special symbols but they are stored inside a variable name which QBASIC will not
changed the way you type it, except it is numbers. Why? Because numbers when stored as
constants, QBASIC can perform mathematical calculation on it.
In QBASIC coding of programme, constants are grouped into two broad headings:
a) String Constant
b) Numeric Constant
String Constants:
It is a letter, words, numbers, combination of letters with numbers or special symbols enclosed in
double quotes ( ) stored inside a variable name in which mathematical operations cannot be
done on it. It can also be used to express statement on a program typed to QBASIC. For instance,
B, Apple, Symbol No. 10208, Welcome to QBasic World!!!, etc.
Numeric Constants:
Numeric constant refers to a number with or without decimal point, stored inside a variable name
in which mathematical operations can be done on it. Numbers written in thousands to QBASIC
will not consists of separator (,) which also can not be enclose in double quotes. Generally,
mathematical and logical operations can be done on them e.g. 101, 105.50, 720, 45603, etc.
VARIABLE:
In QBASIC, a variable is a place on the computer memory which has a name and stores data
temporarily. On the otherhand, a variable is an entity that stores data needed to be used in a
program. Each program defines different number of variables. The value of a variable can be
change during the execution of the program. On declaring (i.e. typing) a variable, one will need
to determine the type of data which QBASIC will stored inside the variable.
String Variable:
String variable stores string data (i.e. quotation statements) with a string variable name declare
on that same line whereby mathematical and logical operations cannot be done on it as directed
by the declaration symbols of dollar sign ($).
Numeric Variable:
A numeric variable stores number data inside it variable name that mathematical and logical
operations can easily be done on it as directed by its declaration symbols typed.
For integers, it stores short whole number with the sign of percentage (%) typed to the variable
name. Long integer stores large range of whole numbers with ampersand (&) declaration, for
single precision, it stores single decimal numbers with or without declaration of exclamation mark
(!) and for double precision, it stores large decimal numbers declares with the use of hash sign
(#)
Arithmetic operators:
These are all the general mathematical signs used to perform simple and practical mathematical
calculations like addition, subtraction, division, multiplication, exponents, etc
Example 1:
Operation Operators Example Results
Addition + 5+8 13
Subtraction - 86 2
Multiplication * 5*4 20
Division / 8/2 4
Integer division \ 9\2 4
Exponential ^ 4^3 64
Modular division Mod 7 Mod 3 1
Relational Operators:
They are operators used to perform comparison on two values of the same typed statements.
E.g.
Operators Relation Examples
= Equal to A = B, A$ = B$
> Greater than A > B, CAT > RAT
< Less than A < B, CAT < CAT
>= Greater than or equal to A >= B, X$ >= Y$
<= Less than or equal to A <= B, X$ <= Y$
<> Not equal to A$ <> B$, X <> Y
Logical Operators:
It combine two or more relational expression to evaluate a singe value as true (non zero answer)
or false (zero answer). For example:
And operation:
When all the results (statements) returned are true.
Statement 1 (for P) Statement 2 (for Q) Results (P & Q)
F T F
T F F
F F F
T T T
Or operation:
It return true if any one of the relational statements expressions return true. E.g.
Statement 1 (for A) Statement 2 (for B) Results (A & B)
F T T
T F T
T T T
F F F
Not Operation:
It operates on one statement operand and returns true if the logical statement returns false. E.g.
Statement 1 (for A) Result (for Not A)
F T
T F
STRING OPERATOR
String joins two or more than two string data (sentences) together to form a simple or compound
sentences.
E.g.
String data (for A$) String data (for B$) Results (A$ + B$)
Wel come Welcome
50 45 5045
The plus sign (+) is used as the string operator as the act of combining two strings together
which can also be known as as concatenation.
EXPRESSION
It is the combination of operators, constants and variables that is evaluated to get a result. The
result is string data, numeric data or logical value and can be stored in a variable. E.g.
(A + B) > C
A >= B + C
u = t + etc
Note, expression can come from any side of the mathematics, some from linear simultaneous equation, algebra,
statistics, trigonometry, etc.
A=LXB A=L*B
P = 2(L+B) P = 2 * (L + B)
I = (P X T X R)
100 I = (P * T * R)/100
V = 4 pi r3
3 V = 4/3 * (PI * R ^ 3)
V = r2h V = PI X r ^ 2 * h
ORDER OF OPERATION
The order of operations is the order (due process) in which all algebraic expression should be
simplified.
For instance on QBASIC:
Parenthesis
Exponents (and Roots)
Multiplication and Division
Addition and Subtraction
[PEMDAS]
Alternatively:
Brackets
Exponentiation
Division and Multiplication
Addition and Subtraction
[BEDMAS]
Note:
Be aware that multiplication does not always come before division, and addition does not always
come before subtraction. For example.
3X35+2
Your working will always starts from left to right.
You work like this. First notice that there is no parenthesis or exponents, so we move to
multiplication and division. Theres only one multiplication, so we do that first and end up with 9
5+2
Now we move to addition and subtraction, so finally we do the subtraction to get 4 + 2 and finally
the addition to give 6. Thus the order becomes: [PEDMSA]
LETS PRACTICE
ALWAYS RUN YOUR PROGRAM (BY PRESSING F5 KEY) AT THE END OF YOUR CODED
PROGRAM TO QBASIC BLUE PAINTED SPACE.
1. Write or code QBASIC program that demonstrates the steps or procedures involve to prepare an
office tea breakfast with the results shown at the output screen.
Solution:
5 REM Example 1
10 REM Coding a program that illustrate
15 REM how to prepare office tea breakfast
18 CLS
20 LET A$ = Wash the kettle
25 LET B$ = Add clean water into the kettle
30 LET C$ = Heat the kettle for 15 minutes
35 LET D$ = Check if the water is boiling
40 LET E$ = If the water boils after 15 mnutes
45 LET F$ = Add coffee, sugar and milk
47 PRINT
49 PRINT Directives to prepare office tea
50 PRINT ..
53 PRINT
55 PRINT The first procedure is to ; A$
60 PRINT The next procedure is to ; B$
63 PRINT The next procedure is to ; C$
65 PRINT The next process is to ; D$
68 PRINT The next process is to ; E$
70 PRINT The last procedure is to ; F$
75 END
If Month = 11, 12, 1 or 2 (November, December, January, or February), then the word, Cool
Season appear on the screen. If month = 3, 4, or 5 (March, April, or May), then the words Hot
Season appear on the screen. If month is any number from 6 to 10 (June to October ), then the
words Wet Season appear on the screen.
Solution:
Alternatively:
3. Write a program that asks for a score then prints the grade assigned to the score.
Solution:
DIM Score AS INTEGER
CLS
PRINT
INPUT "Enter The Test Score: ", Score
PRINT
SELECT CASE Score
CASE IS >= 97
PRINT "Grade A+"
CASE 93 TO 96
PRINT "Grade A"
CASE 90 TO 92
PRINT "Grade A-"
CASE 87 TO 89
PRINT "Grade B+"
CASE 83 TO 86
PRINT "Grade B"
CASE 80 TO 82
PRINT "Grade B-"
CASE 77 TO 79
PRINT "Grade C+"
CASE 73 TO 76
PRINT "Grade C"
CASE 70 TO 72
PRINT "Grade C-"
CASE 67 TO 69
PRINT "Grade D+"
CASE 63 TO 66
PRINT "Grade D"
CASE 60 TO 62
PRINT "Grade D-"
CASE ELSE
PRINT "Fail"
END SELECT
4. Write a program with the comment: I am 11 years old, soon I will grow up and be 25.
Solution:
CLS
AGE = 11
PRINT I am; AGE; years Old.
AGE = 25
PRINT But I will grow and soon will be ; AGE
END
5. Write a program that display todays date in the date format of dddd/mmm/yyyy
Solution:
CLS
INPUT Enter a year; year
INPUT Enter a day; day
INPUT Enter a month; month
a) a = 3+ 3
4+4
E.g.
LET a = (3+3)/(4+4)
b) x = (a b)(a c)2
E.g.
LET x = (a b) * (a c) ^ 2
1
/3
c) f = a
b
E.g.
Let f = a ^ ( 1 / 2 ) / b ^ ( 1 / 3 )
d) d = (8 x2) - (4 x 2 1)
(x 9) x3
E.g.
Let d = ((8 x ^ 2) / ( x 9) (( 4 * 2 1) / (x ^ 3)
Solution:
REM
Author: Sir Isaac
Class: Computer science 404
Date: 07/09/2011
Purpose:
This program will calculate the Area and circumference of a circle
after receiving the value for the radius from the user.
(a) Start
CLS
(b) Declare variable, define known values
DIM radius AS DOUBLE Radius
DIM PI AS DOUBLE Pi
DIM Circumf AS DOUBLE Circumference
DIM Area as DOUBLE Area
PI = 3.141593
COLOR 9
(c) Get Required data from user
PRINT This program calculates the Area and Circumference of a circle
INPUT What is the radius of the circle; radius
(f) Stop
y = a(b c)2
d+2
where a = 2, b = 8, c = 4 and d = 2
Solution:
5 REM
10 CLS
15 a = 2
20 b = 8
25 c = 4
30 d = 2
35 e = a * (b c) ^ 2
40 f = d + 2
45 y = e / f
50 PRINT Your answer is ; y
55 END
Solution:
x = -b b2 4ac
2a
Where 3x2 + 8x 16 = 0 find x.
Solution:
11. Write a program to play a game of knowing how many days are there in a week?
Solution:
CLS
Score = 0
PRINT How many days are there in a week?
INPUT a
IF a = 7 THEN GOTO 2
PRINT Wrong answer!
PRINT To try again press y
INPUT a$
IF a$ = y THEN GOTO 1 ELSE END
Score 10
PRINT Its the right answer!
PRINT Your Score is now; Score; !
PRINT Thanks for playing
END
Solution:
REM Example 5.6
-------------------------------------------------------------
Compute the area of a rectangle
Length L and width W
--------------------------------------------------------------
DIM L AS SINGLE
DIM W AS SINGLE
DIM Area AS SINGLE
CLS
INPUT Length of the rectangle is ; L
INPUT Width of the rectangle is ; W
Area = L * W
PRINT The area of ; L; by; W; rectangle will be ; Area
END
13. You have a Canteen Business and you want to create an incentive bonus for your staff that meet
the stipulated target. Write a program that illustrate these statement.
Solution:
14. Alternatively, the Canteen management held meeting and agreed that where the incentive to the
staff does not meet the target, there will be redundancy. Re-write the program to show the
decision of the management.
Solution:
Solution:
CLS
INPUT Date Number is ; dayNumber
SELECT CASE dayNumber
CASE 1
PRINT Monday
CASE 2
PRINT Tuesday
CASE 3
PRINT Wednesday
CASE 4
PRINT Thursday
CASE 5
PRINT Friday
CASE 6
PRINT Saturday
CASE 7
PRINT Sunday
CASE ELSE
PRINT How many days in your week?
END SELECT
MATHEMATICAL EXPRESSION
16. Write a programme that will show a list of times table number of 3s e.g. 3 x 1 = 3, 3 x 2
= 6, etc.
Solution:
5 CLS
10 REM Compute times table numbers of 3
15 INPUT Enter any number for ; n
20 FOR I = 1 to 12
25 PRINT n; x; I = n * I
30 NEXT I
35 END
17. Write a program that generates multiples of 5 between 5 and 500, displaying their sum and
products at the output screen.
Solution:
5 CLS
10 REM Program to generate multiples of 5
15 between 5 and 500
20 Calculates their sum and products
30 displayed their results
40 SUM = 0
50 PRDT = 1
60 FOR L = 5 TO 500 STEP 5
70 SUM = SUM + L
80 PRDT = PRDT * L
85 Display the current values of L, SUM AND PRDT
90 PRINT L, SUM, PRDT
100 NEXT L
110 display the final values of L, SUM and PRDT
120 PRINT L, SUM, PRDT
130 END
Solution:
19. Given that the goal you set for your retirement in your current employer is N850,000. You decide
to make deposit of your pension payment in advance to ECO BANK PLC with payment of N1,000
each month with the interest of 5.0% interest charge. Write a program to illustrate the above
comments, showing the number of years it will take to complete the retirement task.
Solution:
CLS
REM Program to meet pension retirement goal
DIM Goal AS DOUBLE
DIM Interest AS DOUBLE
DIM Payment AS DOUBLE
DIM Years AS INTEGER
Dim Balance AS DOUBLE
Balance = 0
PRINT So you want to put some money aside for retirement, hmmmm.
INPUT How much money do you need to retire; Goal
INPUT How much money will you contribute every year; Payment
INPUT Interest rate in % (e.g. use 5.0 for 5.0%) will be; Interest
20. Write a menu list program that allow the user to make a wish/choice in a statistical analysis coding
system.
Solution:
CLS
PRINT Which Statistical Analysis do you wish
PRINT
PRINT 1. Compute an Average
PRINT 2. Compute a Standard Deviation
PRINT 3. Find the Median
PRINT 4. Find the Smallest and Largest data value
PRINT 5. Plot the Data
PRINT
PRINT 0. Quit/Return to preview menu
DO
INPUT Enter your choice ( 0 through 5); a%
Use SELECT CASE or IF to check the user
Input, and do the work that has been requested.
LOOP UNTIL a% = 0
MATHEMATICAL CONTINUES
21. Suppose we are given ten rectangles and required to find the area of each rectangle. Given below
is a QBASIC program that reads the length and breath of each rectangle, finds its area and prints
the areas.
Solution:
5 CLS
10 REM Program that reads the length L and
15 breath B of ten rectangles
20 calculates the area of each rectangle
30 and prints the result
40 KANTER = 0
50 PRINT Please enter the values of L and B
60 INPUT L
65 INPUT B
70 Area = L * B
80 PRINT L, B, Area
90 KANTER = KANTER + 1
100 IF KANTER > 10 THEN 120
110 GOTO 50
120 END
DATA:
6 X 5cm, 3 X 4cm, 16 X 6cm, 4 X 5cm, 6 X 8cm, 7 X 3cm, 10 X 4cm, 2 X 2cm, 9 X 2cm,
12 X 6cm.
22. Given that you are required to calculate the powers of numbers. Write a programme that list all
the resulting powers of an integer that is less than 1000.
For example:
CLS
REM Compute List of powers
Const Maxpower = 1000
DIM Power AS INTEGER
DIM n AS INTEGER
Power = 1 The first power n ^ 0 is always 1
COLOR 10, 1
PRINT This program prints all powers <; Maxpower; of an integer
INPUT Enter an integer for; n
DO WHILE Power < Maxpower
PRINT Power;
Power = Power * n
LOOP
23. Below is the record of Sales on tickets from each gate of a sports stadium represented as a set
of data in the following form:
Sample Records
G01 27.00 254.00 15.00 21.00
G02 2.00 196.00 240.00
G03 25.00 300.00 10.00
G04 36.00 298.00 150.00 etc
Write a QBASIC programme to read the sample data above, calculate the total income for each
gate separately and calculate the total income for the stadium and the gate which records the
largest income.
Solution:
24. Write QBASIC Program to read the records/accounts of 1000 employees of STARBLISS (NIG.)
LTD. Each record has the following layout:
Requirement:
Calculate the total monthly net pay of each employee and generate the output reports and
accounts.
Solution:
25. Write QBASIC Programme to input the records of a file where each record contains the identity
of a person, the amount of loan in Naira he obtains (the principal), the interest rate of the loan
and the number of payment period per year. The programme should compute the loan payment
required for each pay period to repay the outstanding principal in one year at the indicated rate in
Naira equal payments. The formula for calculating payments is:
Payment = P(1 + K) + 12
n
Where
P = Principal loan
K = Interest rate
n = Number of periods per year
Solution:
10 CLS
20 REM Set previous key setting off
30 KEY OFF
40 REM Enter the number of the debtors
50 INPUT Please enter the number of debtors to consider; d
60 CLS
70 DIM A$(d), B$(d), C(d), D(d), E(d), F(d)
80 REM Create a for and next loop to accept the records of debtors
90 FOR I = 1 TO d
100 INPUT Surname: ; A$(I)
110 INPUT Other names: ; B$(I)
120 INPUT Principal Loan: ; C(I)
130 INPUT Interest rate: ; K(I)
140 INPUT Payment period per year = ; E(I)
150 REM Compute the payment per period for each debtor
160 F(I) = (C(I) * (1 + K(I)) + 12) / E(I)
170 CLS
180 NEXT I
190 CLS
200 REM Print the report
210 FOR I = 1 TO d
220 PRINT A$(I), B$(I), C(I), K(I), E(I), F(I)
225 NEXT I
230 END
26. Write QBASIC programme that causes a red lighting bolt to be displayed on the screen
Solution:
27. Given below is a QBASIC Programme which causes a sequence of rectangles to move from the
centre of the screen to the outer edges. This programme also utilizes sound to enhance the
graphics effects.
Solution:
10 REM Case study of concentric rectangles
20 REM
30 KEY OFF
35 CLS
40 SCREEN 1
45 COLOR 0, 1
47 C = 3
50 P = 0
55 Q = -45
70 REM Begin main loop
80 FOR I = 1 TO 10
90 LINE (160 1.6 * P, 100 P) (160 + 1.6 * P, 100 + P), C, B
100 IF Q > 0 THEN
105 LINE (160 1.6 * Q, 100 Q) (160 + 1.6 * Q, 100 + Q), O, B
107 ENDIF
110 P = P + S
115 IF P > 95 THEN
117 P = 0
119 C = 1 + INT(3 * RND)
120 Q = Q + 5
123 ENDIF
125 IF Q > 95 THEN
127 Q = 0
129 ENDIF
130 IF P = 0 OR Q = 0 THEN
133 SOUND 20 + INT(100 * RND), 10
135 ENDIF
140 NEXT I
150 END
28. Given below is a QBASIC programme which causes repeated groups of concentric circles to be
generated, with each group starting at the centre of the screen and moving outward to the edge.
Solution:
29. Write an alternative QBASIC programme that allow any shape objects, circles, ellipses and
rectangles to be filled with other paint colours, with the general form of using paint statement.
Solution:
5 CLS
10 REM This programme generates concentric painted circles
20 SCREEN 9
30 FOR K = 1 TO 100
40 CIRCLE(300, 165), K
50 CIRCLE(320, 165), K
60 CIRCLE(100, 183), K
70 CIRCLE(200, 265), K
80 CIRCLE(220, 34), K
90 CIRCLE(240, 55), K
100 CIRCLE(120, 134), K
110 CIRCLE(160, 123), K
120 CIRCLE(80, 265), K
130 CIRCLE(40, 80), K
140 CIRCLE(14, 105), K
150 CIRCLE(140, 25), K
160 CIRCLE(70, 65), K
170 CIRCLE(300, 16), K
180 CIRCLE(400, 84), K
190 CIRCLE(340, 99), K
200 LINE (500, 200 K + 8) (600, 230 K + 8), 2, BF
210 LINE (350, 225 K + 8) (500, 215 K + 8), 7, BF
220 SLEEP 1
230 LINE (500, 200 K + 8) (600, 230 K + 8), 0, BF
240 LINE (350, 225 K + 8) (500, 215 K + 8), 0, BF
250 NEXT K
260 END
30. Given below is a QBASIC programme that causes a bar chart to be generated. Each value is
assumed to be non-negative, therefore the values will be displayed above each of their respective
rectangles, that is, above each bar
Solution:
31. Given below is a basic programme which causes a ball to move freely within a confined enclosure.
Write to generate the animation by means of the GET and PUT statement.
Solution:
ADVANCE ANIMATION
Solution:
33. Write QBASIC program that display a picture of human face using object.
Solution:
5 CLS
10 REM This programme displays the picture of a human face
20 SCREEN 1
30 FOR K = 1 TO 10
40 COLOR 7, 2
50 CIRCLE(150, 100), 70
60 CIRCLE(120, 80), K
70 CIRCLE(180, 80), K
80 LINE(150, 80) (170, 110)
90 LINE-(150, 110 K)
100 CIRCLE(150, 130), K
110 SLEEP 1
120 NEXT K
34. Write a QBASIC programme that generate a waving Nigerian flag on a pole using objects.
Solution:
5 CLS
10 REM This program generates Nigerian flag on a pole
20 SCREEN 9
30 FOR K = 1 TO 100
40 LINE(150, 100) (200, 140), 2, BF
50 LINE(200, 100) (250, 140), 7, BF
60 LINE(250, 100) (310, 140), 2, BF
70 LINE(300, 100) (310, 300), 1, BF
80 SLEEP 1
90 LINE(150, 100) (200, 140), 0, BF
100 LINE(200, 100) (250, 140), 0. BF
110 LINE(250, 100) (300, 140), 0, BF
120 LINE(300, 100) (310, 300), 1, BF
130 LINE(310, 100) (360, 140), 2, BF
140 LINE(360, 100) (410, 140), 7. NF
150 LINE(140, 100) (460, 140), 2, BF
160 LINE(300, 100) (310, 300), 1, BF
170 SLEEP 1
180 LINE(310, 100) (360, 140), 0, BF
190 LINE(360, 100) (410, 140), 0, BF
200 LINE(410, 100) (460, 140), 0, BF
210 LINE(300, 100) (310, 300), 1, BF
220 NEXT K
OPTIONAL
35. Write QBASIC programme that generates a racing car using objects
Solution:
43 CLS
44 REM This programme generates a racing car
45 SCREEN 1
46 COLOR 2
47 LINE(10 + K, 100 + J) (10 + K, 80 + J)
48 LINE (30 + K, 80 + K)
49 LINE (50 + K, 60 + J)
50 LINE (70 + K, 57 + J)
51 LINE (90 + K, 60 + J)
52 LINE (120 + K, 80 + J)
53 LINE (170 + K, 80 + J)
54 LINE (180 + K, 100 + J)
55 LINE (180 + K, 110 + J)
56 LINE (170 + K, 110 + J)
57 LINE(10 + K, 100 + J) (20 + K, 110 + J)
58 LINE(65 + K, 110 + J) (140 + K, 110 + J)
59 LINE(10 + K, 100 + J) (35 + K, 100 + J)
60 LINE(60 + K, 100 + J) (140 + K, 100 + J)
61 LINE(180 + K, 100 + J) (170 + K, 100 + J)
62 LINE(10 + K, 90 + J) (170 + K, 90 + J)
63 LINE(70 + K, 80 + J) (80 + K, 90 + J)
64 LINE (80 + K, 110 + J)
65 LINE(120 + K, 80 + J) (130 + K, 90 + J)
66 LINE (130 + K, 110 + J)
67 LINE(50 + K, 80 + J) (50 + K, 95 + J)
68 LINE(77 + K, 82 + J) (80 + K, 85 + J), 5, BF
69 LINE(52 + K, 82 + J) (55 + K, 85 + J), 5, BF
70 LINE(50 + K, 80 + J) (50 + K, 60 + J)
71 LINE (90 + K, 60 + J)
72 LINE(30 + K, 80 + J) (120 + K, 80 + J)
73 LINE(52 + K, 62 + J) (69 + K, 78 + J), 3, BF
74 LINE(71 + K, 62 + J) (88 + K, 78 + J), 3, BF
75 LINE(90 + K, 62 + J) (118 + K, 78 + J)
76 LINE (90 + K, 78 + J)
77 LINE (90 + K, 62 + J)
78 LINE(70 + K, 80 + J) (80 + K, 90 + J)
79 CIRCLE(50 + K, 110 + J), 15
80 CIRCLE(50 + K, 110 + J), 10
81 LINE(40 + K, 110 + J) (60 + K, 110 + J)
82 LINE(50 + K, 105 + J) (50 + K, 115 + J)
83 CIRCLE(155 + K, 110 + J), 15
84 CIRCLE(155 + K, 110 + J), 10
85 LINE(145 + K, 110 + J) (165 + K, 110 + J)
86 LINE(155 + K, 105 + J) (155 + K, 115 + J)
87 LINE(20 + K, 110 + J) (35 + K, 110 + J)
88 PRINT Set! ; BEEP
89 SLEEP 3
90 LOCATE 10, 30: PRINT Go! ; BEEP
91 SLEEP 1
92 CLS
93 SCREEN 9
94 COLOR 2
95 FOR T = 1 TO 5
96 LINE (1, 50) (700, 140), , B
97 LINE (1, 230) (700, 230)
98 LINE (1, 320) (700, 320)
99 FOR J = 1 TO 270 STEP 90
100 FOR K = 1 TO 1000 STEP 50
101 LINE (10 + K, 100 + J) (10 + K, 80 + J)
102 LINE (30 + K, 80 + J)
103 LINE (50 + K, 60 + J)
104 LINE (70 + K, 57 + J)
105 LINE (90 + K, 60 + J)
106 LINE (120 + K, 80 + J)
107 LINE (170 + K 90 + J)
108 LINE (180 + K, 100 + J)
109 LINE (180 + K, 110 + J)
110 LINE (170 + K, 110 + J)
120 LINE (10 + K, 100 + J) (20 + K, 110 + J)
130 LINE (65 + K, 110 + J) (140 + K, 110 + J)
140 LINE (10 + K, 100 + J) (35 + K, 100 + J)
150 LINE (60 + K, 100 + J) (140 + K, 100 + J)
160 LINE (180 + K, 100 + J) (170 + K, 100 + J)
170 LINE (10 + K, 90 + J) (170 + K, 90 + J)
180 LINE (70 + K, 80 + J) (80 + K, 90 + J)
190 LINE (80 + K, 110 + J)
200 LINE (120 + K, 80 + J) (130 + K, 90 + J)
210 LINE (130 + K, 110 + J)
220 LINE (50 + K, 80 + J) (50 + K, 95 + J)
230 LINE (77 + K, 82 + J) (80 + K, 85 + J), 5, BF
240 LINE(52 + K, 82 + J) (55 + K, 85 + J), 5, BF
250 LINE (50 + K, 80 + J) (50 + K, 60 + J)
260 LINE (90 + K, 60 + J)
270 LINE (30 + K, 80 + J) (120 + K, 80 + J)
280 LINE(52 + K, 62 + J) (69 + K, 78 + J), 3, BF
290 LINE(71 + K, 62 + J) (88 + K, 78 + J), 3, BF
295 LINE (90 + K, 62 + J) (88 + K, 78 + J)
300 LINE (90 + K, 78 + J)
310 LINE (90 + K, 62 + J)
320 LINE (70 + K, 80 + J) (80 + K, 90 + J)
330 CIRCLE (50 + K, 110 + J), 15
340 CIRCLE (50 + K, 110 + J), 10
350 LINE (40 + K, 110 + J) (60 + K, 110 + J)
360 LINE (50 + K, 105 + J) (50 + K, 115 + J)
370 CIRCLE (155 + K, 110 + J), 15
380 CIRCLE (155 + K, 110 + J), 10
390 LINE (145 + K, 110 + J) (165 + K, 110 + J)
400 LINE (155 + K, 105 + J) (155 + K, 115 + J)
410 LINE (20 + K, 110 + J) (35 + K, 110 + J)
420 LINE (10 + K, 100 + J) (10 + K, 80 + J), 0
430 LINE (30 + K, 80 + J), 0
440 LINE (50 + K, 60 + J), 0
450 LINE (70 + K, 57 + J), 0
460 LINE (90 + K, 60 + J), 0
470 LINE (120 + K, 80 + J), 0
480 LINE (170 + K, 90 + J), 0
490 LINE (180 + K, 100 + J), 0
500 LINE (180 + K, 110 + J), 0
510 LINE (170 + K, 110 + J), 0
520 LINE (10 + K, 100 + J) (20 + K, 110 + J), 0
530 LINE (65 + K, 110 + J) (140 + K, 110 + J), 0
540 LINE (10 + K, 100 + J) (35 + K, 100 + J), 0
550 LINE (60 + K, 100 + J) (140 + K, 100 + J), 0
560 LINE (180 + K, 100 + J) (170 + K, 100 + J), 0
570 LINE (10 + K, 90 + J) (170 + K, 90 + J), 0
580 LINE (70 + K, 80 + J) (80 + K, 90 + J), 0
590 LINE (80 + K, 110 + J), 0
600 LINE (120 + K, 80 + J) (130 + K, 90 + J), 0
610 LINE (130 + K, 110 + J), 0
620 LINE (50 + K, 80 + J) (50 + K, 95 + J), 0
630 LINE (77 + K, 82 + J) (80 + K, 85 + J), 0, BF
640 LINE (52 + K, 82 + J) (55 + K, 85 + J), 0, BF
650 LINE (50 + K, 80 + J) (50 + K, 60 + J), 0
660 LINE (90 + K, 90 + J), 0
670 LINE (30 + K, 80 + J) (120 + K, 80 + J), 0
680 LINE (52 + K, 62 + J) (80 + K, 85 + J), 0, BF
690 LINE (71 + K, 62 + J) (88 + K, 78 + J), 0, BF
700 LINE (90 + K, 62 + J) (118 + K, 78 + J), 0
710 LINE (90 + K, 78 + J), 0
720 LINE (90 + K, 62 + J), 0
730 LINE (70 + K, 80 + J) (80 + K, 90 + J), 0
740 CIRCLE (50 + K, 110 + J), 15
750 CIRCLE (50 + K, 110 + J), 10
760 LINE (40 + K, 110 + J) (60 + K, 110 + J), 0
770 LINE (50 + K, 105 + J) (50 + K, 115 + J), 0
780 CIRCLE (155 + K, 110 + J), 15, 0
790 CIRCLE (155 + K, 110 + J), 10, 0
800 LINE (145 + K, 110 + J) (165 + K, 110 + J), 0
810 LINE (155 + K, 105 + J) (155 + K, 115 + J), 0
820 LINE (20 + K, 110 + J) (35 + K, 110 + J), 0
830 NEXT K
840 NEXT J
850 NEXT T
I WILL STOP HERE FOR NOW. I HOPE THIS WILL HELP YOU FOR YOUR PROGRAMMING.