QBASIC program codes

 

 

 

 

 

 

WAP to count the no. of vowels and constants in the file called frunlog.txt of c:

 

CLS

OPEN "c:\frunlog.txt" FOR INPUT AS #1

DO

LINE INPUT #1, ch$

FOR i = 1 TO LEN(ch$)

        char$ = MID$(ch$, i, 1)

        IF UCASE$(char$) = "A" OR UCASE$(char$) = "E" OR UCASE$(char$) = "I" OR                                                      UCASE$(char$) = "O" OR UCASE$(char$) = "U" THEN

                vow = vow + 1

        ELSE

                cons = cons + 1

        END IF

NEXT

LOOP UNTIL EOF(1)

PRINT " The no. of vowels are:"; vow

PRINT " The no. of constants are:"; cons

CLOSE #1

END

 

 

 

WAP to generate the multiplication table of the number entered by the user.

START:

CLS

REM * TO PRINT THE MULTI

INPUT "Enter a number"; a

FOR i = 1 TO 10

         PRINT a; "*"; i; "="; a * i

NEXT

LOCATE 15, 1

INPUT "DO YOU WANT TO CONTINUE"; B$

IF B$ = "Y" OR B$ = "y" THEN

GOTO START

ELSE

PRINT "Good Bye"

END IF

END


WAP to change the entered sentence into uppercase and lowercase.

 

DECLARE SUB upper ()

DECLARE SUB lower ()

 

CLS

PRINT TAB(20); "CONVERSION OF TEXT"

PRINT : PRINT

PRINT "1. Lowercase to uppercase"

PRINT "2. Uppercase to lowercase"

PRINT

PRINT "-------------------------"

PRINT : PRINT

INPUT "Enter your selection"; sel

SELECT CASE sel

        CASE IS = 1

        CALL upper

        CASE IS = 2

        CALL lower

END SELECT

END

 

SUB lower

PRINT : PRINT

INPUT "Enter a sentence in uppercase", u$

PRINT "The text entered is:"; u$

b$ = LCASE$(u$)

PRINT "Now the text is changed into lowercase"

PRINT b$

END SUB

 

SUB upper

INPUT "Enter a sentence is lowercase"; l$

PRINT "The text entered is:"; l$

a$ = UCASE$(l$)

PRINT " Now the text is converted into uppercase"

PRINT a$

END SUB

 


WAP to calculate the mean and median from the given data.

CLS

COLOR 9

PRINT TAB(20); " Calculation of mean and median"

PRINT TAB(20); "--------------------------------"

PRINT : PRINT

INPUT "Enter number of data for mean or median"; nos

PRINT

DIM dat(nos)

FOR i = 1 TO nos

begin:

INPUT "Enter nos."; dat(i)

IF dat(i) < 0 THEN PRINT "Wrong Entry": GOTO begin

IF NOT i = 1 THEN

        FOR k = 1 TO i - 1

                IF dat(k) = dat(i) THEN PRINT "Wrong Entry": GOTO begin

        NEXT k

END IF

NEXT i

CLS

FOR count = 1 TO nos

        PRINT dat(count);

NEXT

PRINT : PRINT

PRINT " 1. Mode"

PRINT " 2. Median"

INPUT "Enter your selection"; n

ON n GOSUB mean, median

END

 

mean:

FOR newcount = 1 TO nos

        sum = sum + dat(newcount)

NEXT

PRINT " Arithmetic Mean is"; sum / nos

END

 

median:

FOR a = nos TO 1 STEP -1

 

        FOR b = 1 TO a - 1

                IF dat(b) < dat(b + 1) THEN SWAP dat(b), dat(b + 1)

        NEXT b

NEXT a

PRINT "Median is", dat((nos + 1) / 2)

END


WAP to generate the report card of a student.

CLS

REM *------------------Input Module-------------------"

PRINT TAB(20); "--------------- Report Card -----------------"

PRINT "---------------------------------------------"

INPUT "enter name"; n$

INPUT "enter class"; c

PRINT : PRINT :

10 :      INPUT "Enter marks in maths:"; m

IF m > 100 THEN PRINT "invalid choice": GOTO 10

20 :      INPUT "Enter marks in science:"; s

IF s > 100 THEN PRINT TAB(2); "invalid choice": GOTO 20

30 :      INPUT "Enter marks in o.maths:"; om

IF om > 100 THEN PRINT TAB(30); "invalid choice": GOTO 30

40 :      INPUT "Enter marks in english:"; e

IF e > 100 THEN PRINT "invalid choice": GOTO 40

50 :      INPUT "Enter marks in social studies:"; ss

IF ss > 100 THEN PRINT "invalid choice": GOTO 50

60 :      INPUT "Enter marks in health:"; h

IF h > 100 THEN PRINT "invalid choice": GOTO 60

70 :      INPUT "Enter marks in computer:"; c

IF c > 100 THEN PRINT "invalid choice": GOTO 70

80 :      INPUT "Enter marks in nepali:"; n

IF n > 100 THEN PRINT "invalid choice": GOTO 80

REM*---calculation------**

total = m + s + om + e + ss + h + c + n

percent = total / 8

IF m < 40 AND s < 40 AND om < 40 AND e < 40 AND ss < 40 AND h < 40 AND c < 40 AND n < 40 THEN

        division$ = "fail"

ELSEIF percent >= 60 THEN division$ = "First"

ELSEIF percent < 60 OR percent >= 50 THEN division$ = "second"

ELSE

        division$ = "Third"

END IF

REM**---- printing module -------**

PRINT : PRINT :

PRINT "total marks obtained is:"; total

PRINT "total percent obtained is:"; percent

PRINT "your division is:"; division$

END