Full width home advertisement

Grade 10 Revision

Post Page Advertisement [Top]

QBASIC and C Programming

QBASIC and C Programming











IMPORTANT QUESTIONS

1.Write a QBASIC program using sub procedure to reverse the given string. 

Ans.

DECLARE SUB REV(N$)

INPUT”ENTER A STRING”;N$

CALL REV(N$)

END

SUB REV(N$)

FOR I =LEN(N$) TO 1 STEP-1

K$= MID$(N$,I,1)

R$= R$+ K$

NEXT I 

PRINT “THE REVERSED STRING IS “; R$

END SUB



2.Write a QBASIC program using sub procedure to reverse the given number.

Ans.

DECLARE SUB REV(N)

INPUT”ENTER A NUMBER”;N

CALL REV(N)

END

SUB REV(N)

P=N

WHILE N<>0

R= N MOD 10

S= S*10 + R

N = N\10

WEND

PRINT”THE REVERSED NUMBER IS:”;S

END SUB 



3.Write a QBASIC program using Function ... End Function to find the area of parallelogram. [Hint: A= (B*H)]

Ans.

DECLARE FUNCTION AREA(B,H)

INPUT”ENTER BASE AND HEIGHT”;B,H

PRINT”THE AREA OF PARALEELOGRAM IS”;AREA(B,H)

END

FUNCTION AREA(B,H)

A= B*H

AREA=A

END FUNCTION 


4.Write a QBASIC program using Function ... End Function to find the HCF of two numbers.

Ans.

DECLARE FUNCTION HCF(A,B)

INPUT”ENTER TWO NUMBERS”;A,B

IF A>B THEN SWAP A,B

PRINT”THE HCF OF TWO NUMBERS IS”;HCF(A,B)

END

FUNCTION HCF(A,B)

FOR I = 1 TO A

IF A MOD I= 0 AND B MOD I=0 THEN

H=I

END IF

NEXT I

HCF=H

END FUNCTION


5.A sequential data file called “staff.dat” contains some records under fields name, post and salary of employees. Write a program to display records whose salary is between 15000 to 600000.

Ans.

OPEN “staff.dat” FOR INPUT AS#1

CLS

WHILE NOT EOF(1)

INPUT#1, N$, P$, S

IF S<=150000 AND S>= 600000

PRINT N$,P$,S

END IF

WEND

CLOSE #1

END


6.WAP to create a sequential file named “staff.dat” and store records under the fields name, post and salary. The program should terminate when user desires.

Ans.

OPEN “staff.dat” FOR OUTPUT AS #1

DO

INPUT”ENTER NAME”;N$

INPUT”ENTER POST”;P$

INPUT”ENTER SALARY”;S

WRITE #1,N$, P$,S

INPUT”DO YOU WANT TO CONTINUE?(Y/N)?”;CH$

LOOP WHILE UCASE$(CH$)=”Y”

CLOSE #1

END

7.WAP to store the details of 5 students in the file “student.rec” containing the fields name, percentage and section.

Ans.

OPEN “staff.dat” FOR OUTPUT AS #1

FOR I= 1 TO 5

INPUT”ENTER NAME”;N$

INPUT”ENTER POST”;P$

INPUT”ENTER SALARY”;S

WRITE #1,N$, P$,S

NEXT I

CLOSE #1

END


8.WAP to count the total number of records from the sequential file“staff.dat” containing some records under fields name, post and salary of employees.

Ans.

OPEN “staff.dat” FOR INPUT AS#1

CLS

WHILE NOT EOF(1)

INPUT#1, N$, P$, S

C=C+1

WEND

PRINT”THE TOTAL RECORDS IS”;C

CLOSE #1

END


9.Analyze the given program and answer the questions:

DECLARE FUNCTION factorial(N)

INPUT "Enter any number : " ; N

Print "The Factorial is "; factorial(N)

End


FUNCTION factorial(N)

D = 1

FOR I= 1 TO N

    D = D * I

NEXT I

factorial = D

End Function

(a) Which loop is used in above program?

Ans. FOR… NEXT loop

(b) Write the name of procedure used in above program.

Ans. factorial


10. Analyze the given program and answer the questions:

DECLARE SUB res(a$)

CLS

A$="CANDLELIGHTS"

CALL res(a$)

END

SUB res(a$) L=LEN(a$)

FOR x= L to 1 STEP -2

PRINT MID$(a$, x, 1);

NEXT x

END SUB

a. Does the program execute if DECLARE SUB… is removed?

Ans. Yes, it runs.

b. What will be the output if we change STEP -2 into STEP-3 ?

Ans. SGEN


11.Read the following program and answer the following questions.  

DECLARE FUNCTION COUNT(A$)

Input “Enter a word”; W$

END


FUNCTION COUNT(A$)

B=LEN(A$)

C$=UCASE$(A$)

FOR I=1 TO B

E$=MID$(C$,I,1)

IF E$=”A” OR E$=”E” OR E$=”I” OR E$=”O” OR E$=”U” THEN C=C+1

END IF

NEXT I

COUNT=C

END FUNCTION

a) List the string Library functions used in the above program.

Ans. MID$, LEN, UCASE$

b) Write down the missing statements in the main module to execute the program.

Ans. Print COUNT(A$)



12.Study the following program and answer the given questions.

DECLARE SUB RESULT ( )

CLS

CALL RESULT

END

SUB RESULT ( )

        W$=”SCIENCE”

        L=LEN (W$)

        X=1; Y=3

        FOR I=1 TO L STEP 2

        PRINT TAB (Y); MID$(W$,X,L)

        X=X+1

        L=L-2

        Y=Y+1

    NEXT I

   END SUB

a.) Name the  user defined function used in the above program.

Ans. RESULT

b.) How many times does the loop execute? 

Ans. 7 times


13.Find the output of given program:

DECLARE SUB RESULT ( )

CLS

CALL RESULT

END

SUB RESULT ( )

        W$=”ROSEBUD”

        L=LEN (W$)

        X=1; Y=3

        FOR I=1 TO L STEP 2

        PRINT TAB (Y); MID$(W$,X,L)

        X=X+1

        L=L-2

        Y=Y+1

    NEXT I

    END SUB


Ans.

      ROSEBUD

        OSEBU

          SEB

            E


14.Write down the output of following program.                                    
DECLARE SUB Result (  )
CALL Result 
END

SUB Result 
For I = 1 to 9 STEP 2
Sum=Sum +I^2
Next I
PRINT Sum
END SUB

Ans. 
165



15.Write down the output of following program.                                    
DECLARE SUB Series ( ) 
CALL Series 
END

SUB Series ( ) 
N=2
C=1 
WHILE C<=10 
       PRINT N 
       N=N+C 
       C=C+1 
WEND
END SUB

Ans.
2  3  5  8  12  17  23  30  38  47



16.Re-write the given program after correcting the bugs.       
REM To display all the records from emp.dat file
OPEN "emp.dat" FOR APPEND AS#1
WHILE NOT FOE()
WRITE 1,N$,A$
PRINT N$,A$
LOOP
CLOSE #1
END

Ans.
REM To display all the records from emp.dat file
OPEN "emp.dat" FOR INPUT AS#1
WHILE NOT EOF(1)
INPUT #1,N$,A$
PRINT N$,A$
WEND
CLOSE #1
END


17.Rewrite the given program after correcting the bugs.
REM display Records of students From Data File
OPEN "XYZ.TXT" FORINP AS #2
PRINT "ROLL", "NAME", "ADDRESS", "CLASS", "SECTION"
DO WHILE NOT EOF
    INPUT #1, RN, N$, AD$, CL, S$
    PRINT RN, N$, AD$, CL, S$
NEXT
CLONE #2
END

Ans.
REM display Records of students From Data File
OPEN "XYZ.TXT" FOR INPUT AS #2
PRINT "ROLL", "NAME", "ADDRESS", "CLASS", "SECTION"
DO WHILE NOT EOF(2)
    INPUT #1, RN, N$, AD$, CL, S$
    PRINT RN, N$, AD$, CL, S$
WEND
CLOSE #2
END


18.Re-write the given program after correcting the bugs.    
REM to add more records as per user’s choice
OPEN sal.dat FOR INPUT AS#1
DO
INPUT"Enter name ";N$
INPUT"Enter Address";A $
WRITE #2,N$,A$
INPUT “Add more records (Y/N)”;Choice$
LOOP WHILE UCASE(CH$)=”Y”
CLOSE #1
END

Ans.
REM to add more records as per user’s choice
OPEN "sal.dat" FOR APPEND AS#1
DO
INPUT"Enter name ";N$
INPUT"Enter Address";A $
WRITE #1,N$,A$
INPUT “Add more records (Y/N)”;Choice$
LOOP WHILE UCASE(Choice$)=”Y”
CLOSE #1
END


19. Define library functions.
Ans. The predefined readymade function provided by the compiler or interpreter which can be called to do a particular operation and cannot be used as user defined function is called library function. Eg. INT    
                                                               
20. Why is C called middle level language?    
Ans. C is the high level language that resembles some features of low level language, that’s why it is called middle level language.      
21.Write down the function of the following statements:         
i) KILL: It deletes the particular file from the sub-directory       
ii) INPUT#: It reads data from sequential data file

22.Differentiate between sub and function procedure.
Ans.
i. SUB requires to call the procedure whereas function requires to print the procedure.
ii. SUB does not return the value whereas function returns the value.

23.Write any two advantages of structured programming.
Ans.
i. It divides the complex program into simple functionable modules.
ii. It is based on normal algorithmic approach ie, top-down approach.

24.Write the functions of 
i.RMDIR: It removes the specified subdirectory 
ii.NAME: It renames the specified file.
iii. OPEN: It opens the sequential file in INPUT, OUTPUT or APPEND mode.
iv.CLOSE: It closes the files opened in INPUT, OUTPUT or APPEND mode
v. MKDIR: It creates a sub directory 

25. List any two data types used in C.
Ans. int, char

27. Differentiate between C and QBASIC.
Ans.
i. C is middle level language whereas QBASIC is high level langauge
ii. C supports only function procedure whereas QBASIC supports both function procedure and sub procedure.

28. Define looping.
Ans. The block of codes executed repeatedly in a program is called looping.

29.Mention the types of procedure.
Ans. The types of procedure are:
i. Sub Procedure
ii. Function Procedure

30. Define global and local variable.
Ans. The variable that lies in the Declare part and whose scope is throughout the program is called global variable.
The variable whose scope is only within a particular sub module is called local variable.


31. Write down the output of the given program. Show with dry run in table.                                    

DECLARE SUB PATTERN ( )

CALL PATTERN

END

 

SUB PATTERN

A=1

FOR I = 1 TO 10

PRINT A

A=A+2

NEXT I

END SUB



Ans.  

1  3  5  7  9  11 13  15  17  19 



32. Re-write the given program after correcting the bugs.    

REM  Sub program to find average of three numbers

DECLARE SUB AVG (A,B,C)

INPUT “ENTER ANY THREE NUMBERS” , A,B,C

CALL SUB AVG(A,B,C)

END

 

SUB AVG(A,B,C)

A= (A+B+C)/3

DISPLAY “AVERAGE OF THREE NUMBERS IS” ; B

SUB END


Program after correction:

REM  Sub program to find average of three numbers

DECLARE SUB AVG (A,B,C)

INPUT “ENTER ANY THREE NUMBERS” , A,B,C

CALL  AVG(A,B,C)

END

 

SUB AVG(A,B,C)

S= (A+B+C)/3

PRINT “AVERAGE OF THREE NUMBERS IS” ; S

END SUB


33. Study the following program and answer the given questions.                                                          

DECLARE SUB FACT (N)

INPUT “ENTER ANY NUMBER”, N

CALL FACT (N)

END

 

SUB FACT(N)

F= 1

FOR I = 1 TO 10

      F = F * I

      PRINT F

NEXT I

END SUB



a. Write the sub procedure name used in above program.  

Ans. FACT


b.Will the program run, if Declare Sub ... is removed from above program?

Ans. Yes, it runs.

 

    34. Write a SUB program to check whether the supplied number is even or odd.

DECLARE SUB CHECK(N)

INPUT "ENTER A NUMBER ";N

CALL CHECK(N)

END

SUB CHECK(N)

IF N MOD 2 = 0 THEN

    PRINT "IT IS EVEN"

    ELSE

    PRINT "IT IS ODD"

END IF

END SUB

 

 

35.  Write a program to check whether the given number is positive, negative or zero using Sub… end sub.

 

DECLARE SUB CHECK(N)

INPUT "ENTER A NUMBER ";N

CALL CHECK(N)

END

SUB CHECK(N)

IF N > 0 THEN

    PRINT "IT IS POSITIVE"

    ELSEIF N<0 THEN

    PRINT "IT IS NEGATIVE"

ELSE

PRINT “IT IS ZERO”

END IF

END SUB

 

 

36. WAP to find simple interest using SUB…. END SUB

DECLARE SUB INTEREST( P, T , R )

INPUT “ENTER PRINCIPAL, TIME AND RATE ”; P, T , R

CALL INTEREST( P, T , R )

END

SUB INTEREST( P, T , R )

I = ( P* T * R )/ 100

PRINT “THE SIMPLE INTEREST  IS :”;I

END SUB 


37. WAP using sub to display the multiplication table of a given number. 

 

DECLARE SUB MUL(N)
INPUT”ENTER A NUMBER”;N
CALL MUL(N)
END
SUB MUL(N)
FOR I = 1 TO 10
PRINT N; “X” ; I; “=”;N*I
NEXT I

END SUB

 

  38WAP TO PRINT THE POSSIBLE FACTORS OF GIVEN NUMBER USING SUB END SUB.

 DECLARE SUB FACTOR(N)

INPUT “ENTER A NUMBER”;N

CALL FACTOR(N)

END

SUB FACTOR(N)

PRINT” THE FACTORS OF”;N; “ARE”

FOR I = 1 TO N

IF N MOD I =0 THEN PRINT I

NEXT I

END SUB

 

 39.  WAP to find the factorial of a given number using Sub End Sub.

 DECLARE SUB FACT (N)    

INPUT”ENTER A NUMBER”;N

CALL FACT (N)

END

SUB FACT (N)

F=1

FOR I = 1 TO N

F = F* I

NEXT I

PRINT “THE FACTORIAL OF”;N; “IS”; F

END SUB


 40.  WAP to check whether the multidigit number is palindrome or not using SUB.. END… SUB.

 DECLARE SUB REV(N)

INPUT”ENTER A MULTIDIGIT NUMBER”;N

CALL REV(N)

END

SUB REV(N)

P=N

WHILE N<>0  

R= N MOD 10

S=S*10+R

N=N\10  

WEND

IF P= S THEN

PRINT “IT IS PALINDROME”

ELSE

PRINT “IT IS NOT PALINDROME”

END IF

END SUB

 

 

41. WAP to check whether the multidigit number is Armstrong or not using SUB.. END… SUB.

 DECLARE SUB ARM(N)

INPUT”ENTER A MULTIDIGIT NUMBER”;N

CALL ARM(N)

END

SUB ARM(N)

P=N

WHILE N<>0  

R= N MOD 10

S=S+ R^3

N=N\10  

WEND

IF P= S THEN

PRINT “IT IS ARMSTRONG”

ELSE

PRINT “IT IS NOT ARMSTRONG”

END IF

END SUB 

 

 

 


No comments:

Post a Comment

Bottom Ad [Post Page]