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

Monday, November 28, 2022

How to Write a QBASIC Program to Display Only Vowel Letters from Input String

 QBASIC program to display only vowel letters from input string



QBASIC program to display only vowel letters from input string

Introduction


QBASIC is a high-level programming language that was developed by Microsoft. It is an easy-to-learn language that is used for creating simple programs, games, and applications. In this article, we will learn how to write a QBASIC program to display only vowel letters from an input string.


The program will take a string as input and display only the vowel letters from that string. We will use simple programming constructs like loops, if-else statements, and string manipulation to achieve this.


Steps to Write QBASIC Program to Display Only Vowel Letters from Input String

Follow these simple steps to write a QBASIC program to display only vowel letters from an input string:

Step 1: Get Input String


First, we need to get the input string from the user. We can use the INPUT statement to get the input string from the user.

INPUT "Enter any string"; a$




Step 2: Loop Through Input String


Now, we need to loop through the input string and check each character if it is a vowel or not. We can use a FOR loop to iterate through each character in the input string.
FOR i = 1 TO LEN(a$)
m$ = UCASE$(MID$(a$, i, 1))
............
NEXT i

Step 3: Check if Character is a Vowel

Inside the FOR loop, we need to check if the current character is a vowel or not. We can use an SELECT CASE statement to check if the character is a vowel.


SELECT CASE m$
CASE "A", "E", "I", "O", "U"
v$=v$+m$
END SELECT



Step 4: Store Vowel Letters

If the current character is a vowel, we need to store it in the variable v$. We can use the concatenation operator + to append the vowel letter to the variable v$.


Step 5: Display Vowel Letters



Finally, we need to display the v$ variable that contains all the vowel letters from the input string.

PRINT "Vowel letters are: ;v$


Full QBASIC Program



We can solve the above program by using SUB and FUNCTION procedure also.

Using SUB procedure (SUB….END SUB)

DECLARE SUB vowel (a$)
CLS
INPUT "Enter any string"; a$
CALL vowel(a$)
END

SUB vowel (a$)
FOR i = 1 TO LEN(a$)
m$ = UCASE$(MID$(a$, i, 1))
IF m$ = "A" OR m$ = "E" OR m$ = "I" OR m$ = "O" OR m$ = "U" THEN
PRINT m$;
END IF
NEXT i
END SUB


Using FUNCTION Procedure (FUNCTION…END FUNCTION)

DECLARE FUNCTION vowel$ (a$)
CLS
INPUT "Enter any string:"; a$
PRINT vowel$(a$)
END

FUNCTION vowel$ (a$)
FOR i = 1 TO LEN(a$)
m$ = UCASE$(MID$(a$, i, 1))
SELECT CASE m$
CASE "A", "E", "I", "O", "U"
v$ = v$ + m$
END SELECT
NEXT i
vowel$ = v$
END FUNCTION


Output:



FAQs


Q 1. What is QBASIC?
Ans: QBASIC is a high-level programming language that was developed by Microsoft. It is used for creating simple programs, games, and applications.

Q 2. Can I use this QBASIC program to display vowel letters from any input string?
Ans: Yes, you can use this QBASIC program to display vowel letters from any input string.

Q 3. What if the input string does not contain any vowel letters?
Ans: If the input string does not contain any vowel letters, then the output will be an empty string.

Q4. Can I modify this program to display consonant letters instead of vowel letters?
Ans: Yes, you can modify this program to display consonant letters instead of vowel letters by changing the SELECT CASE statement in Step 3.


Conclusion


In this article, we learned how to write a QBASIC program to display only vowel letters from an input string. We went through the step-by-step instructions and explained each step in detail. We also provided some FAQs to help you understand the program better.

QBASIC is an easy-to-learn language, and this program is a great example of how simple programs can be written using QBASIC. We hope that this article has helped you in understanding how to write a QBASIC program to display only vowel letters from an input string.



No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages