QBASIC Question Set/ Old questions/ Modular Programming

**1) Calculate Room Area and Perimeter**

Write a QBASIC program that prompts the user for the length and breadth of a room. Calculate its area using the formula `Area = Length × Breadth`, and calculate the perimeter using the formula `Perimeter = 2 × (Length + Breadth)`. Create a user-defined function to compute the area and a sub-program to calculate the perimeter. (Hint: `Area = L × B`, `Perimeter = 2 × (L + B)`)

DECLARE FUNCTION Area (Length, Breadth)
DECLARE SUB Peri (Length, Breadth)

CLS
INPUT "Enter the length of the room: "; Length
INPUT "Enter the breadth of the room: "; Breadth

A=Area (Length, Breadth)
CALL Peri (Length, Breadth)

PRINT "Area of the room is: "; A
END

SUB Peri (Length, Breadth)
    Perimeter = 2 * (Length + Breadth)
  PRINT "Perimeter of the room is: "; Perimeter
END SUB

FUNCTION Area (Length, Breadth)
    Area = Length * Breadth
END FUNCTION

**2) Calculate Room Area and Volume**

Write a QBASIC program that takes a room's length, breadth, and height as input. Compute its area using the formula `Area = Length × Breadth` and its volume using the formula `Volume = Length × Breadth × Height`. Implement a user-defined function to calculate the area and a sub-program to determine the volume. (Hint: `Area = L × B`, `Volume = L × B × H`)

DECLARE FUNCTION CalculateArea(Length, Breadth)
DECLARE SUB CalculateVolume(Length, Breadth, Height)

CLS
INPUT "Enter the length of the room: "; Length
INPUT "Enter the breadth of the room: "; Breadth
INPUT "Enter the height of the room: "; Height

Area = CalculateArea(Length, Breadth)
CALL  CalculateVolume (Length, Breadth, Height)

PRINT "Area of the room is: "; Area

END

FUNCTION CalculateArea(Length, Breadth)
    CalculateArea = Length * Breadth
END FUNCTION

SUB CalculateVolume(Length, Breadth, Height)
    Volume = Length * Breadth * Height
    PRINT "Volume of the room is: "; Volume
END SUB

**3) Surface Area of Walls and Box**

Create a QBASIC program that takes the length, breadth, and height of an object. Calculate the surface area of its four walls using the formula `Surface Area = 2 × Height × (Length + Breadth)`, and compute the surface area of a box using the formula `Surface Area = 2 × (Length × Height + Breadth × Height + Length × Breadth)`. Develop a user-defined function for the walls' surface area and a sub-program for the box's surface area. (Hint: Walls' Surface Area = `2H × (L + B)`, Box's Surface Area = `2 × (LH + BH + LB)`)

DECLARE FUNCTION CalculateWallsSurfaceArea(Length, Breadth, Height)
DECLARE SUB CalculateBoxSurfaceArea(Length, Breadth, Height)

CLS
INPUT "Enter the length of the object: "; Length
INPUT "Enter the breadth of the object: "; Breadth
INPUT "Enter the height of the object: "; Height

WallsSurfaceArea = CalculateWallsSurfaceArea(Length, Breadth, Height)
CALL  CalculateBoxSurfaceArea (Length, Breadth, Height)

PRINT "Surface area of the walls: "; WallsSurfaceArea

END

FUNCTION CalculateWallsSurfaceArea(Length, Breadth, Height)
    CalculateWallsSurfaceArea = 2 * Height * (Length + Breadth)
END FUNCTION

SUB CalculateBoxSurfaceArea(Length, Breadth, Height)
    BoxSurfaceArea = 2 * (Length * Height + Breadth * Height + Length * Breadth)
    PRINT "Surface area of the box: "; BoxSurfaceArea
END SUB

**4) Circle Area and Cylinder Volume**

Craft a QBASIC program that allows the user to input the radius of a circle. Calculate the area of the circle using the formula `Area = π × Radius²` and find the volume of a cylinder using the formula `Volume = π × Radius² × Height`. Implement a user-defined function for the circle's area and a sub-procedure for the cylinder's volume. (Hint: Circle's Area = `π × r²`, Cylinder's Volume = `π × r² × h`)

DECLARE FUNCTION CalculateCircleArea(Radius)
DECLARE SUB CalculateCylinderVolume(Radius, Height)


CLS
INPUT "Enter the radius of the circle: "; Radius
INPUT "Enter the height of the cylinder: "; Height
CONST PI = 22/7

CircleArea = CalculateCircleArea(Radius)
CALL  CalculateCylinderVolume (Radius, Height)

PRINT "Area of the circle: "; CircleArea

END

FUNCTION CalculateCircleArea(Radius)
    CalculateCircleArea = PI * Radius * Radius
END FUNCTION

SUB CalculateCylinderVolume(Radius, Height)
    Volume = PI * Radius * Radius * Height
    PRINT "Volume of the cylinder: "; Volume

END SUB

**5) Function to Find Wall Area**

Write a QBASIC program to compute the area of four walls using user-defined FUNCTIONS. Calculate the total wall area using the formula `Total Wall Area = 2 × Height × (Length + Breadth)`. (Hint: Total Wall Area = `2H × (L + B)`)

DECLARE FUNCTION CalculateTotalWallArea(Height, Length, Breadth)

CLS

INPUT "Enter the height of the walls: ", Height
INPUT "Enter the length of the walls: ", Length
INPUT "Enter the breadth of the walls: ", Breadth

TotalArea = CalculateTotalWallArea(Height, Length, Breadth)

PRINT "The total wall area of four walls is "; TotalArea

FUNCTION CalculateTotalWallArea(Height, Length, Breadth)
    CalculateTotalWallArea = 2 * Height * (Length + Breadth)
END FUNCTION

**6) Circle Area and Circumference**

Develop a QBASIC program that requests the radius of a circle from the user. Calculate its circumference using the formula `Circumference = 2 × π × Radius` and find its area using the formula `Area = π × Radius²`. Create a user-defined function for the circle's area and a sub-program for the circumference. (Hint: Area = `r²`, Circumference = `2πr`)

DECLARE FUNCTION CalculateCircleArea(Radius)
DECLARE SUB CalculateCircleCircumference(Radius)

CLS

INPUT "Enter the radius of the circle: "; Radius
CONST PI = 22/7

CALL  CalculateCircleCircumference (Radius)
CircleArea = CalculateCircleArea(Radius)

PRINT "Area of the circle: "; CircleArea

END

FUNCTION CalculateCircleArea(Radius)
    CalculateCircleArea = PI * Radius * Radius
END FUNCTION

SUB CalculateCircleCircumference(Radius)
    Circumference = 2 * PI * Radius
    PRINT "Circumference of the circle: "; Circumference
END SUB

**7) Square and Average**

Design a QBASIC program that takes two numbers as input. Calculate and display the square of each number using a SUB... END SUB program. Additionally, calculate and display the average of the two numbers using FUNCTION... END FUNCTION. (Hint: Square = `Number × Number`, Average = `(Number1 + Number2) / 2`)

DECLARE SUB CalculateSquare(Number)
DECLARE FUNCTION CalculateAverage(Number1, Number2)

CLS

INPUT "Enter the first number: "; Number1
INPUT "Enter the second number: "; Number2

CALL  CalculateSquare (Number1)
CALL  CalculateSquare (Number2)

Avg = CalculateAverage(Number1, Number2)

PRINT "Average of the two numbers: "; Avg

END

SUB CalculateSquare(Number)
    Square = Number * Number
    PRINT "Square of the number "; Number;" is : "; Square
END SUB

FUNCTION CalculateAverage(Number1, Number2)
    CalculateAverage = (Number1 + Number2) / 2
END FUNCTION

Netra Koirala

Netra Koirala

Computer Science Educator

Passionate computer science educator and author. Provides free study notes, practical guides, and tutorials for Class 9, 10, 11, 12, and B.Sc CSIT students in Nepal. Years of teaching experience in computer science fundamentals.

Computer Science notes, tutorials, MCQs, and educational resources for Nepal students. Covering Class 9, SEE preparation, Class 11, Class 12, SLC, programming, DBMS, networking, HTML, JavaScript, PHP, OOP and more.

Featured Post

Grade 10 Computer Science: Specification Grid & Model Questions

Specification Grid & Model Questions of Computer Science | Grade 10 📚 Examination Resource Specification Grid & M...

Followers