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 consonant letters

 QBASIC program to input any string and print only consonant letters

 



QBASIC program to input any string and print only consonant letters


Introduction

QBASIC is a high-level programming language that is widely used for creating various types of applications. One of its features is the ability to manipulate and process strings in different ways. In this tutorial, we will walk you through the steps of writing a QBASIC program to input any string and print only consonant letters. Whether you are new to programming or an experienced developer looking to expand your skill set, this guide is for you.

What are Consonant Letters?

Consonant letters are the letters of the alphabet that are not vowels. In English, the consonant letters are B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Y, and Z.


Full QBASIC Code




Explanation of Code


The QBASIC code you provided does the following:

  1. CLS: This command clears the screen before the program starts.
  2. INPUT "Enter any string:"; s$: This line prompts the user to enter a string, and the string is stored in the variable "s$".
  3. l = LEN(s$): This line calculates the length of the string that the user entered and stores it in the variable "l".
  4. FOR x = 1 TO l: This line starts a loop that will iterate through each character in the string.
  5. m$ = UCASE$(MID$(s$, x, 1)): This line extracts the character at the current position of the loop and converts it to uppercase using the UCASE$ function. The resulting character is stored in the variable "m$".
  6. IF m$ = "A" OR m$ = "E" OR m$ = "I" OR m$ = "O" OR m$ = "U" THEN: This line checks if the current character is a vowel. If it is, the character is added to the variable "v$".
  7. ELSE: If the current character is not a vowel, it is added to the variable "c$".
  8. END IF: This line ends the IF statement.
  9. NEXT x: This line increments the loop counter and continues with the next character in the string.
  10. PRINT c$: This line prints the consonant letters that were stored in the variable "c$".

We can solve above program by using SUB and FUNCTION procedure

 By using SUB procedure (SUB…END SUB)


DECLARE SUB cons (s$)
CLS
INPUT "Enter any string:"; s$
CALL cons(s$)
END

SUB cons (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$
ELSE
c$ = c$ + m$
END IF
NEXT x
PRINT c$
END SUB


 By using the FUNCTION procedure (FUNCTION..END FUNCTION)


DECLARE FUNCTION cons$ (s$)
CLS
INPUT "Enter any string:"; s$
PRINT cons$(s$)
END

FUNCTION cons$ (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
cons$ = c$
END FUNCTION


Output





Frequently Asked Questions


Q: What is QBASIC? 
Ans: QBASIC is a high-level programming language that is used to create various types of applications.

Q: What are consonant letters? 
Ans: Consonant letters are the letters of the alphabet that are not vowels.

Q: What does the code do? 
Ans: The code allows you to input any string and print only the consonant letters.

Conclusion

In this tutorial, we have shown you how to write a QBASIC program to input any string and print only consonant letters. By following our step-by-step guide, you can become a QBASIC programming expert in no time. Whether you are new to programming or an experienced developer, QBASIC is a great language to learn and use for various types of applications. Try experimenting with the code and see what else you can do with it.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages