-->
Showing posts with label Grade 10 computer science. Show all posts
Showing posts with label Grade 10 computer science. Show all posts

Sunday, June 8, 2025

Qbasic program to get output using dry run table | SEE computer science programming guide in Qbasic - to count total words

 


QBasic programs collection-Especially for SEE (Grade-10)



QBasic program to know the output of program using dry run table- to count total words.

declare function wordcount%(s$)
Cls
Input "enter a sentence", line$
Print "total words=", wordcount%(line$)
End
Function wordcount% (s$)
    count = 1
    For i = 1 To Len(s$)
        If Mid$(s$, i, 1) = " " Then
            count = count + 1
        End If
    Next i
    wordcount% = count

End Function


output:

 Dry run table for ouput is given below.
IF we take the input Hello how are you?,

S$

Count

I= 1 to len(s$)[17]

Mid$(s$,I,1)= “ “

 

Hello how are you?

1

I=1

No upto five times

 

 

 

I=6

Yes, count=2

 

 

 

I=7/8/9

no

 

 

 

I=10

Yes, count=3

 

 

 

I=11/12/13

no

 

 

 

I=14

Yes,count=4

 

 

 

I=15/16/17

no

 


output is
4

Qbasic program to get output using dry run table | SEE computer science programming guide in Qbasic-2

 


QBasic programs collection-Especially for SEE (Grade-10)



QBasic program to know the output of program using dry run table(p-2)



declare function reverse$(s$)

Cls

Input "enter a string"; s$

Print "the reverse of a string is"; reverse(s$)

End

Function reverse$ (s$)

    For i = Len(s$) To 1 Step -1

        r$ = r$ + Mid$(s$, i, 1)

    Next i

    reverse$ = r$

End Function

Output with dry run table:

If the input is 'program' then its dry run can be

S$

For i=len(s$) to 1 step-1

r$=r$+mid$(s$,I,1)

 

program

I=7

r$=m

 

 

I=6

r$=m+a=ma

 

 

I=5

R$=ma+r=mar

 

 

I=4

r$=mar+g=marg

 

 

I=3

r$=marg+o=margo

 

 

I=2

r$=margo+r=margor

 

 

I=1

r$=margor+p=margorp

 



Output:

margorp


Qbasic program to get output using dry run table | SEE computer science programming guide in Qbasic

 QBasic programs collection-Especially for SEE (Grade-10)


QBasic program to know the output of program using dry run table


declare function onlydigits$(text$)

Cls

Input "enter a string"; s$

Print "the digits in that string ="; onlydigits$(s$)

End

Function onlydigits$ (s$)

    For i = 1 To Len(s$)

        r$ = Mid$(s$, i, 1)

        If r$ >= "0" And r$ <= "9" Then

            digits$ = digits$ + r$

        End If

    Next i

    onlydigits$ = digits$

End Function


Dry run table with output:

If the input is 'Grade 12', the dry run table can  be written as below.

S$

I=1 to len(s$)

1 to 8;

r$= Mid$(s$, i, 1)

if r$ >= "0" And r$ <= "9"

Digits$

Grade 12

i=1

r$=G

no

 

 

I=2

r$=r

no

 

 

I=3

R$=a

no

 

 

I=4

r$=d

No

 

 

I=5

r$=e

No

 

 

I=6

r$=space

No

 

 

I=7

r$=1

yes

Digits$=1

 

I=8

r$=2

yes

Digits$=1+2=12

 

 

 

 

    onlydigits$ = digits$

onlydigits$=12

 

output=12