QBasic Programming

WAP to input any string and count total no. of vowels , consonants, words and sentences

CLS
INPUT "ENTER ANY STRING"; S$
VC = 0
CC = 0
WC = 1
SC = 0
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ = "O" OR C$ = "U" THEN
VC = VC + 1
ELSEIF B$ = " " THEN
WC = WC + 1
ELSEIF B$ = "." THEN
SC = SC + 1
ELSE
CC = CC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF VOWELS= "; VC
PRINT "TOTAL NO. OF CONSONANTS="; CC
PRINT "TOTAL NO. OF WORDS="; WC
PRINT "TOTAL NO. OF SENTENCES="; SC
END

USING SUB PROCEDURE
DECLARE SUB COUNT (S$)
CLS
INPUT "ENTER ANY STRING"; S$
CALL COUNT(S$)
END

SUB COUNT (S$)
VC = 0
CC = 0
WC = 1
SC = 0
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ = "O" OR C$ = "U" THEN
VC = VC + 1
ELSEIF B$ = " " THEN
WC = WC + 1
ELSEIF B$ = "." THEN
SC = SC + 1
ELSE
CC = CC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF VOWELS= "; VC
PRINT "TOTAL NO. OF CONSONANTS="; CC
PRINT "TOTAL NO. OF WORDS="; WC
PRINT "TOTAL NO. OF SENTENCES="; SC
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION COUNT (S$)
CLS
INPUT "ENTER ANY STRING"; S$
PRINT "TOTAL NO. OF CONSONANTS= "; COUNT(S$)
END

FUNCTION COUNT (S$)
VC = 0
CC = 0
WC = 1
SC = 0
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ = "O" OR C$ = "U" THEN
VC = VC + 1
ELSEIF B$ = " " THEN
WC = WC + 1
ELSEIF B$ = "." THEN
SC = SC + 1
ELSE
CC = CC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF VOWELS="; CC
PRINT "TOTAL NO. OF WORDS="; WC
PRINT "TOTAL NO. OF SENTENCES="; SC
COUNT = CC
END FUNCTION

WAP to input any string and count total no. of sentences (Prev Lesson)
(Next Lesson) WAP to input any string and display only consonant by removing vowels
Back to QBasic Programming

No Comments

Post a Reply

Course Curriculum

error: Content is protected !!