Thursday, 19 April 2012

QBASIC program to produce bar charts or Histograms?

Check out this QBASIC program to produce a bar chart from inputted data.

CLS
SCREEN 12
' THIS PROGRAM PLOTS A BAR CHART OF 12 BARS

INPUT " CHOOSE THE COLOR OF YOUR BARS,ANY ONE OF BLUE, GREEN, RED AND
YELLOW"; COL$

SELECT CASE COL$
CASE "BLUE"
LET A = 9
CASE "GREEN"
LET A = 10
CASE "RED"
LET A = 12
CASE "YELLOW"
LET A = 14
CASE "blue"
LET A = 9
CASE "green"
LET A = 10
CASE "red"
LET A = 12
CASE "yellow"
LET A = 14

END SELECT
LINE (10, 200)-(10, 400)
LINE (10, 400)-(600, 400)

FOR X = 35 TO 600 STEP 50
INPUT "INPUT VERTICAL VALUE <= 200 "; Y
LINE (X, (400 - Y))-((X + 30), 400), A, BF
NEXT X

END

Monday, 16 April 2012

A simple program to change any number in base ten to another base.

In the study of computer science you must come across number base
problems, this little code here can help you.
CLS
'THIS PROGRAM CHANGES ANY NUMBER IN BASE TEN TO ANY BASE YOU
'WISH TO CHANGE IT TO
DIM B(30)
INPUT "THE NO IN BASE TEN"; D
INPUT "THE NEW BASE YOU WANT TO CHANGE IT TO"; NB
CLS

BT = D
DO
K = K + 1
I = I + 1
E = D MOD NB
D = D \ NB
B(I) = E
LOOP UNTIL D < NB
PRINT
PRINT
PRINT BT; "IN BASE"; NB; "IS"

B(I + 1) = D
FOR I = K + 1 TO 1 STEP -1
COLOR 6
PRINT USING "#"; B(I);
NEXT I
END

Qbasic program to produce a multiplication table of variable width & height, accompanied with rows and columns.

'THIS ONE CREATES A MULTIPLICATION TABLE WITH CORRESPONDING ROWS AND COLUMNS
'IT'S KINDA DYNAMIC, THIS AND MORE CAN BE ACHIEVED WITH QBASIC
DECLARE SUB BRAND ()
CLS
SCREEN 12
'PROGRAM TO PRODUCE MULTIPLICATION TABLE
INPUT "INPUT THE THE DESIRED WIDTH OF THE TABLE"; X
INPUT "INPUT THE THE DESIRED LENGTH OF THE TABLE"; Y

SX = 6
SY = 15

CLS
CALL BRAND
CLS
PRINT

FOR A = 1 TO Y
FOR B = 1 TO X
COLOR 14
PRINT USING "###"; A * B;
PRINT " ";
NEXT
PRINT
NEXT

LINE (SX - 5, SY - 5)-(31.5 * X + 5, (15.89 * Y + 20)), 13, B
LINE (SX, SY)-(31.5 * X, (15.89 * Y) + 15), 15, B
'THIS FIRST LOOP DRAWS THE FIRST TWO VERTICAL LINES
FOR LX = 37.5 TO (31.5 * 3) STEP 31.5
LINE (LX, SY)-(LX, (15.89 * Y) + SY), 9
NEXT
'THIS DRAWS THE REMAINING VETICAL LINES
FOR LX2 = 94.5 TO (31.5 * X) STEP 31.5
LINE (LX2, SY)-(LX2, (15.89 * Y) + SY), 10
NEXT
'THIS LOOP DRAWS ALL THE HORIZONTAL LINES
FOR LY = 30.89 TO (15.89 * Y) STEP 15.89
LINE (SX, LY)-(31.5 * X, LY), 3
NEXT

END

SUB BRAND
PRINT
PRINT
PRINT
PRINT " MULTIPLICATION TABLE PROGRAM"
PRINT " COMPLETED BY"
COLOR 9
PRINT " IKFORMULA "
SLEEP 2

END SUB

Friday, 13 April 2012

Program to create an analog clock.

This program creates an analog clock.
CLS
SCREEN 12
SECONDHAND = 80
MINHAND = 65
HOURHAND = 50
OX = 200 'THESE IS THE CENTER OF THE CLOCK
OY = 250
RADIUS = 100

DO
FOR H = .10464 TO 6.2784 STEP .5232 'the angles are already in radians
FOR M = .10464 TO 6.2784 STEP .10464
FOR S = .10464 TO 6.2784 STEP .10464

'************************************************************************
FOR H2 = 0 TO 5.7552 STEP .5232 'to create the marks all
S4X = OX + ((SECONDHAND + 10) * COS(H2)) 'around the face of the
S4Y = OY + ((SECONDHAND + 10) * SIN(H2)) 'clock
S5X = OX + ((SECONDHAND + 15) * COS(H2))
S5Y = OY + ((SECONDHAND + 15) * SIN(H2))

LINE (S5X, S5Y)-(S4X, S4Y)

NEXT H2
'***********************************************************************

FOR S2 = .10464 TO 6.2784 STEP .10464
S2X = OX + ((SECONDHAND + 20) * COS(S2))
S2Y = OY + ((SECONDHAND + 20) * SIN(S2))
S3X = OX + ((SECONDHAND + 15) * COS(S2))
S3Y = OY + ((SECONDHAND + 15) * SIN(S2))

LINE (S3X, S3Y)-(S2X, S2Y)

CIRCLE (OX, OY), 95

NEXT S2

SX = OX + (SECONDHAND * COS(S))
SY = OY + (SECONDHAND * SIN(S))

MX = OX + (MINHAND * COS(M))
MY = OY + (MINHAND * SIN(M))

HX = OX + (HOURHAND * COS(H))
HY = OY + (HOURHAND * SIN(H))

LINE (OX, OY)-(SX, SY), 4 'Second hand

LINE (OX, OY)-(MX, MY), 14 'MINUTE hand
CIRCLE (MX, MY), 5
LINE (OX, OY)-(HX, HY) 'HOUR hand
CIRCLE (HX, HY), 5
CIRCLE (OX, OY), RADIUS
CIRCLE (OX, OY), RADIUS + 10
CIRCLE (OX, OY), 5, 1
SLEEP 1
SOUND 4000, .1
CLS
NEXT S
NEXT M
NEXT H
LOOP
END