Menu drive program in QBASIC
What is a Menu-Driven Program?
A menu-driven program is a program that presents the user with a menu of options to choose from. The user selects an option from the menu and the program responds accordingly. This type of program is useful for applications where there are several different functions that the user might want to perform.
A menu-driven program in QBasic is a program that presents the user with a list of options or commands and allows the user to choose one of them to execute.
The Advantages of Using a Menu-Driven Program
- User-Friendly: It simplifies user interaction.
- Error Reduction: Reduces the possibility of input errors.
- Efficiency: Improves the efficiency with which specific functions are carried out.
- Scalability: It is simple to add or change options.
Example of menu-driven program in QBasic:
CLS
DO
PRINT
"Menu:"
PRINT
"1. Print a message"
PRINT
"2. Calculate the area of a circle"
PRINT
"3. calculate the sum of two numbers"
PRINT
"4. Quit"
INPUT
"Enter your choice: ", choice
SELECT CASE choice
CASE 1
PRINT "You have chosen option 1."
INPUT "Enter a message: ", message$
PRINT message$
CASE 2
PRINT "You have chosen option 2."
INPUT "Enter the radius of the circle: ", radius
area = 3.14 * radius * radius
PRINT "The area of the circle is: "; area
CASE 3
PRINT "You have chosen option 3"
INPUT "Enter any two numbers"; a, b
s
= a + b
PRINT "Sum of two numbers="; s
CASE 4
PRINT "You have chosen option 4. Goodbye for now!"
EXIT DO
CASE ELSE
PRINT "Invalid choice."
END
SELECT
LOOP
In above example, the program displays a menu with four options: "1. Print a message",
"2. Calculate the area of a circle",
"3. Calculate the sum of two numbers" and
"4. Quit".
The user is prompted to enter their choice, and the program uses a SELECT CASE statement to execute the corresponding code block based on the user's choice.
If the user enters 1, the program prompts the
user to enter a message and then prints the message. If the user enters 2, the
program prompts the user to enter the radius of a circle and calculates the
area of the circle. If the user enters 3, the program prompts the user to enter
two numbers and calculate the sum of two numbers, If the user enters 4, the
program prints a goodbye message and exits the program. If the user enters any
other number, the program prints an "Invalid choice" message.
Conclusion:
No comments:
Post a Comment