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

QBASIC program to input any string and count total no of consonants letters

 QBASIC program to input any string and count total no of consonants letters








Introduction


As a beginner programmer, it is essential to start with the basics of programming languages. QBASIC is one such language that provides a solid foundation to start learning the basics of programming. In this article, we will discuss how to write a QBASIC program to input any string and count the total number of consonant letters present in that string.




Understanding QBASIC


QBASIC is an acronym for Quick Beginners All-Purpose Symbolic Instruction Code. It is a high-level programming language that was developed in the 1980s by Microsoft Corporation. QBASIC is an interpreted language that provides a simple syntax and easy-to-use commands, making it an ideal language for beginners.


What is a consonant letter?

A consonant letter is a letter of the alphabet that is not a vowel. Examples of consonant letters include b, c, d, f, g, h, j, k, l, m, n, p, q, r, s, t, v, w, x, y, and z.


Steps to Write the QBASIC Program

Here are the steps to write a QBASIC program to input any string and count the total number of consonant letters present in that string:


Step 1: Input the string

The next step is to input the string from the user. This can be done using the INPUT statement in QBASIC.








Step 2: Count the consonant letters



The next step is to count the total number of consonant letters present in the input string. This can be done using a loop that iterates through each character in the string and checks if it is a consonant.










Step 3: Display the output

The final step is to display the output, which is the total number of consonant letters present in the input string.



Full QBASIC Program


Here's the full QBASIC program to input any string and count the total number of consonant letters present in that string:



We can solved above program by using SUB and FUNCTION procedures:

Using SUB procedure (SUB…END SUB)

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

SUB con (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
v = v + 1
END IF
NEXT i
PRINT "Total consonant letters:"; LEN(a$) - v
END SUB



Using FUNCTION procedure (FUNCTION…END FUNCTION)


DECLARE FUNCTION con (a$)
CLS
INPUT "Enter any string:"; a$
PRINT "Total consonant letters:"; con(a$)
END

FUNCTION con (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$
CASE ELSE
c$ = c$ + m$
END SELECT
NEXT i
con = LEN(c$)
END FUNCTION

 

Output



Conclusion


QBASIC is a simple and easy-to-use programming language for beginners. In this article, we discussed how to write a QBASIC program to input any string and count the total number of consonant letters present in that string. We went through the steps involved in writing the program, including declaring the variables, inputting the string, counting the consonant letters, and displaying the output.

By following these steps, you can write a simple and effective QBASIC program that can count the total number of consonant letters present in any input string. This program can be a great starting point for beginners who want to learn the basics of programming and start building their programming skills.

FAQs

1) What is QBASIC?
Ans: QBASIC is a high-level programming language that was developed by Microsoft Corporation in the 1980s. It provides a simple syntax and easy-to-use commands, making it an ideal language for beginners.

2) What is a loop in QBASIC?
Ans: A loop in QBASIC is a sequence of instructions that is repeated until a specific condition is met. In this program, we used a loop to iterate through each character in the input string and count the total number of consonant letters present.

3) How can I learn QBASIC?
Ans: There are many resources available online to learn QBASIC, including tutorials, videos, and online courses. You can also practice by writing simple programs and experimenting with different commands and statements.

4) Can QBASIC be used for real-world applications?
Ans: QBASIC is primarily used as a teaching language and is not commonly used for real-world applications. However, it can be used to create simple programs and automate basic tasks.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages