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

Friday, December 9, 2022

QBASIC program to input any string and print only vowel letters


QBASIC program to input any string and print only vowel letters





Introduction:


In this article, we'll look at how to write a QBASIC program that displays the vowel letters in a string. QBASIC is a high-level programming language known for its ease of use and simplicity, making it an excellent choice for beginners. You will be able to identify and display vowel letters from any input string if you understand the logic and structure of the program.




What is QBASIC?


Microsoft created QBASIC as a simplified version of the BASIC (Beginner's All-purpose Symbolic Instruction Code) programming language. It was popular in the 1990s and provided an easy way to learn programming concepts. QBASIC programs are written in an easy-to-understand and readable style, making it an excellent choice for educational purposes and for beginners looking to gain a fundamental understanding of programming.


Steps to write the program:

Step 1: Define the variables
Step 2: Get the input string from the user
Step 3: Loop through the input string and check for vowels
Step 4: Display the vowel letters





Program to Display vowel letters without using Modular programming


CLS

INPUT "Enter any string:"; s$

l = LEN(s$)

FOR x = 1 TO l

m$ = UCASE$(MID$(s$, x, 1))

IF m$ = "A" OR m$ = "E" OR m$ = "I" OR m$ = "O" OR m$ = "U" THEN

PRINT m$;

END IF

NEXT x

END



Program to display vowel letters By using SUB procedure (SUB…END SUB)


DECLARE SUB vowel (s$)

CLS

INPUT "Enter any string:"; s$

CALL vowel(s$)

END



SUB vowel (s$)

l = LEN(s$)

FOR x = 1 TO l

m$ = UCASE$(MID$(s$, x, 1))

IF m$ = "A" OR m$ = "E" OR m$ = "I" OR m$ = "O" OR m$ = "U" THEN

PRINT m$;

END IF

NEXT x

END SUB



QBASIC program to display vowel letters By using the FUNCTION procedure (FUNCTION..END FUNCTION)


DECLARE FUNCTION vowel$ (s$)

CLS

INPUT "Enter any string:"; s$

PRINT vowel$(s$)

END



FUNCTION vowel$ (s$)

l = LEN(s$)

FOR x = 1 TO l

m$ = UCASE$(MID$(s$, x, 1))

IF m$ = "A" OR m$ = "E" OR m$ = "I" OR m$ = "O" OR m$ = "U" THEN

v$ = v$ + m$

END IF

NEXT x

vowel$ = v$

END FUNCTION



We can also write the same program By using the SELECT CASE conditional statement


DECLARE FUNCTION vowel$ (s$)

CLS

INPUT "Enter any string:"; s$

PRINT vowel$(s$)

END



FUNCTION vowel$ (s$)

l = LEN(s$)

FOR x = 1 TO l

m$ = UCASE$(MID$(s$, x, 1))

SELECT CASE m$

CASE "A", "E", "I", "O", "U"

v$ = v$ + m$

END SELECT

NEXT x

vowel$ = v$

END FUNCTION




Output:






Conclusion:

We looked at how to write a QBASIC program to display the vowel letters from an input string in this article. By following the steps outlined, you can create a working program that identifies and displays the vowel letters in a given string. Because of its simplicity and readability, QBASIC is an excellent language for beginners to learn and apply programming concepts.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages