Computer Science


1. Write a program to read the records from the file "RESULT.DAT" and display only those records whose percentage is greater than 80 and less than 90. Also count the total number of records presenting in the data file.
Ans:
OPEN “RESULT.DAT” FOR INPUT AS #1
WHILE NOT EOF(1)
LINE INPUT #1, N$, A$,NEP,ENG,SCI,COMP,HP
C=C+1

TOTAL=NEP+ENG+SCI+COMP+HP
PER=(TOTAL/500)*100
IF PER>80 AND PER<90 THEN
WEND
CLOSE#1
PRINT “NO. OF RECORDS DISPLAYED AND PER=”;C, PER
END
 ----------------------------------------------------------------------------------------------------------------------------------
2.    A data file named "STAFF.DAT" contains some records have fields name, post and salary. Write a program to count the total number of officers in the office.
   
OPEN “REC.DAT” FOR INPUT AS #1
WHILE NOT EOF(1)
LINE INPUT #1, POST$
C=C+1
WEND
CLOSE#1
PRINT “NO. OF OFFICERS DISPLAYED=”;POST$
            END 


 ----------------------------------------------------------------------------------------------------------------------------------
3.    Write a program to read all the data of the data file named "REASULT.DAT" and display only those records whose name is start from "S".
Ans :

Ans: OPEN “RESULT.DAT” FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, N$,A$,NEP,ENG,SCI,SOC,HP
CH$= MID$(N$,1,1)
IF CH$="S" THEN
WEND
CLOSE#1
PRINT N$,A$,NEP,ENG,SCI,SOC,HP
END
 ----------------------------------------------------------------------------------------------------------------------------------
4.    A data file "SALARY.DAT" contains the information of employees name, address and salary. Write a program to display all the information of employees whose salary is more than 25,000 and less than 45,000.
Ans:
OPEN “SALARY.DAT” FOR INPUT AS#1
CLS
WHILE NOT EOF(1)
INPUT #1, N$,A$,S
IF S>=25000 AND S=45000 THEN
PRINT N$,P$,S
END IF
WEND
CLOSE#1
END


 -------------------------------------------------------------------------------------------------------------------
  5.      A sequential data file "student.dat" has 50 records having field roll number, name, class and address. Write a program to display from 30th to 40th records.
OPEN "STUDENT.DAT" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, R, N#, C, A$
IF R>=30 AND R<=40 THEN
PRINT R, N#, C, A$
END IF
WEND
CLOSE#1
END
 ----------------------------------------------------------------------------------------------------------------------------------
6. Write a program to calculate the sum of each digit of user entered number using sub …. End sub.

Answer: 

DECLARE SUB digit(n)

INPUT “Enter any digit”; n

CALL digit(n)

END


SUB  digit (n)

WHILE n <> 0

R= n mod 10

S= s+r

N = n\10

WEND
PRINT “Sum of digits is”; s
End sub
  ----------------------------------------------------------------------------------------------------------------------------------
7. Write a program to accept any ten numbers and print largest and smallest number among them using function function procedure.

Answer:
REM Accept any ten numbers and display largest and smallest number
DECLARE FUNCTION GREAT()
DECLARE FUNCTION SMALL()
DIM SHARED N(10)
CLS
FOR I = 1 TO 10
INPUT "ENTER THE NUMBERS";N(I)
 NEXT I
PRINT"GREATEST NUMBER"; GREAT
PRINT"SMALLEST NUMBER"; SMALL
END

FUNCTION GREAT
G=N(1)
FOR I = 2 TO 10
IF N(I)>G THEN G = N(I)
NEXT I
GREAT = G
END FUNCTION

FUNCTION SMALL
S= N(1)
FOR I = 2 TO 10
IF N(I)< S THEN S = N(I)
NEXT I
SMALL = S
END FUNCTION
 ----------------------------------------------------------------------------------------------------------------------------------
8. Write a qbasic program to accept name of five person and print longest and shortest name. 
REM Accept name of five person and print longest and shortest name
CLS
DIM n(5) AS STRING
FOR i = 1 TO 5
    INPUT "enter five name"; n(i)
NEXT i
a$ = n(1)
b$ = n(1)
FOR j = 2 TO 5
    IF LEN(n(j)) > LEN(a$) THEN a$ = n(j)
    IF LEN(n(j)) < LEN(b$) THEN b$ = n(j)

NEXT j
PRINT "the longest name is "; a$
PRINT "the shortest name is "; b$
END
 ----------------------------------------------------------------------------------------------------------------------------------
9. Write a qbasic program to accept name of five person and print longest name using FUNCTION procedure. 

declare function long$(a$)
CLS
INPUT "enter first name"; a$
PRINT lon(a$)
END
FUNCTION lon$ (a$)
    FOR i = 2 TO 5
        INPUT "enter next name "; b$
        IF LEN(b$) > LEN(a$) THEN a$ = b$
    NEXT i
    lon$ = a$
END FUNCTION
 ----------------------------------------------------------------------------------------------------------------------------------
10. Write a qbasic program to accept name of five person and print shortest name using FUNCTION procedure.

declare function shrt$(a$)
CLS
INPUT "enter first name"; a$
PRINT shrt(a$)
END
FUNCTION shrt$ (a$)
    FOR i = 2 TO 5
        INPUT "enter next name "; b$
        IF LEN(b$) < LEN(a$) THEN a$ = b$
    NEXT i
    shrt$ = a$
END FUNCTION
 


No comments:

Post a Comment