Tuesday, 24 December 2024

Grade-9 Winter Vacation Homework 2081

Home


10 questions about conditional statements in QBasic, covering IF, IF...ELSE, IF...ELSEIF...ELSE, and SELECT CASE:


Questions on IF:

  1. Write a QBasic program using an IF statement to check if a number entered by the user is positive.
  2. Create a program to check if a number is divisible by 5 using a single IF statement.

Questions on IF...ELSE:

  1. Write a program using IF...ELSE to determine if a number entered by the user is even or odd.
  2. 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:

  1. Write a QBasic program to grade a student's marks:
    • 90 and above: "A"
    • 80-89: "B"
    • 70-79: "C"
    • Below 70: "Fail"
  2. 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:

  1. 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).
  2. 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:

  1. 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 using IF...ELSEIF...ELSE.
  2. 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:

  1. Write a QBasic program using a FOR loop to print the first 10 natural numbers.
  2. Create a program using a FOR loop to calculate the sum of all even numbers between 1 and 50.

Questions on WHILE:

  1. Write a QBasic program using a WHILE loop to find the factorial of a number entered by the user.
  2. Use a WHILE loop to print all multiples of 3 between 1 and 30.

Questions on DO WHILE:

  1. Write a QBasic program using a DO WHILE loop to print the squares of numbers from 1 to 10.
  2. 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:

  1. Write a QBasic program using a DO LOOP WHILE to reverse a number entered by the user (e.g., input: 1234, output: 4321).
  2. Use a DO LOOP WHILE to display the first 10 terms of the Fibonacci series.

Questions on DO UNTIL:

  1. Write a QBasic program using DO UNTIL to display all odd numbers between 1 and 20.
  2. 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$):

  1. Write a QBasic program to extract and display the first 3 characters of a string entered by the user using the LEFT$ function.
  2. Create a program to display the last 4 characters of a string entered by the user using the RIGHT$ function.
  3. 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$):

  1. Write a program to convert a numeric string (e.g., "1234") into a number using VAL, add 10 to it, and display the result.
  2. 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$):

  1. Write a program that converts a string entered by the user to uppercase using UCASE$.
  2. Create a QBasic program that converts a string entered by the user to lowercase using LCASE$.

Practical Applications:

  1. 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$, and RIGHT$.
  2. Count Vowels and Consonants: Write a program to count the number of vowels and consonants in a string entered by the user using MID$ and UCASE$ (to handle case insensitivity).
  3. 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$ or RIGHT$ 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 using RIGHT$.

These questions provide a mix of theoretical understanding and practical problem-solving with QBasic's inbuilt functions.

No comments:

Post a Comment

Popular Posts