Sunday, 29 December 2024

Grade-10-Ch-8 Review of QBASIC Programming RoseBud

 1. Fill in the Blanks

a. program    b. programmers    c. QBASIC    d. flowchart    e. syntax     f. $ (dollar)     g. space                   h. assignament     i. logical         j. variable

2. State whether the following statements are true or false

a. true    b. false    c. false    d. true    e. true    f. true     g. false

3. Write the syntax and purposes of the following stetements and functions

Below are the syntax and purpose of the listed statements/functions in QBasic:


a. INPUT

  • Syntax:
    INPUT "Prompt message"; VariableName
  • Purpose:
    Accepts input from the user and stores it in a variable.

b. PRINT

  • Syntax:
    PRINT "Text", or PRINT VariableName
  • Purpose:
    Displays text or the value of a variable on the screen.

c. DIM

  • Syntax:
    DIM VariableName(DataType) or DIM ArrayName(Dimensions)
  • Purpose:
    Declares a variable or an array with a specified data type or size.

d. READ-DATA

  • Syntax:
    READ VariableName
    DATA Value1, Value2, ...
  • Purpose:
    Retrieves values from a DATA statement and assigns them to variables sequentially.

e. SING()

  • Syntax:
    SING(Value)
  • Purpose:
    Calculates and returns the sine of a value (usually in radians).

f. MID$()

  • Syntax:
    MID$(String, Start, Length)
  • Purpose:
    Extracts a substring from a string, starting at the specified position and for the specified length.

g. IF-END IF

  • Syntax:
    IF Condition THEN
        Statements
    END IF
    
  • Purpose:
    Executes a block of code if the condition is true.

h. SELECT-END SELECT

  • Syntax:
    SELECT CASE Expression
        CASE Value1
            Statements
        CASE Value2
            Statements
    END SELECT
    
  • Purpose:
    Allows branching logic based on multiple possible values of an expression.

i. EXIT

  • Syntax:
    EXIT FOR or EXIT DO
  • Purpose:
    Exits a loop prematurely.

j. LEFT$()

  • Syntax:
    LEFT$(String, Length)
  • Purpose:
    Returns the leftmost Length characters of a string.

k. RIGHT$()

  • Syntax:
    RIGHT$(String, Length)
  • Purpose:
    Returns the rightmost Length characters of a string





4. Write the algorithm and  draw the flowcharts for the followings:

Here are the algorithms and corresponding flowcharts for the given problems:


a. To Find the Volume of a Box (V = L × B × H)

Algorithm:

  1. Start.
  2. Input length L, breadth B, and height H.
  3. Calculate volume: V = L * B * H.
  4. Display V.
  5. Stop.

Flowchart:

  • Flowchart Explanation:
    1. Input values L, B, H.
    2. Perform calculation: V = L * B * H.
    3. Output the result.

b. To Find the Area of 4 Walls (A = 2 × H × (L + B))

Algorithm:

  1. Start.
  2. Input height H, length L, and breadth B.
  3. Calculate area: A = 2 * H * (L + B).
  4. Display A.
  5. Stop.

Flowchart:

  • Flowchart Explanation:
    1. Input H, L, and B.
    2. Perform calculation: A = 2 * H * (L + B).
    3. Output the result.

c. To Find the Area of a Circle (A = π × r²)

Algorithm:

  1. Start.
  2. Input radius r.
  3. Calculate area: A = 3.14 * r^2.
  4. Display A.
  5. Stop.

Flowchart:

  • Flowchart Explanation:
    1. Input radius r.
    2. Perform calculation: A = 3.14 * r^2.
    3. Output the result.



5. Debug the following programs and underline the corrected statements:

Here are the debugged versions of the given programs and alternative implementations using the SELECT CASE statement.


a) REM to Print Percentage with Corrected Code

Debugged Code (IF-END IF Implementation):

REM Program to Print Percentage and Division
INPUT "Enter the percentage of a Student:::"; P

IF P >= 60 THEN
    D$ = "First Division"
ELSEIF P >= 50 AND P < 60 THEN
    D$ = "Second Division"
ELSEIF P >= 40 AND P < 50 THEN
    D$ = "Third Division"
ELSE
    D$ = "Fail"
END IF

PRINT "The Division is: "; D$
END

Correct Code Using SELECT CASE:

REM Program to Print Percentage and Division Using SELECT CASE
INPUT "Enter the percentage of a Student:::"; P

SELECT CASE P
    CASE IS >= 60
        D$ = "First Division"
    CASE 50 TO 59.9
        D$ = "Second Division"
    CASE 40 TO 49.9
        D$ = "Third Division"
    CASE ELSE
        D$ = "Fail"
END SELECT

PRINT "The Division is: "; D$
END

b) REM to Check Divisibility by 5 with Corrected Code

Debugged Code (IF-END IF Implementation):

REM Program to Check Divisibility by 5
CLS
INPUT "Enter a Number: "; N

IF N MOD 5 = 0 THEN
    PRINT N; " is fully divisible by 5"
ELSE
    PRINT N; " is not fully divisible by 5"
END IF

END

Correct Code Using SELECT CASE:

REM Program to Check Divisibility by 5 Using SELECT CASE
CLS
INPUT "Enter a Number: "; N

SELECT CASE N MOD 5
    CASE 0
        PRINT N; " is fully divisible by 5"
    CASE ELSE
        PRINT N; " is not fully divisible by 5"
END SELECT

END

Explanation of Corrections:

  1. Syntax Fixes:

    • Used MOD operator for divisibility checks in part b.
    • Corrected logical operators (AND, OR, ELSEIF) in part a.
  2. Proper Range Handling:

    • Ranges for percentage values were clarified with AND and TO for the correct logic.
  3. Output:

    • All outputs are displayed correctly based on user input.

Both the IF-END IF and SELECT CASE implementations are now error-free.


6. Write the program for the following:

Here are the QBasic programs for the given problems:


a. Program to Find the Area of a Triangle

REM Program to Find the Area of a Triangle
INPUT "Enter the base of the triangle: "; b
INPUT "Enter the height of the triangle: "; h

area = (1 / 2) * b * h

PRINT "The area of the triangle is: "; area
END

b. Program to Find the Simple Interest

REM Program to Find the Simple Interest
INPUT "Enter Principal Amount (P): "; P
INPUT "Enter Rate of Interest (R): "; R
INPUT "Enter Time Period (T): "; T

SI = (P * T * R) / 100

PRINT "The Simple Interest is: "; SI
END

c. Program to Calculate the Volume of a Cube

REM Program to Calculate the Volume of a Cube
INPUT "Enter the side length of the cube (L): "; L

V = L ^ 3

PRINT "The volume of the cube is: "; V
END

d. Program to Calculate the Perimeter of a Rectangle

REM Program to Calculate the Perimeter of a Rectangle
INPUT "Enter the length of the rectangle (L): "; L
INPUT "Enter the breadth of the rectangle (B): "; B

P = 2 * (L + B)

PRINT "The perimeter of the rectangle is: "; P
END

e. Program to Calculate Total Fare Based on Destination

REM Program to Calculate Total Fare
CLS
INPUT "Enter Passenger's Name: "; Name$
INPUT "Enter Number of Passengers: "; Num
INPUT "Enter Destination (Pokhara/Dharan/Kakrivitta): "; Destination$

IF UCASE$(Destination$) = "POKHARA" THEN
    Rate = 1800
ELSEIF UCASE$(Destination$) = "DHARAN" THEN
    Rate = 1980
ELSEIF UCASE$(Destination$) = "KAKRIVITTA" THEN
    Rate = 2000
ELSE
    PRINT "Invalid Destination!"
    END
END IF

TotalFare = Rate * Num

PRINT "Name: "; Name$
PRINT "Destination: "; Destination$
PRINT "Number of Passengers: "; Num
PRINT "Total Fare: "; TotalFare
END

f. Program to Check if a Name Starts with "A"

REM Program to Check if a Name Starts with "A"
CLS
INPUT "Enter a Name: "; Name$

IF LEFT$(UCASE$(Name$), 1) = "A" THEN
    PRINT "The name starts with 'A'."
ELSE
    PRINT "The name does not start with 'A'."
END IF

END

Explanation:

  1. Each program uses the INPUT statement to gather necessary inputs.
  2. Arithmetic operations such as *, /, ^ are used for calculations.
  3. IF-ELSEIF and STRING Functions (e.g., LEFT$, UCASE$) are used for logical conditions.
  4. Programs handle invalid inputs in part e.

All these programs are written for QBasic and will run correctly when tested.

No comments:

Post a Comment

Popular Posts