Home
10 questions about conditional statements in QBasic, covering IF
, IF...ELSE
, IF...ELSEIF...ELSE
, and SELECT CASE
:
Questions on IF
:
- Write a QBasic program using an
IF
statement to check if a number entered by the user is positive. - Create a program to check if a number is divisible by 5 using a single
IF
statement.
Questions on IF...ELSE
:
- Write a program using
IF...ELSE
to determine if a number entered by the user is even or odd. - Write a QBasic program using
IF...ELSE
to print "Adult" if the user's age is 18 or above, and "Minor" otherwise.
Questions on IF...ELSEIF...ELSE
:
- Write a QBasic program to grade a student's marks:
- 90 and above: "A"
- 80-89: "B"
- 70-79: "C"
- Below 70: "Fail"
- Create a QBasic program that uses
IF...ELSEIF...ELSE
to classify a person's Body Mass Index (BMI):- BMI < 18.5: "Underweight"
- 18.5 <= BMI < 25: "Normal weight"
- 25 <= BMI < 30: "Overweight"
- BMI >= 30: "Obese"
Questions on SELECT CASE
:
- Write a program using
SELECT CASE
to display the name of the day based on a number entered by the user (1 for Monday, 2 for Tuesday, ..., 7 for Sunday). - Write a QBasic program using
SELECT CASE
to display the category of a vehicle based on the number of wheels entered by the user:- 2 wheels: "Bike"
- 4 wheels: "Car"
- More than 4 wheels: "Truck"
- Otherwise: "Unknown"
Mixed Questions:
- Write a program that asks the user to enter a character and checks if it is a vowel (
a, e, i, o, u
) or a consonant usingIF...ELSEIF...ELSE
. - Create a QBasic program using
SELECT CASE
to calculate a discount based on the purchase amount:
- Purchase >= 500: 20% discount
- Purchase between 200 and 499: 10% discount
- Purchase < 200: No discount
10 QBasic questions involving loops, covering FOR
, WHILE
, DO...WHILE
, DO LOOP WHILE
, DO UNTIL
, and DO LOOP UNTIL
:
Questions on FOR
:
- Write a QBasic program using a
FOR
loop to print the first 10 natural numbers. - Create a program using a
FOR
loop to calculate the sum of all even numbers between 1 and 50.
Questions on WHILE
:
- Write a QBasic program using a
WHILE
loop to find the factorial of a number entered by the user. - Use a
WHILE
loop to print all multiples of 3 between 1 and 30.
Questions on DO WHILE
:
- Write a QBasic program using a
DO WHILE
loop to print the squares of numbers from 1 to 10. - Create a program using a
DO WHILE
loop that asks the user to enter numbers until they enter a negative number, then display the sum of all entered numbers.
Questions on DO LOOP WHILE
:
- Write a QBasic program using a
DO LOOP WHILE
to reverse a number entered by the user (e.g., input: 1234, output: 4321). - Use a
DO LOOP WHILE
to display the first 10 terms of the Fibonacci series.
Questions on DO UNTIL
:
- Write a QBasic program using
DO UNTIL
to display all odd numbers between 1 and 20. - Create a program using
DO UNTIL
to count the number of digits in a number entered by the user.
Bonus Question:
Write a program using DO LOOP UNTIL
that calculates the sum of numbers entered by the user, stopping when the user enters zero, and displays the total sum.
10 QBasic questions that involve using inbuilt library functions like LEFT$
, RIGHT$
, MID$
, VAL
, STR$
, UCASE$
, and LCASE$
, including practical applications such as checking for palindromes, counting vowels and consonants, and integer-to-binary conversion:
Questions on String Manipulation (LEFT$
, RIGHT$
, MID$
):
- Write a QBasic program to extract and display the first 3 characters of a string entered by the user using the
LEFT$
function. - Create a program to display the last 4 characters of a string entered by the user using the
RIGHT$
function. - Write a QBasic program that uses the
MID$
function to extract a substring from the 3rd to the 6th character of a string entered by the user.
Questions on Conversion Functions (VAL
, STR$
):
- Write a program to convert a numeric string (e.g., "1234") into a number using
VAL
, add 10 to it, and display the result. - Create a QBasic program to convert an integer entered by the user into a string using
STR$
, concatenate it with another string (e.g., " is the number"), and display the result.
Questions on Case Conversion (UCASE$
, LCASE$
):
- Write a program that converts a string entered by the user to uppercase using
UCASE$
. - Create a QBasic program that converts a string entered by the user to lowercase using
LCASE$
.
Practical Applications:
- Check Palindrome: Write a QBasic program to check if a string entered by the user is a palindrome (e.g., "madam" is a palindrome). Use
MID$
,LEFT$
, andRIGHT$
. - Count Vowels and Consonants: Write a program to count the number of vowels and consonants in a string entered by the user using
MID$
andUCASE$
(to handle case insensitivity). - Integer to Binary Conversion: Write a QBasic program to convert an integer entered by the user into its binary representation. Use a loop and string concatenation with
STR$
to build the binary string.
Example Scenarios:
- For the palindrome check, reverse the string using
MID$
orRIGHT$
and compare it with the original string. - For the vowels and consonants count, use
MID$
to extract characters one by one,UCASE$
to standardize the case, and conditional checks (IF
) to categorize each character. - For integer-to-binary conversion, use repeated division by 2, store remainders as strings using
STR$
, and reverse the binary string at the end usingRIGHT$
.
No comments:
Post a Comment