Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Thursday, December 29, 2022

Menu drive program in QBASIC

 

Menu drive program in QBASIC


Menu drive program in QBASIC



QBASIC is an old-school programming language that is still used today by some enthusiasts and beginners who are just starting to learn to program. One of the most interesting programs you can write a menu driven program in QBASIC. In this article, we will discuss what a menu-driven program is and how to create one 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

Why should you use a menu-driven approach in QBASIC?
  • 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

 Output:

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:

In conclusion, menu-driven programs are a powerful tool in QBASIC that allow us to create interactive applications. By following the simple steps outlined above, we can create menu-driven programs that provide the user with a list of options to choose from and perform different actions based on their selection. Whether you are creating a game, a utility, or a graphical user interface, menu-driven programs can help you create.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages