To find the surface area of a sphere. (Qbasic Code)

  • To find the surface area of a sphere. (Qbasic Code)
CLS
INPUT "Enter radius of sphere"; r
LET pie = 3.14
A = 4 * pie * r ^ 2
PRINT "The total surface area of the sphere is"; A
END


  • Using SUB Procedure
DECLARE SUB TSA (r)
CLS
INPUT "Enter radius of the sphere"; r
CALL tsa(r)
END

SUB tsa (r)
LET pie = 3.14
A = 4 * pie * r ^ 2
PRINT "The total surface area of the sphere is"; A
END SUB


  • Using FUNCTION Procedure
DECLARE FUNCTION TSA (r)
CLS
INPUT "Enter radius of the sphere"; r
PRINT "The total surface area of the sphere is"; TSA(r)
END

FUNCTION TSA (r)
LET pie = 3.14
A = 4 * pie * r ^ 2
TSA = A
END FUNCTION

To create a data file MARK.DAT and stores name, address and marks in any three subjects for five students. (Qbasic)

  • Write a program to create a data file "MARK.DAT" and stores name, address and marks in any three subjects for five students. (Qbasic)
CLS
OPEN "MARK.DAT" FOR OUTPUT AS #1
FOR I = 1 TO 5
    INPUT "Enter name"; N$
    INPUT "Enter address"; A$
    INPUT "Enter mark in subject 1"; S1
    INPUT "Enter mark in subject 2"; S2
    INPUT "Enter mark in Subject 3"; S3
    WRITE #1, N$, A$, S1, S2, S3
NEXT I
CLOSE #1
END

A program to create a data file STD.DAT which stores Roll number, Name, Class and age of student. (Qbasic)

  • Write a program to create a data file "STD.DAT" which stores Roll number, Name, Class and age of student. Age of students must be from 15 to 19. (Qbasic)
CLS
OPEN "STD.DAT" FOR OUTPUT AS #1
INPUT "Enter Roll number"; R
INPUT "Enter Name"; N$
INPUT "Enter Class"; C$
1:
INPUT "Enter Age (15 to 19)"; A
IF A >= 15 AND A <= 19 THEN
    WRITE #1, R, N$, C$, A
ELSE
    PRINT "Please enter correct age"
    GOTO 1
END IF
CLOSE #1
END

To create a serial file having variable name, department and telephone number. (Qbasic)

  • Write a program to create a serial file having variable name, department and mobile number. Mobile number should be in between 1000000000 to 9999999999. (Qbasic)
CLS
OPEN "RECORD.DAT" FOR OUTPUT AS #1
INPUT "Enter name"; N$
INPUT "Enter department"; D$
1:
INPUT "Enter mobile number "; T
IF T > 9000000000 AND T < 9999999999 THEN
    WRITE #1, N$, D$, T
ELSE
    PRINT "Wrong mobile number"
    GOTO 1
END IF

A program to convert temperature in celsius to fahrenheit (Qbasic)

PROGRAM TO CONVERT TEMPERATURE IN CELSIUS TO FAHRENHEIT (Qbasic)
CLS
INPUT “ENTER TEMPERATURE IN CELSIUS”; C
F = C * (9 / 5) + 32
PRINT “TEMPERATURE IN FAHRENHEIT=”; F
END

  • USING SUB PROCEDURE
DECLARE SUB CONVERT (C)
CLS
INPUT “ENTER TEMPERATURE IN CELSIUS”; C
CALL CONVERT (C)
END

SUB CONVERT (C)
F = C * (9 / 5) + 32
PRINT “TEMPERATURE IN FAHRENHEIT=”; F
END SUB

  • USING FUNCTION PROCEDURE
DECLARE FUNCTION CONVERT (C)
CLS
INPUT “ENTER TEMPERATURE IN CELSIUS”; C
PRINT “TEMPERATURE IN FAHRENHEIT=”; CONVERT (C)
END

FUNCTION CONVERT (C)
F = C * (9 / 5) + 32
CONVERT = F
END FUNCTION

A Program to convert temperature in Fahrenheit to Centigrade

  • A Program to convert temperature in Fahrenheit to Centigrade (Qbasic)
CLS
INPUT "ENTER TEMPERATURE IN FAHRENHEIT"; F
C = (F - 32) * (5 / 9)
PRINT "TEMPERATURE IN CELSIUS="; C
END

  • USING SUB PROCEDURE
DECLARE SUB CONVERT (F)
CLS
INPUT "ENTER TEMPERATURE IN FAHRENHEIT"; F
CALL CONVERT(F)
END

SUB CONVERT (F)
C = (F - 32) * (5 / 9)
PRINT "TEMPERATURE IN CELSIUS="; C
END SUB

  • USING FUNCTION PROCEDURE
DECLARE FUNCTION CONVERT (F)
CLS
INPUT "ENTER TEMPERATURE IN FARENHEIT"; F
PRINT "TEMPERATURE IN CELCIUS="; CONVERT(F)
END

FUNCTION CONVERT (F)
C = (F - 32) * (5 / 9)
CONVERT = C
END FUNCTION

To input number in inches and convert it into feet and inches.(Qbasic)

To input number in inches and convert it into feet and inches.(Qbasic)
CLS
INPUT "Enter the value in inches"; in
f = in \ 12
rn = in MOD 12
PRINT "The equivalent result is"; f; "feet and"; rn; "inches"
END

Notes: Here,
in - represents the data in inches.
f - represents the data result in feet.
rn - represents the remaining data in inches after feet is calculated.

To find simple interest for a given principle, time and rate of interest. (Qbasic)

To find simple interest for a given principle, time and rate of interest. (Qbasic)
CLS
INPUT "Enter the principle amount"; p
INPUT "Enter the time"; t
INPUT "Enter the rate"; r
i = (p * t * r) / 100
PRINT "The simple interest is"; i
END

A program to find the volume and area of a box. (Qbasic Code)

A program to find the volume and area of a box. (Qbasic Code)
CLS
INPUT "Enter the length of the box"; l
INPUT "Enter the breadth of the box"; b
INPUT "Enter the height of the box"; h
v = l * b * h
a = 2 * (l * b + b * h + h * l)
PRINT "The volume of the box is"; v
PRINT "The area of the box is"; a
END