QBASIC

 

 

QBASIC 

1.       FULL FORM = Quick Beginner's All Purpose Symbolic Instruction Code.

2.        It is a high level computer language developed by Microsoft. In 1985.

3.       It was invented by John G. Kemeny and Thomas E. Kurtz.

 

Features:

1.       It is easy to learn and fun to practice.

2.       it is available in almost every computer.

3.       It automatically check syntax.

4.       It is suitable for mathematical and business application.

5.       Programming and debugging is simple and quick.

6.       Modification of program is quite easy.

 

Elements:

1.       Character set: alphabet(A to Z), digits (0 to 9) and special character (+,(),$,=)

2.       Constant and variables: The quantity which doesn't change its value during the execution of the program is called constant.

The quantity which may change its value during the execution of the program is called variable.

Numeric(0 to 9) and string($) (a to z).

3.       Arithmetic expressions; addition(+), subtraction(-), multiplication(*), division(/)

 

Programs:

1.       WAP to print sum of two given numbers.

2.       WAP to print area of rectangle.

3.       WAP to print name, address and mobile number.

4.       WAP to print are of circle. Pi*r2 (use pi = 3.14)

5.       WAP to print sum and average of given three number.

6.       WAP to print sum of square of two different number.

7.       WAP to print simple interest where SI=(P*T*R)/100

8.       WAP to find your age.

9.       WAP to convert the Celsius into Fahrenheit.

10.   WAP to convert Euro into Nepali rupees. 1 rs = 140 euro


 

 

 

 

 

 

 

 READ & DATA statement.

READ a, b, c

PRINT a, b, c

DATA 34,56,78

 

11.   REM find average using READ ... DATA

 CLS

READ a, b, c

avg = (a + b + c) / 3

PRINT "Average = "; avg

DATA 45,67,52

END

 


 

Control structure:

1.       Sequential structure

2.       Selection (Conditional) structure

i.                    If CASE

Structure 1.

Syntax: if <condition> THEN

<statement block>

END

 

Structure 2.

Syntax ; if <condition> THEN

<statement 1>

ELSE <statement 2>

END

 

Structure 3.

Syntax ; IF <condition1> THEN

<statement 1>

                ELSEIF <condition 2>

                THEN <statement 2>

                ELSEIF<condition 3>

                THEN <statement 3>

                ELSE

                <statement 4>

                END IF

                END

 

 

 

 

ii.                   SELECT CASE

Syntax:

SELECT CASE Test-expression

    CASE condtion1

        PRINT  statement1

    CASE condition2

        PRINT statement2

    CASE condtion 3

        PRINT sttmnt 3

    CASE ELSE

        PRINT sttmnt 4

END SELECT

 

 


      Unconditional statement ;

GOTO statement

CLS

PRINT "Kathmandu"

GOTO abc

PRINT "Birgunj"

abc:

PRINT "Biratnagar"

END

 

Conditional statement ; if elseif then else ENDIF

 

 

 

 

 

 

 

 

 

 

 

Looping Structure;

Looping is the process of repeating a block of statements multiple number of times as per the requirement. A loop is terminated when the given condition is satisfied.

                      

WAP to print Nepal 100 times.

CLS

FOR i= 1 TO 100

Print "NEPAL"

NEXT i

END

 

1.       WAP to print your name 1000 times.

CLS

FOR i = 1 TO 1000

Print "HIMALAYAN"

NEXT i

END

 


2.       WAP to print first 100 natural number.

CLS

FOR i = 1 TO 100               

PRINT i;

NEXT i

END

 

 


3.       WAP to print first n natural number.

CLS

INPUT "ENTER NUMBER"; n

FOR i = 1 TO n

PRINt i;

NEXT i

END

 

4.       WAP to print first n natural odd number.

CLS

INPUT "ENTER NUMBER"; n

FOR i = 1 TO n STEP 2

PRINt i;

NEXT i

END

 

5.       WAP to calculate sum of n natural number

CLS

INPUT "ENTER NUMBER"; n

FOR i = 1 TO n

S=S + i

NEXT i

Print "Sum is " ; S

END

 

6.       WAP to generate following series.

a.       1, 2 ,3, 4 ................. 10th term

b.       1, 3, 5, 7...................10th term

c.       2, 4, 6, 8 ...................10th term

d.       1, 4, 9, 16.................. 10th term

e.       1, 8, 27, 64.................. 10th term

f.        1, 2, 4, 7, 11   .................... 10th term

g.       5, 10 20 35................... 10th term

h.       1 5 9 13   ...................... 10th term

i.         1 1 2 3 5, 8, 13 ......................... 10th term


 


2. WHILE WEND

 

Syntax:

WHILE [Condition]

Statement

Increment/Decrement

WEND

END

REM program to print Nepal 100 times.

CLS

i = 1

WHILE i<=100

Print "Nepal"

i=i+1

WEND

END

1, 8, 27, 64,.... 10th terms

WHILE WEND

CLS

I = 1

WHILE i<=10

Print i^3;

i = i+1

WEND

END

REM program to print 10 natural number.

WHILE END

CLS

i = 1

WHILE i <= 10

    PRINT i;

    i = i + 1

WEND

END

 

1, 3, 5, 7... 10th terms

WHILE WEND

CLS

I = 1

WHILE i<=10

Print i;

i=i+2

WEND

END

CLS

FOR i= 1 TO 100

Print "NEPAL"

NEXT i

END

 

 

 

 

 

 

 

 

 

 

 

 

 


1.       WAP to print n natural number.       

CLS

INPUT "Enter number"; n

i = 1

WHILE i <= n

Print i;

i = i+1

WEND

END

 

 

 

 

2.       WAP to calculate sum of n natural number    

CLS

INPUT "ENTER NUMBER"; n

i = 1

While i <= n

S=S + i

i=i + 1

WEND

Print "Sum is " ; S

END

 

3.       WAP to calculate product of n natural number         1*2*3

CLS

INPUT "ENTER NUMBER"; n

i = 1

P=1

While i <=n

P= P* i

i=i+1

WEND

Print "Product is " ; P

END

 

4.       WAP to print the reverse of given number.

CLS

INPUT "ENTER NUMBER"; n  123                            12                               1

                WHILE n<>0                              123 <> 0                   12<>0                       1<> 0

                r= n MOD 10                            123 MOD 10 = 3     12 MOD 10 = 2        1 MOD 10 = 1

                s=s*10+r                                     3                              3*10+2 = 32               32*10+1 = 321

                n= n\10                                     123\10 = 12              12\ 10 = 1                 1\10 = 0

                WEND

                Print "reverse of given number is "; s

                END

 

 

 

 

 

 

 

 

 

 

 

5.       WAP to print whether given number is palindrome or not.

CLS

INPUT "ENTER NUMBER"; n  

                z = n

WHILE n<>0

                r= n MOD 10

                s=s*10+r                         

                n= n\10              

                WEND

                If z=s THEN

 PRINT "Palindrome"

ELSE

Print "Not Palindrome"

                ENDIF

                END

 

 

 

6.       WAP to print sum of given number.

CLS

INPUT "ENTER NUMBER"; n      

                WHILE n<>0

                r= n MOD 10                                 

                s= s + r                                              

                n= n\10

                WEND

                Print "Sum of given number is " s

                END

 

7.       WAP to print whether given number is Armstrong or not.  153, 370, 371 , 407

CLS

INPUT "ENTER NUMBER"; n

                z=n

WHILE n<>0

                r= n MOD 10

                s=s+r^3

                n= n\10

                WEND

                If z=s THEN

 PRINT "Armstrong"

ELSE

Print "Not Armstrong"

                ENDIF

                END

 

 

 

 

 

 

 

STRING FUNCTION

1.       LEN

Length of string

Syntax ; LEN(string variable)

For ex. N$ = NEPAL

A= LEN(N$)

PRINT A;

OUTPUT ; 5

                                                                                                                                                                  

2.       LEFT$

Extract the left character

Syntax ; LEFT$ (string variable, No. of character)

For ex.

N$ = NEPAL

A$ = LEFT$ (N$,2)

OUTPUT ; NE

 

N

NE

NEP

NEPA

NEPAL

Example:

CLS

N$ = NEPAL

FOR i = 1 to LEN(N$)

A$ = LEFT$ (N$, i)

Print A;

NEXT i

END

 

 

 

 

 

 

3.       RIGHT$

Extract the right character

Syntax : RIGHT$ (S.V , No. of character)

L

AL

PAL

EPAL

NEPAL

For ex.

CLS

N$ = NEPAL

FOR i = 1 to LEN(N$)

A$ = RIGHT$ (N$, i)

Print A;

NEXT i

END

 

 

 

 

4.       MID$

Extract the right character

Syntax : MID$ (S.V , Starting no. of character, Total no. of character)

EPA

For ex.

CLS

N$ = NEPAL

A$ = MID$ (N$, 2, 3)

Print A;

NEXT i

END

 

 

5.       LCASE$

Lower case

Syntax : LCASE$ (string variable)

nepal

For ex.

CLS

N$ = NEPAL

A$ = LCASE$ (N$)

Print A$;

NEXT i

END

 

 

 

 

 

6.       UCASE$

Upper case

Syntax : UCASE$ (string variable)

NEPAL

For ex.

CLS

N$ = nepal

A$ = UCASE$ (N$)

Print A$;

NEXT i

END

 

 

 

 

 

 

 

 

1.       REM to print reverse of given string.

CLS

INPUT "Enter any string"; N$

a = len (N$)

for i = a to 1 step -1

X$ = MID$ (N$, i)

W$ = W$ + X$

NEXT i

PRINT "Reverse string is"; W$

END

 

2.       REM To check whether given string is palindrome or not.

CLS

CLS

INPUT "Enter any string"; N$

a = len (N$)

for i = a to 1 step -1

X$ = MID$ (N$, i)

W$ = W$ + X$

NEXT i

IF N$ = W$ THEN

PRINT "Palindrome"

ELSE

PRINT "Not Palindrome"

ENDIF

END

 

 

 

 

 

 

 

3.       WAP to count vowels in a given string.

CLS

INPUT "Enter any string"; N$

FOR i = 1 to LEN(N$)

                X$ = MID$ (N$, i, 1)

                X$ = LCASE$ (X$)

                IF X$ = "a" OR X$ = "e" OR X$ = "i" OR X$ = "o" OR X$ = "u" THEN

                V= V+1

                ENDIF

NEXT i

Print "Total number of vowels is"; V

END

 

4.       WAP to count vowels and consonant in a given string.

CLS

INPUT "Enter any string"; N$

FOR i = 1 to LEN(N$)

                X$ = MID$ (N$, i, 1)

                X$ = LCASE$ (X$)

                IF X$ = "a" OR X$ = "e" OR X$ = "i" OR X$ = "o" OR X$ = "u" THEN

                V= V+1

                ELSE

                C = C + 1

                ENDIF

NEXT i

Print "Total number of vowels is"; V

Print "Total number of consonant is"; C

END

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5.       WAP to count vowels and consonant in a given string.

CLS

INPUT "Enter any string"; N$

FOR i = 1 to LEN(N$)

                X$ = MID$ (N$, i, 1)

                X$ = LCASE$ (X$)

                IF X$ = "a" OR X$ = "e" OR X$ = "i" OR X$ = "o" OR X$ = "u" THEN

                V$= V$+X$

                ELSE

                C$ = C$ + X$

                ENDIF

NEXT i

Print "Total vowels are "; V$

Print "Total consonants are"; C

END

 

6.       WAP to print string in alternatively capital and lower case. (NePaL)

CLS

INPUT "Enter any string"; N$

FOR i = 1 to LEN (N$)

                X$ = MID$(N$, i, 1)

                IF i MOD 2 = 0 THEN

                W$ = W$ + LCASE$(X$)

                ELSE

                W$ = W$ + UCASE$(X$)

                END IF

NEXT i

PRINT W$

END

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Nested Loop :

If one loop exist inside another loop then is is known as nested loop.

CLS

123

FOR i = 1 To 3

Print i;

Next i

END

 

123123123

FOR i = 1 To 3

                FOR j = 1 To 3

                Print j:

                Next j

Print i;

Next i

END

 

123

123

123

FOR i = 1 To 3

                FOR j = 1 To 3

                Print j:

                Next j

                Print

Print i;

Next i

END

 

111

222

333

FOR i = 1 To 3

                FOR j = 1 To 3

                Print i:

                Next j

                Print

Print i;

Next i

END

 

5

55

555

5555

55555

 

CLS

n= 5

FOR i = 1 To 5

Print ; n

n = 5 *10 + 5

Next i

END

 

55555

5555

555

55

5

CLS

n= 55555

FOR i = 1 To 5

Print ; n

n = 5 \10 

Next i

END

1

12

123

1234

12345

 


CLS

FOR i = 1 To 5

                FOR j = 1 to i

                                Print j;

                Next j

                Print

Next i

END

 

1

22

333

4444

55555

CLS

FOR i = 1 To 5

                FOR j = 1 to i

                                Print i;

                Next j

                Print

Next i

END

12345

1234

123

12

1

 


CLS

FOR i = 5 to 1 step -1

                For j = 1 to i

                                Print j;

                Next j

                Print

Next i

END

55555

4444

333

22

1

CLS

FOR i = 5 to 1 step -1

                For j = 1 to i

                                Print i;

                Next j

                Print

Next i

END

 

54321

5432

543

54

5

CLS

FOR i = 1 to 5

                For j = 5 to i step -1

                                Print j;

                Next j

                Print

Next i

END

 

11111

2222

333

44

5

CLS

FOR i = 1 to 5

                For j = 5 to i step -1

                                Print i;

                Next j

                Print

Next i

END

 

POKHARA

  OKHAR

     KHA

       H

CLS

N$ = "POKHARA"

L = LEN(N$)

For i = 1 to 4

                X$ = MID$(N$, i, l)

                PRINT tab (i) ; X$

                L = L – 2

NEXT i

END

 

       H

     KHA

  OKHAR

POKHARA

CLS

N$ = "POKHARA"

L = 1

FOR i = 4 TO 1 STEP -1

                X$ = MID$(N$, i, 1)

                PRINT TAB(i); X$

                L = L + 2

Next i

End

 

 


No comments:

Post a Comment

OOP

  UNIT 5. Object Oriented Programming (3 marks)     1. What are the programming methods or approaches of program development?   Th...

designs

designs

Pages