Connect Me

twitterfacebookgoogle plus email

  Instagram View Biwas Bhattarai's profile on LinkedIn
Showing posts with label SLC Nepal Computer Science. Show all posts
Showing posts with label SLC Nepal Computer Science. Show all posts

WAP to create a data file "Book.txt"

1)WAP to create a data file "Book.txt" and enter book name, author name, price, published year, and language used. Ask user to continue for next record.
2) WAP to display records from "Book.txt", where language used is "Nepali"
3) WAP to display records from "Book.txt", where price of a book is between 500 to 1000.
4) WAP to display records from "Book.txt", where published year is 2015 and author name starts with letter "N"
5) WAP to copy records from "Book.txt" to "Eng.txt" file where language used is "English"

1)
OPEN "BOOK.TXT" FOR OUTPUT AS #1
CLS
DO WHILE UCASE$(CH$)="Y" 
INPUT "ENTER BOOK NAME";BN$INPUT "ENTER AUTHOR NAME";AN$
INPUT "ENTER PRICE"; P
INPUT "ENTER PUBLISHED YEAR"; PY
INPUT "ENTER LANGUAGE OF THE BOOK";L$
WRITE #1, BN$, AN$, P, PY, L$
INPUT "DO YOU WANT TO ADD MORE (Y/N)"; CH$
LOOP
CLOSE #1
END

2)
OPEN "BOOK.TXT" FOR INPUT AS #1
CLS
PRINT "BOOKNAME", "AUTHORNAME", "PRICE","YEAR","LANGUAGE"
WHILE NOT EOF(1)
INPUT #1, BN$, AN$, P, PY, L$
IF UCASE$(L$)="NEPALI" THEN
PRINT BN$, AN$, P, PY, L$
END IF
WEND
CLOSE #1
END

3)
OPEN "BOOK.TXT" FOR INPUT AS #1
CLS
PRINT "BOOKNAME", "AUTHORNAME", "PRICE","YEAR","LANGUAGE"
WHILE NOT EOF(1)
INPUT #1, BN$, AN$, P, PY, L$
IF P>=500 AND P<=1000 THEN
PRINT BN$, AN$, P, PY, L$
END IF
WEND
CLOSE #1
END

4)
OPEN "BOOK.TXT" FOR INPUT AS #1
CLS
PRINT "BOOKNAME", "AUTHORNAME", "PRICE","YEAR","LANGUAGE"
WHILE NOT EOF(1)
INPUT #1, BN$, AN$, P, PY, L$
N$=LEFT$(AN$,1)
IF PY=2015 AND UCASE$(N$)="N" THEN
PRINT BN$, AN$, P, PY, L$
END IF
WEND
CLOSE #1
END

5)
OPEN "BOOK.TXT" FOR INPUT AS #1
OPEN "ENG.TXT" FOR OUTPUT AS #2
CLS
WHILE NOT EOF(1)
INPUT #1, BN$, AN$, P, PY, L$
IF UCASE$(L$)="ENGLISH" THEN
WRITE #2, BN$, AN$, P, PY, L$ 
END IF
WEND
CLOSE #1
CLOSE #2
END

Original file is BOOK.TXT. All records with language as ENGLISH will be copied to new file ENG.TXT.
WRITE #2, BN$, AN$, P, PY, L$ will copy into #2, which mean ENG.TXT file.

WAP to create a data file “info.dat” and enter the following details for 5 students.

WAP to create a data file “info.dat” and enter the following details for 5 students.
a. Name
b. Address
c. Class
d. Roll number
e. Section
f. House


OPEN "info.dat" FOR OUTPUT AS #1
FOR I=1 TO 5
INPUT "Enter your name "; n$
INPUT "Enter your address "; ad$
INPUT "Enter your class "; cl
INPUT "Enter your roll number "; rn
INPUT "Enter your Section "; s$
INPUT "Enter your House "; h$
WRITE #1, n$, ad$, cl, rn s$, h$
NEXT I
CLOSE #1
END

WAP to enter a string and print how many letter “P” are in the string. (If input is Pineapple, answer is 3)

DECLARE SUB TOTAL(P$)
CLS
INPUT "ENTER A STRING"; P$
CALL TOTAL(P$)
END

SUB TOTAL(P$)
P$=UCASE$(P$)
FOR I = 1 TO LEN(P$)
IF MID$(P$,I,1)="P" THEN C=C+1
NEXT I
PRINT "TOTAL NUMBER OF LETTER P IS "; C
END SUB

Same program using more number of lines (line with red color added for more elaboration)

DECLARE SUB TOTAL(P$)
CLS
INPUT "ENTER A STRING"; P$
CALL TOTAL(P$)
END

SUB TOTAL(P$)
Q$=UCASE$(P$)
L-LEN(Q$)
FOR I = 1 TO L
R$=MID$(Q$,I,1)
IF R$="P" THEN C=C+1
NEXT I
PRINT "TOTAL NUMBER OF LETTER P IS "; C
END SUB

Ą
https://www.flickr.com/photos/spklg/15211044551/