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 count the total number of vowel letters from input string

QBASIC program to count the total number of vowel letters from input string

 


Introduction


QBASIC is a high-level programming language that was designed to be easy to learn and use. It is an interpreted language that is often used for educational purposes and for small-scale applications. In this article, we will explore how to create a QBASIC program that counts the total number of vowel letters from an input string.

Steps to create a QBASIC program to count vowel letters

  1. Start by opening the QBASIC editor.
  2. Create a new program and give it a name.
  3. Declare a variable to store the input string.
  4. Ask the user to input a string.
  5. Initialize a counter variable to 0.
  6. Loop through each character in the string.
  7. If the character is a vowel letter, increment the counter variable.
  8. Print the total number of vowel letters to the screen.
  9. End the program.

Code


Here is the code for the QBASIC program to count the total number of vowel letters from an input string:




Explanation of Code:

  • CLS: This command clears the screen.
  • INPUT "Enter any string:"; s$: This statement prompts the user to enter a string and stores the string in the variable "s$".
  • l = LEN(s$): This statement calculates the length of the input string and stores the value in the variable "l".
  • FOR x = 1 TO l: This statement sets up a FOR loop that will iterate through each character of the input string.
  • m$ = UCASE$(MID$(s$, x, 1)): This statement extracts each character of the input string and stores it in the variable "m$". The UCASE$ function converts the character to uppercase to make it easier to check if it is a vowel.
  • IF m$ = "A" OR m$ = "E" OR m$ = "I" OR m$ = "O" OR m$ = "U" THEN: This line of code checks if the character is a vowel by comparing it to the letters "A", "E", "I", "O", and "U".
  • v = v + 1: If the current character is a vowel, the program increments the variable "v" (which represents the count of vowel letters) by 1.
  • ELSE: If the current character is not a vowel, the program increments the variable "c" (which represents the count of consonant letters) by 1.
  • NEXT x: This statement ends the FOR loop and moves to the next character of the input string.
  • PRINT "Total number of vowel letters="; v: This statement prints the total number of vowel letters by displaying the message "Total number of vowel letters=" followed by the value of the variable "v".
  • END: This statement ends the program.

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

 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

v = v + 1

ELSE

c = c + 1

END IF

NEXT x

PRINT "Total number of vowel letters="; v

END SUB


By using FUNCTION procedure (FUNCTION..END FUNCTION)

DECLARE FUNCTION vowel (s$)

CLS

INPUT "Enter any string:"; s$

PRINT "Total number of consonants letters="; 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$

CASE ELSE

c$ = c$ + m$

END SELECT

NEXT x

vowel = LEN(v$)

END FUNCTION


Output:




Conclusion


In this article, we have learned how to create a QBASIC program to count the total number of vowel letters from an input string. We covered the basics of QBASIC programming and provided step-by-step instructions for creating the program. We also provided a detailed explanation of the code and demonstrated how to run the program. With this knowledge, you can create your own QBASIC programs and explore the world of programming further.

FAQs


1. What is QBASIC? 
Ans: QBASIC is a high-level programming language that is easy to learn and use. It is often used for educational purposes and for small-scale applications.

2. What are vowel letters? 
Ans: Vowel letters are the letters 'a', 'e', 'i', 'o', and 'u' in English.

3. How does the QBASIC program count the total number of vowel letters? 
Ans: The QBASIC program loops through each character in the input string and checks if it is a vowel letter. If it is, the counter variable is incremented by 1.

4. Can I use QBASIC to create other types of programs? 
Ans: Yes, QBASIC can be used to create a wide variety of programs, including games, utilities, and educational software.

5. Is QBASIC still used today? 
Ans: While QBASIC is no longer widely used, it is still used in some educational settings and by hobbyists who enjoy programming in older languages.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages