WAP using SUB procedure to enter a string and print the characters of even position only. (Example: KATHMANDU, output is AHAD)
DECLARE SUB EVEN(E$)
CLS
INPUT "INPUT A WORD/STRING";E$
CALL EVEN(E$)
END
SUB EVEN(E$)
FOR I=1 TO LEN(E$)
F$=MID$(E$,I,1)
IF I MOD 2=0 THEN PRINT F$;
NEXT I
END SUB
Showing posts with label SLC qbasic. Show all posts
Showing posts with label SLC qbasic. Show all posts
QBASIC Modular Programming
- A modular programming is breaking down the design of a program into individual components (modules) that can be programmed and tested independently.
- A sub procedures is a block of statements that carries out a well-defined task.
- A function procedure is a type of procedure that returns a value whenever it is called.
- Arguments are the parameters passed to the procedure.
- Recursion is a programming technique that allows the programmer to express operations in terms of themselves.
- A global variable is declared inside a procedure, and is not accessible outside the procedure.
- A local variable is declared outside all procedures and is accessible in its scope.
QBASIC Program to get the factorial of a supplied number
DECLARE FUNCTION fact (n)
CLS
INPUT "Supply a number"; n
CLS
INPUT "Supply a number"; n
Create a data file to display the records with the students name starting with "B"
Solution:
REM PROGRAM DISPLAYING THE NAMES OF STUDENTS STARTING WITH LETTER "B"
CLS
OPEN "MARKS.DAT" FOR INPUT AS #1
DO WHILE NOT EOF(1)
REM PROGRAM DISPLAYING THE NAMES OF STUDENTS STARTING WITH LETTER "B"
CLS
OPEN "MARKS.DAT" FOR INPUT AS #1
DO WHILE NOT EOF(1)
Create a data file to display all the records of above file "Marks.dat"
Solution:
REM PROGRAM TO DISPLAY ALL THE RECORDS OF THE GIVEN FILE
CLS
OPEN "MARKS.DAT" FOR INPUT AS #1
PRINT "NAME", "ENGLISH", "COMPUTER", "SCIENCE"
REM PROGRAM TO DISPLAY ALL THE RECORDS OF THE GIVEN FILE
CLS
OPEN "MARKS.DAT" FOR INPUT AS #1
PRINT "NAME", "ENGLISH", "COMPUTER", "SCIENCE"
SLC QBASIC File Handling
WAP in QBASC to enter the records of variable numbers of employee with the following details:
1) Employee ID
2) Full Name
3) Full Address
4) DOB
5) Post
6) Salary
Program:
CLS
OPEN "EMP.DAT" FOR OUTPUT AS #1
INPUT "How many records do you want to enter";N
FOR I=1 TO N
INPUT "Enter Employee ID";EID$
INPUT "Enter Employee fullname";FN$
INPUT "Enter Address";ADD$
INPUT "Enter DOB(mm-dd-yyyy)";DOB$
INPUT "Enter Post";P$
INPUT "Enter Salary"; S
WRITE #1, EID$,FN$,ADD$,DOB$,P$,S
NEXT I
CLOSE #1
END
OR
CLS
OPEN "EMP.DAT" FOR OUTPUT AS #1
repeat:
INPUT "Enter Employee ID";EID$
INPUT "Enter Employee fullname";FN$
INPUT "Enter Address";ADD$
INPUT "Enter DOB(mm-dd-yyyy)";DOB$
INPUT "Enter Post";P$
INPUT "Enter Salary"; S
WRITE #1, EID$,FN$,ADD$,DOB$,P$,S
INPUT "Do You want to add more records (Y/N)";CHOICE$
IF UCASE$(CHOICE$)="Y" THEN GOTO repeat
CLOSE #1
END
QBASIC - File Handling
WAP to store roll num, name, grade, section, of 10 students in "stu.dat" data file.
cls
OPEN "Stu.dat" for OUTPUT AS #1
FOR I=1 TO 10
INPUT SRN
INPUT NA$
INPUT S$
WRITE #1, SRN, NA$, S$
NEXT I
CLOSE#1
END
cls
OPEN "Stu.dat" for OUTPUT AS #1
FOR I=1 TO 10
INPUT SRN
INPUT NA$
INPUT S$
WRITE #1, SRN, NA$, S$
NEXT I
CLOSE#1
END
SLC QBASIC- Array problems
WAP to ask user 20 different integers and print the sum of positive numbers only.
DECLARE SUB SUM(N())
DIM N(20)
CLS
PRINT "Enter 20 integers"
FOR I= 1 TO 20
INPUT "Number";N(I)
NEXT I
CALL SUM(N())
END
SUB SUM(N())
FOR J=1 TO 20
IF N(J)>0 THEN S=S+N(J)
NEXT J
PRINT "Sum of positive numbers is ";S
END SUB
WAP to ask user 10 different numbers and print the greatest number.
DECLARE SUB GREAT(N())
DIM N(10)
CLS
PRINT "Enter 10 numbers"
FOR I= 1 TO 10
INPUT "Number";N(I)
NEXT I
CALL GREAT(N())
END
SUB GREAT(N())
FOR J=1 TO 10
IF N(J)>G THEN G=N(J)
NEXT J
PRINT "Greastest number is ";G
END SUB
DECLARE SUB SUM(N())
DIM N(20)
CLS
PRINT "Enter 20 integers"
FOR I= 1 TO 20
INPUT "Number";N(I)
NEXT I
CALL SUM(N())
END
SUB SUM(N())
FOR J=1 TO 20
IF N(J)>0 THEN S=S+N(J)
NEXT J
PRINT "Sum of positive numbers is ";S
END SUB
WAP to ask user 10 different numbers and print the greatest number.
DECLARE SUB GREAT(N())
DIM N(10)
CLS
PRINT "Enter 10 numbers"
FOR I= 1 TO 10
INPUT "Number";N(I)
NEXT I
CALL GREAT(N())
END
SUB GREAT(N())
FOR J=1 TO 10
IF N(J)>G THEN G=N(J)
NEXT J
PRINT "Greastest number is ";G
END SUB
File Handling in Qbasic
QBasic Program display only the list of pass student
CLSOPEN "RESLUT.TXT" FOR INPUT AS #1
PRINT "RN", "NAME", "ENGLISH","NEPALI", "MATHS"
WHILE NOT EOF (1)
INPUT#1, RN,N$,ENG,NEP,MAT
IF ENG>=40 AND NEP>=40 AND MAT>=40 THEN
PRINT RN, N$, ENG, NEP, MAT
END IF
WEND
CLOSE #1
END
QBASIC Program using DO LOOP UNTIL
Display the first 10 natural numbers using DO .... UNTIL LOOP
CLSA=1
DO UNTIL A>10
PRINT A
A=A+1
LOOP
END
QBASIC Program to get the factorial of a supplied number
REM QBASIC Program to get the factorial of a supplied number
DECLARE FUNCTION fact (n)CLS
INPUT "Supply a number"; n
PRINT "Factorial value of"; n; "is"; fact(n)
END
FUNCTION fact (n)
f = 1
c = 1
WHILE c <= n f = f * c c = c + 1 WEND fact = f END FUNCTION
QBASIC Program to display prime digits of a supplied number
REM QBASIC Program to display prime digits of a supplied number
Declare Sub Disprime(n)
CLS
INPUT n
Call Disprime(n)
End
Sub Disprime(n)
m = n
PRINT "Prime digits are ";
WHILE n <> 0
r = n MOD 10
c = 0
n = n \ 10
FOR i = 1 TO r
IF r MOD i = 0 THEN c = c + 1
NEXT i
IF c = 2 THEN PRINT r
WEND
End SUB
Declare Sub Disprime(n)
CLS
INPUT n
Call Disprime(n)
End
Sub Disprime(n)
m = n
PRINT "Prime digits are ";
WHILE n <> 0
r = n MOD 10
c = 0
n = n \ 10
FOR i = 1 TO r
IF r MOD i = 0 THEN c = c + 1
NEXT i
IF c = 2 THEN PRINT r
WEND
End SUB
QBASIC
REM QBASIC Program to display only Armstrong Numbers from 1 to 1000
DECLARE SUB arm ()
CLS
CALL arm
END
SUB arm
PRINT "Armstrong numbers from 1 to 1000 are "
FOR n = 1 TO 1000
i = n
a = 0
WHILE i <> 0
r = i MOD 10
a = a + (r ^ 3)
i = i \ 10
WEND
IF a = n THEN PRINT a
NEXT n
END SUB
DECLARE SUB arm ()
CLS
CALL arm
END
SUB arm
PRINT "Armstrong numbers from 1 to 1000 are "
FOR n = 1 TO 1000
i = n
a = 0
WHILE i <> 0
r = i MOD 10
a = a + (r ^ 3)
i = i \ 10
WEND
IF a = n THEN PRINT a
NEXT n
END SUB
SLC QBASIC Programs
Palindrome string
REM Program to check whether a supplied string is palindrome or not
CLS
INPUT "ENTER A STRING/WORD";N$
L=LEN(N$)
FOR I= 1 TO L
M$=MID$(N$,I,1)+M$
NEXT I
IF M$=N$ THEN
PRINT "THE SUPPLIED STRING IS PALINDROME"
ELSE
PRINT "THE SUPPLIED STRING IS NOT PALINDROME"
END IF
END
Subscribe to:
Posts (Atom)





