114k views
3 votes
write a QBASIC that ask length,breadth and height of room and calculate its area and volume.create a user-defined function to calculate area and sub programe to calculate volume​

1 Answer

3 votes

Answer:

REM Program to calculate the area and volume of a room

DIM length, breadth, height, area, volume AS SINGLE

INPUT "Enter the length of the room: ", length

INPUT "Enter the breadth of the room: ", breadth

INPUT "Enter the height of the room: ", height

REM Call user-defined function to calculate area

area = calculateArea(length, breadth)

REM Call sub-program to calculate volume

CALL calculateVolume(length, breadth, height, volume)

PRINT "The area of the room is "; area; " square units."

PRINT "The volume of the room is "; volume; " cubic units."

END

REM User-defined function to calculate area

FUNCTION calculateArea(l, b)

calculateArea = l * b

END FUNCTION

REM Sub-program to calculate volume

SUB calculateVolume(l, b, h, v)

v = l * b * h

END SUB

Step-by-step explanation:

The program first asks the user to enter the length, breadth, and height of the room. It then calls a user-defined function calculateArea to calculate the area of the room, which is stored in the area variable. The program then calls a sub-program calculateVolume to calculate the volume of the room, which is stored in the volume variable. Finally, the program prints the values of area and volume.

Note that the user-defined function calculateArea takes two parameters l and b which represent the length and breadth of the room respectively, and returns the product of l and b, which is the area of the room. The sub-program calculateVolume takes three parameters l, b, and h which represent the length, breadth, and height of the room respectively, and calculates the product of l, b, and h, which is the volume of the room. The volume is stored in the variable v, which is passed as a parameter to the sub-program.

User Ashtom
by
7.1k points