Saturday, October 1, 2022

QBASIC Modular Programming - Debugging - SEE Computer Science 2079

 Debug

1. [SLC 2065]

DECLARE FUNCTION SUM(a,b)
REM Program to sum given two numbers
Input ”Enter first number”; x
Input “Enter second number; y
PRINT SUM(a,b)
END

FUNCTION SUM(x,y)
SUM=a+b
END

2. [SLC 2072]

FUNCTION SUM (m,n)

Rem to print sum of two numbers

a= 6

b= 7

DISPLAY SUM (a, b)

END

 

FUNCTION SUM (m,n)

S = m +n

S = SUM

END SUM

3. [SLC 2068]

CREATE FUNCTION Square(A)
Rem to print square of a number
CLS
Get “a number”; A
CALL square(A)
END
FUNCTION square(A)
Ans=A^2
Square=Ans
END Square(A)

 

4. PABSON FIRST TERM 2079

DECLARE SUB SUM (P, Q, R)

CLS

INPUT “Enter the numbers”: P,Q,R

CALL SUM

END SUB

SUB Check(P,Q,R)

S = P + Q + R

PRINT “Sum of three numbers is”; SUM

END SUB

 

5. SQUARE

Rewrite the given program after correcting the bugs.

Rem to print square root of entered number.

DECLARE SOB SQUARE (N)

ENTER N

DISPLAY SQUARE (N)

END

SUB SQUARE (N)

S= N^0.5

PRINT S

FINISH

6. SQUARE ROOT

REM TO FIND SQUARE ROOT OF THE FIRST FIVE NATURAL NUMBERS

CLS

DECLARE FUNCTION SQROOT (D)

FOR K= 1 TO 15

A = SQROOT(K)

PRINT "SQUARE ROOT"; K; "="; K

NEXT K

END

 

FUNCTION SQROOT (D)

SQROOT =SQR(K)

END

 

7. [MM 2076]

REM To check the input no.  is perfect square or not

DECLARE FUNCTION chk$ (a)

CLS

INPUT “Enter the number :”; a

CALL chk$ (a)

END

 

FUNCTION chk$(a)

m=SQUARE (a)

n=INT (m)

IF m=a   THEN

c$=”Perfect Square”

ELSE

c$=”Not Perfect Square”

END IF

C$=chk$

END FUNCTION

 

8. GREAT

DECLARE SUB CORRECT ()

CLS

Call Correct

End

SUB CORRECT

Rem to find greatest number among three number

WRITE “Enter and three number”; A, B, C

If A>B AND A>C then

G=A

IF B>A AND B>C then

G=B

ELSE

G=C

IF END

Display “Greatest number”; G

End Sub.

 

9. SEE 2078

DECLARE SUB Series ( )

CLS

EXECUTE Series

END

 SUB Series( )

REM Program to generate 1 1 2 3 5 .....upto the 20th terms

A=1

B=1

FOR ctr=10 to 1

DISPLAY A:B:

A=A+B

B=A+B

NEXT ctr

END Series ( )

10. [SLC 2064] [SLC 2067 S] [SLC 2071 S]

 

DECLARE SUB Series( )

CLS

EXECUTE Series

END

 

 

SUB Series( )

REM program to generate  3 3 4 9 15 upto 20th terms.

A=3

B=3

FOR ctr= 10 to 1

DISPLAY A;B;

A=A+B

B=A+B

NEXT ctr

END Series( )

11. [SLC 2066]

DECLARE SUB Fibonic ()

REM *Fibonic series*

CALL SUB Fibonic

END

SUB Fibonic

A=1

B=1

FOR x=1 to 10

DISPLAY a;

a=a+b

b=a+b

END Fibonic

 

12. [SEE 2065 S]

DECLARE SUB Series()

EXECUTE Series

END

SUB Series

A=2

B=2

FOR ctr= 1 to 5

            DISPLAY A;B;

            A=A+B

            B=A+B

            LOOP ctr

END Series()

13. [SEE 2073 U]

 

DECLARE SUB Series ( )

CLS

EXECUTE Series

END

 

SUB Series

REM Program to print 4 4 8 12 20 ....... 20th terms

X = 4

Y = 4

FOR ctr = 10 To 1

DISPLAY X; Y;

X = X+Y

Y = X+ Y

Next ctr

End Series

 

14. [SLC 2070]

 

DECLARE SUB Series( )

CLS

EXECUTE Series

END

 

SUB Series

REM  to generate 2 2 4 6 10….. upto 10th term

P=2

Q=2

FOR           Ctr=1 TO 5

DISPLAY P,Q,

P=P+Q

Q=P+Q

WEND

END Series()

 

15. [SLC 2071]

 

DECLARE SUB CUBE(N)

CLS

FOR I = 1 TO 5

READ

CALL CUBE(No)

NEXT X

DATA 3, 5, 2, 6, 4

END

 

SUB CUBE( )

DISPLAY N^3

END SUB

 

 

16. [SEE 2073]

DECLARE SUB SUM (N)

INPUT "Any Number"; N

PRINT SUM (N)

END

SUB SUM (N)

S = 0

WHILE N = 0

R = R MOD 10

S = S+R

N = N/10

WEND

PRINT "Sum of digits"; s

END

17. [SEE 2074]

REM TO find the factorial of a given number.

DECLARE FUNCTION FACTO (N$)

CLS

INPUT "Enter a number", X

PRINT "The Factorial is: ", FACTO (N)

END

 

FUNCTION FACTO (N)

F = 1

WHILE N = 0

F = F*N

N = N - 1

WEND

F = FACTO

END FUNCTION

 

18. SOS 2078

REM to print odd numbers from 32 to 12

DECLARE SUB show( )

CALL show

END

 

SUB show( )

N=12

WHILE N<=32

IF N MOD 2 = 0 THEN PRINT N;

N = N – 1

NEXT N

END SUB

 

19. PABSON PRE BOARD  2078 – 1

Rem to convert the given number in reverse order

DECLARE FUNCTION REV (A)

CLS

INPUT "ENTER A NUMBER"; A

CALL REV (A)

PRINT "REVERSE ="; RE

END

 

FUNCTION REV$ (A)

WHILE A<> 0

R= A MOD2

S = S * 10 + R

A = A - 10

WEND

REV = S

END SUB

20. JEC 2070

DECLARE FUNCTION result$(n)

CLS

INPUT n

B$= result(n)

PRINT B$

END

 

FUNCTION result(n)

IF n MOD 2=0 THEN

result= “odd”

ELSE

result= “even”

END IF

END FUNCTION

21. SET

DECLARE FUNCTION BINARY(N)

CLS

INPUT “Enter any number=”;N

PRINT “Result=”;BINARY()

END

 

FUNCTION BINARY(A)

BASE=2

WHILE A<>0

R=A MOD BASE

A=A/BASE

B$=STR$(R)+B$

WEND

BINARY=VAL(B)

END FUNCTION

22. SOS 2070

REM to display the binary equivalent of decimal number

DECLARE FUNCTION bin(x)

CLS

INPUT “Decimal number”;n

PRINT “Binary equivalent”;bin(n)

END

FUNCTION bin(x)

WHILE X<>0

R=X MOD 2

S$=VAL(R)+S$

X=X\10

LOOP

D=STR$(S$)

bin=D

END FUNCTION

23. SEE Grade Promotion 2078 - 1

 

REM Program to make a word reverse

DECLARE FUNCTION Rev$(N$)

CLS

INPUT “Enter a word”: N$

DISPLAY “Reversed is”; Rev$(N$)

END

 

FUNCTION Rev$(N$)

FOR K=LEN$(N$) to 1 STEP-1

B$=B$+MID$(N$,1,K)

NEXT K

B$=REV$

END FUNCTION

 

24. [SEE 2075]

 

DECLARE FUNCTION reverse$ (N$)

INPUT "Any String"; N$

X$ = reverse$(N$)

PRINT N$

END

 

FUNCTION reverse (N$)

L = LEN$(N$)

FOR X = L To 1 STEP - 1

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

B$ = B$+A$

NEXT X

B$ = reverse$ (N$)

END FUNCTION

 

25. [SLC 2069]

 

Rem program to reverse the string or word

DECLARE SUB REV(W$)

CLS

INPUT “Enter a word”;W$

CALL REV(W$)

END

 

SUB REV(W$)

FOR I=LEN(W$) to 1 step -1

C$=LEFT$(W$,I,1)

S$=D$+1

LOOP

PRINT “Reverse string is:”; D$

CLOSE SUB

 

 

26. [MFT 2076]

REM program to display reverse of supplied string

DECLARE SUB REVE (C$)

CLS

INPUT “Enter the value”; C$

FOLLOW REVE (C$)

END

 

SUB REVE(C$)

FOR J = 1 to LEN(C$)

B$ = MID$(C$, 1, J)

A$=A$+B$

LOOP J

PRINT A$

END SUB

27. [PMT 2075]

 

DECLARE FUNCTION REV$ (ST$)

CLS

INPUT “Enter string”, S$

LET R$= REV$(st$)

PRINT "The reverse string is :"; R$

END

 

FUNCTION REV$(ST$)

FOR I = LEN(ST$) TO 1

RV$= RV$+ MID$(ST$, 1, I)

NEXT I

RV$=REV$

END FUNCTION

 

 

28. MAAF MT 2079

REM to display the reverse of the supplied string

DECLARE SUB rev (s$)

CLS

INPUT n$

CALL rev$(n$)

END

 

SUB rev (n$)

FOR k=1 TO LEN(n$).

a$ = MID$(n$, 1, k)

p$ = p$ + n$

NEXT k

PRINT p$

END SUB

 

29. SEDIPS 2078

REM to count total number of word existing in a sentence input by a user.

DECLARE FUNCTION wordcount(W$)

CLS
LINE INPUT “Enter a sentence:”; S$

C=Wordcount(W$)

PRINT “Total number of word existing in a sentence”; C

END

 

FUNCTION wordcount$(W$)

FOR C=LEN(W$) to 1 STEP-1

CH$=MID(S, C, 1)

IF CH$=SPACE$(1) THEN CNT=CNT+1

NEXT C

CNT=wordcount

END FUNCTION

30. SEDIPS 2070

DECLARE FUNCTION word1(s$)

REM PROGRAM FOR COUNTING WORDS

s$= computer is an electronic machine

CALL word1(s$)

PRINT word1(s$)

END

FUNCTION word1(s$)

W=1

FOR K= 1 TO LENGTH(s$)

IF MID$(s$,K,1)= “ ” THEN W=W+1

NEXT K

          word1= W

 

31. PABSON PRE BOARD  2078

DECLARE FUNCTION PAL$ (W$)

CLS

INPUT "Enter a word"; W$

SHOW PAL$ (W$)

END

 

FUNCTION PAL$ (W$)

FOR I= LEN (W$) TO 1 STEP1

 R$=R$+MID$ (W$, I, 1)

NECT I

IF R$-W$ THEM

P$="Palindrome"

ELSE

P$="Not palindrome"

ENDIF

P$=PAL$

END FUNCTION

32. SEE Grade Promotion 2078 – 1

    REM to display records from existing file.

    CLS
    OPEN “emp.txt” FOR APPEND AS #1

    WHILE NOT EOF(#1)

    WRITE #1, eN$, post$, salary

    PRINT eN$, post$, salary

    CLOSE#1

    END

 

33. [SLC 2067] [JEC 2078]

REM to display all the records from sequential data file ABC.DAT
OPEN “ABC.DAT” FOR OUTPUT AS # 1

DO WHILE NOT EOF(“ABC.DAT”)
INPUT # 1,N$,A
PRINT N$,A
CLOSE 1
END

34. [SEE 2075 U]

REM program to read data from the data file.

OPEN “STD.DAT” FOR OUTPUT AS #1

CLS

WHILE NOT EOF(#1)

WRITE#1, N$, R, C, P

PRINT N$, R, C, P

WEND

CLOSE “STD.DAT”

END 

 

35. [SLC 2068 S]

Rem to display the contents of a data file.
OPEN “Marks.dat” FOR OUTPUT AS #1
CLS
WHILE EOF(1)
            INPUT #1, Name$, Age, Add$
            DISPLAY Name$, Age, Add$
WEND
CLOSE 1
END

 

36 [SLC 2069]

REM display Records of students From Data File

OPEN “STDREC.DAT” FOR INP AS #1

PRINT “ROLL”,”NAME”,”ADDRESS”,”CLASS”,”SECTION”

DO WHILE NOT EOF

            INPUT #1,RN,N$,AD$,CL,S$

            PRINT RN,N$,AD$,CL,S$

NEXT

CLOSE #1

            END

 

37. SET

REM to print only male record on the printer from the data file.

OPEN "EMP.DAT" FOR OUTPUT AS #1

DO

INPUT #4, N$, A%, S$

SELECT CASE S

CASE MALE

PRINT N$, A%, S$

END SELECT

LOOP UNTIL EOF(1)

STOP #1

 

38. [SEE 2074 U]

Rem To print only class 10 record from "student.dat" CLS

OPEN "I",#2, "Student.Dat"

WHILE NOT EOF (#2)   

WRITE#2, N$,C,R   

IF C=10 THEN            

DISPLAY N$,C,R   

END IF

NEXT

CLOSE #2

END

39. PABSON 2078 SET C

REM to count total no. of passed student

CLS
WHILE NOT EOF( )

OPEN “pab.txt” FOR OUTPUT AS #1

INPUT #2, ID, M1, M2, M3

IF M1>=32, M2.=32, M3.=32 THEN

X=X+1

END IF

WEND

PRINT “TOTAL RECORD”; X

END

40. NPABSON 2078

REM Program to display all the pass students records

OPEN “text.txt” FOR OUTPUT AS #5

PRINT “NAME”, “CLASS”, “RESULT”

DIO WHILE NOT EOF(5)

INPUT N$, C, R$

IF R$=”PASS” THEN PRINT #2, N$, C, R$

WEND

CLOSE #1

41. [SLC 2066 S]

REM To store Name, post and salary

OPEN “EMP.DOC” FOR OUT AS #1

INPUT” Enter name”;N

INPUT” Enter post”;P$

INPUT “Enter salary”;S

WRITE #2, N$,P$, S

CLOSE #1

END

42.  SET

REM to store name and age in a sequential data file STD.DOC

OPEN STD.DOC FOR OUT AS#1

INPUT “Enter name”;N

INPUT “Enter age”;A

WRITE 1,N$,A

CLOSE #1

END

43. SET

OPEN “EMPLOYEE.DAT” FOR OUTPUT AS #4

DO

INPUT “Enter employee name:”; N$

INPUT “Enter employees address:”; A$

INPUT “Enter employees age:”; A1

INPUT “Enter gender:”; G$

INPUT “Enter employees salary:”;S

WRITE #1,N$,A$,A1,G,S

INPUT “Add more records(Y/N):”;A

LOOP WHILE UCASE(A$)=”Y”

CLOSE #10

END

44. SEE MODEL SET 2

REM to create a new file

CLS

OPEN “ABC.DAT” FOR INPUT AS #1

DO

INPUT “Enter Name, Roll No & Total. “; N$, R, T

INPUT #1, N$, R, T

INPUT “Supply more records Y/N”; C$

LOOP WHILE UCASE(Y$)=”Y”

CLOSE #1

END

45. SEE MODEL SET 1

REM to add record in an existing file

CLS

OPEN “Record.Dat” FOR OUTPUT AS #1

AA:

INPUT “Enter Name, Class and Roll No.”; Nm$, Cl, Rn

INPUT #2, Nm$, Cl, Rn

INPUT “More records”; Y$

IF UCASE$(Y$)=”Y” THEN GOTO aa

CLOSE “Record.dat”

END

46. NPABSON PRE BOARD  2078

REM to add more data in a sequential file.

 OPEN “EMP.DAT” FOR INPUT AS #2

 DO

 INPUT “ENTER NAME”; N$

 INPUT “ENTER ADDRESS”; A$

 INPUT “ENTER SALARY”; S$

 WRITE #1, N$, A$, S

INPUT” Do you want to add more records.”; M$

LOOP WHILE UCASE(M$) = “Y”

END

47. [SLC 2070 S]

 

OPEN "STUDENT.DAT" FOR APPEND AS 1#
INPUT "NAME"; N$
INPUT "ADDRESS"; ADD$
INPUT "AGE"; AGE$
WRITE #1, N$, ADD$, AGE
          END# 1
           STOP

 

48. NPABSON 2070

REM TO ADD RECORDS IN “MARK.DAT” SEQUENTIAL DATAFILE

OPEN “A”, 2, “STDREC.DAT”

DO

INPUT “ROLL NUMBER, NAME, CLASS”; R, N$, C

WRITE #1, R, N$, C

INPUT “Want to continue(Y/N)”;H$

LOOP UNTIL UCASE$(H$)<> “Y”

TERMINATE #1

END

49.  COPY

REM COPY THE DATA OF “SRC.INF” TO “DEST.INF”

OPEN “SRC.INF” FOR INPUT AS #1

OPEN “DEST.INF” FOR OUTPUT AS #2

CLS

WHILE NOT EOF( )

INPUT #2, NM$, RN, AGE

WRITE #1, NM$, RN, AGE

CLOSE #1, #2

END

 

50. [SQE 2075K]

 

REM to copy from old file to new file
OPEN "info.dat" for INPUT AS #1
OPEN "temp.dat" for OUTPUT AS #2
DO UNTIL EOF(1)
INPUT #2, n$, p$, d$, s
WRITE #1, n$, p$, d$, s
WEND
CLOSE #2, #2
END

 

“Courage doesn’t always roar. Sometimes courage is the quiet voice at the end of the day saying ‘I will try again tomorrow’.”

– Mary Anne Radmacher

 

1 comment: