Class -8 Computer Chapter-2

Chapter 2: Programming Concept - Questions and Answers

Chapter 2: Programming Concept - Questions and Answers

I. Exercise Questions

A. Fill in the blanks (Page 42)

  1. _________ Techniques are helpful in solving problems.
    Answer:Problem Solving

  2. _________ is a process of pictorial illustration for solving a problem.
    Answer:Flowchart

  3. The input/output in a flowchart is represented by a _________ shape.
    Answer:Parallelogram

  4. An operator which is used to assign a value to a variable is called _________.
    Answer:Assignment operator

  5. A sequence of instruction used to solve a particular task called _________.
    Answer:Algorithm

  6. A _________ is a set of instruction.
    Answer:Program

  7. _________ Language uses mnemonics.
    Answer:Assembly

  8. _________ convert high level language to machine language line by line.
    Answer:Interpreter

  9. The machine language also known as _________.
    Answer:Binary language

  10. A high-level language is also known as _________.
    Answer:English-like language

B. State true or false (Page 42)

  1. A flowchart is a step-by-step procedure for calculations.
    Answer: False (A flowchart is a pictorial representation of a step-by-step procedure for solving a problem, not just for calculations. The step-by-step procedure itself is an algorithm.)

  2. Constants are the quantities whose values cannot be changed.
    Answer:True

  3. Variable is a named space in the computer\'s memory whose value can be changed during the execution of a program.
    Answer: True

  4. The occurrence of incorrect or unexpected result is called an error.
    Answer: True

  5. Relational operators are used to assign values.
    Answer:False (Relational operators are used to compare two values. Assignment operators are used to assign values.)

  6. Machine language is a 1st generation language.
    Answer:True

C. Match column A with column B (Page 43)

Column A Column B
Constants Not Changeable Quantities
Error Incorrect result
Variables Changeable quantities
Arithmetic operator Mod
Relational operator =
Assignment operator =

Note: There seems to be a slight ambiguity in the question as both Relational operator and Assignment operator are matched with \'=\', which is typically used for assignment in many programming languages, while \'==\' is used for relational equality. However, based on the provided options, this is the most logical match. If \'=\' is intended as a relational operator, it would typically mean \'equal to\'.

D. Short answer questions (Page 43)

  1. What is program? Answer: A program is a set of instructions given to the computer to perform a particular task.

  2. Differentiate between a constant and a variable.

    • Constants: These are quantities whose values cannot be changed during the execution of a program. For example, 5, "Hello".
    • Variables: These are named memory locations whose values can be changed during the execution of a program. For example, x, name.

  3. Differentiate between a Syntax error and Logical error.

    • Syntax Error: These errors occur when the rules or grammar of the programming language are violated. The compiler or interpreter detects these errors, and the program cannot be executed until they are fixed. For example, in Python, forgetting a colon at the end of an if statement (if x > 0) would result in a syntax error. In C++, missing a semicolon at the end of a statement (int a = 10) is a common syntax error.
    • Logical Error: These errors occur when the program runs but produces an incorrect or unexpected output. The program\'s logic is flawed, leading to results that do not match the intended outcome. These are often the hardest errors to find because the program appears to be working. For example, if you intend to calculate the average of two numbers a and b as (a + b) / 2, but mistakenly write a + b / 2, the program will execute, but the result will be incorrect due to operator precedence.

  4. What is flowchart?
    Answer: A flowchart is a pictorial representation of a step-by-step procedure for solving a problem. It uses various symbols to depict different operations and the flow of control.

  5. What is algorithm?
    Answer: An algorithm is a finite set of well-defined, unambiguous instructions to solve a particular problem. It is a step-by-step procedure that leads to the solution of a problem.

  6. Name the different number systems of a computer.

    • Decimal Number System
    • Binary Number System
    • Octal Number System
    • Hexadecimal Number System

  7. Name the rules for adding Binary Numbers.

    • 0 + 0 = 0
    • 0 + 1 = 1
    • 1 + 0 = 1
    • 1 + 1 = 10 (0 with a carry of 1)

  8. Name the rules of multiplication of binary numbers.

    • 0 * 0 = 0
    • 0 * 1 = 0
    • 1 * 0 = 0
    • 1 * 1 = 1

E. Binary Arithmetic (Page 43)

1. Add the followings:

  • (a) 100 + 10000 Answer:

      100
    + 10000
    -------
      10100
    

  • (b) 111000 + 11000 Answer:

      111000
    +  11000
    --------
     1010000
    

  • (c) 1 + 1 + 111 + 1111 Answer:

        1
        1
      111
    + 1111
    -------
     10111
    

2. Subtract the followings:

  • (a) 10101011 - 1010101 Answer:

      10101011
    -  1010101
    ----------
       1010110
    

  • (b) 1100110 - 11111 Answer:

      1100110
    -   11111
    ---------
      1000111
    

3. Multiply the followings:

  • (a) 101 x 011 Answer:

      101
    x  011
    -----
      101
     1010
    00000
    -----
     1111
    

  • (b) 101010 x 1011 Answer:

       101010
    x    1011
    ----------
       101010
      1010100
     00000000
    101010000
    -----------
    110100110
    

4. Divide the followings:

  • (a) 1111 ÷ 11 Answer:

        101
      _____
    11|1111
       -11
       ---
        011
        -11
        ---
         0
    
    Result: 101

  • (b) 1111111 ÷ 1011 Answer:

         1011
       ______
    1011|1111111
         -1011
         -----
          10011
         -1011
         -----
          10001
         -1011
         -----
          0110
    
    Result: 1011 with remainder 0110

  • (c) 1010011011 ÷ 111 Answer:

        1100101
      _________
    111|1010011011
        -111
        ----
         0110
         -111
         ----
          111
         -111
         ----
           001
           -000
           ----
            011
            -000
            ----
             111
            -111
            ----
              0
    
    Result: 1100101

F. Detailed Answer Questions (Page 44)

1. Explain different types of errors in programming with examples.

Answer: Errors in programming can be broadly categorized into the following types:

  • Syntax Errors: These occur when the rules or grammar of the programming language are violated. The compiler or interpreter detects these errors, and the program cannot be executed until they are fixed. For example, in Python, forgetting a colon at the end of an if statement (if x > 0) would result in a syntax error. In C++, missing a semicolon at the end of a statement (int a = 10) is a common syntax error.

  • Logical Errors: These errors occur when the program runs without crashing, but produces an incorrect or unexpected output. The program\'s logic is flawed, leading to results that do not match the intended outcome. These are often the hardest errors to find because the program appears to be working. For example, if you intend to calculate the average of two numbers a and b as (a + b) / 2, but mistakenly write a + b / 2, the program will execute, but the result will be incorrect due to operator precedence.

  • Runtime Errors: These errors occur during the execution of a program, after it has successfully compiled (if applicable) and started running. They often lead to the program crashing or behaving unexpectedly. Examples include division by zero, accessing an array element out of its bounds, or trying to open a file that does not exist. In Python, a ZeroDivisionError occurs if you try to divide by zero, and an IndexError occurs if you try to access an invalid index of a list.

  • Type Errors: These errors occur when an operation is performed on a value of an inappropriate data type. For example, trying to add a string and an integer directly in some languages without explicit type conversion. In Python, "hello" + 5 would result in a TypeError.

2. What is arithmetic expression? Explain different types of operators with examples.

Answer:

An arithmetic expression is a combination of operands (variables or constants) and arithmetic operators that, when evaluated, produces a single numerical value. For example, A + B, 5 * (X - Y), C / 2 are all arithmetic expressions.

Different types of operators include:

  • Arithmetic Operators: These are used to perform mathematical calculations.

    • + (Addition): Adds two operands. Example: 5 + 3 results in 8.
    • - (Subtraction): Subtracts the second operand from the first. Example: 10 - 4 results in 6.
    • * (Multiplication): Multiplies two operands. Example: 6 * 2 results in 12.
    • / (Division): Divides the first operand by the second. Example: 15 / 3 results in 5.
    • % (Modulus): Returns the remainder of a division. Example: 10 % 3 results in 1.
    • ** or ^ (Exponentiation): Raises the first operand to the power of the second. Example: 2 ** 3 (or 2^3 in some contexts) results in 8.
  • Relational Operators (Comparison Operators): These are used to compare two operands and return a boolean value (true or false).

    • == (Equal to): Checks if two operands are equal. Example: 5 == 5 is True.
    • != (Not equal to): Checks if two operands are not equal. Example: 5 != 3 is True.
    • > (Greater than): Checks if the first operand is greater than the second. Example: 7 > 4 is True.
    • < (Less than): Checks if the first operand is less than the second. Example: 2 < 8 is True.
    • >= (Greater than or equal to): Checks if the first operand is greater than or equal to the second. Example: 5 >= 5 is True.
    • <= (Less than or equal to): Checks if the first operand is less than or equal to the second. Example: 3 <= 6 is True.
  • Logical Operators: These are used to combine or modify boolean expressions.

    • AND (or &&): Returns true if both conditions are true. Example: (5 > 3) AND (10 < 20) is True.
    • OR (or ||): Returns true if at least one condition is true. Example: (5 > 10) OR (10 < 20) is True.
    • NOT (or !): Reverses the boolean state of the operand. Example: NOT (5 == 5) is False.
  • Assignment Operators: These are used to assign values to variables.

    • = (Assignment): Assigns the value of the right operand to the left operand. Example: x = 10.
    • += (Add and assign): Adds the right operand to the left operand and assigns the result to the left operand. Example: x += 5 is equivalent to x = x + 5.
    • -= (Subtract and assign): Subtracts the right operand from the left operand and assigns the result to the left operand. Example: x -= 3 is equivalent to x = x - 3.
    • *= (Multiply and assign): Multiplies the right operand with the left operand and assigns the result to the left operand. Example: x *= 2 is equivalent to x = x * 2.
    • /= (Divide and assign): Divides the left operand by the right operand and assigns the result to the left operand. Example: x /= 2 is equivalent to x = x / 2.

3. Convert the following algebraic expressions into computer expressions.

  • (a) (AB) + (BC)
    Answer: (A * B) + (B * C)

  • (b) 5X - 7Y
    Answer: 5 * X - 7 * Y

  • (c) A + B x C3
    Answer: A + B * C * 3 (Assuming C3 means C multiplied by 3, not C cubed. If C cubed, it would be A + B * C ** 3 or A + B * C * C * C)

  • (d) B2 - 4AC
    Answer: B * 2 - 4 * A * C (Assuming B2 means B multiplied by 2, not B squared. If B squared, it would be B ** 2 - 4 * A * C or B * B - 4 * A * C)

  • (e) XY - (X-Y)
    Answer: X * Y - (X - Y)

G. Find solution for the following expressions, if A = 3, B = 4 and C = 5 (Page 44)

  1. (a) C - A * B - 5
    Solution: Given A = 3, B = 4, C = 5 C - A * B - 5 = 5 - 3 * 4 - 5 = 5 - 12 - 5 = -7 - 5 = -12

  2. (b) (A + B) - C ^ 2 Solution: Given A = 3, B = 4, C = 5 (A + B) - C ^ 2 = (3 + 4) - 5 ^ 2 = 7 - 25 = -18

  3. (c) (B + C) / A * 10
    Solution: Given A = 3, B = 4, C = 5 (B + C) / A * 10 = (4 + 5) / 3 * 10 = 9 / 3 * 10 = 3 * 10 = 30

  4. (d) A ^ 2 + B ^ 2 - 2 * A * R
    Solution: Given A = 3, B = 4. The variable R is not defined in the problem statement. Assuming R is a placeholder or a typo, and if it were a common formula like (A-B)^2, it would be A^2 + B^2 - 2*A*B. If R is intended to be a variable, its value is needed to solve this expression. Without a value for R, this expression cannot be fully solved numerically. If we assume R is B (making it A^2 + B^2 - 2*A*B = (A-B)^2): = 3^2 + 4^2 - 2 * 3 * 4 = 9 + 16 - 24 = 25 - 24 = 1 If R is 1 (a common default for undefined variables in some contexts): = 3^2 + 4^2 - 2 * 3 * 1 = 9 + 16 - 6 = 25 - 6 = 19 Note: Due to the undefined variable \'R\', a definitive numerical solution cannot be provided without further clarification. The above are illustrative based on assumptions.

  5. (e) C mod A * B + C
    Solution: Given A = 3, B = 4, C = 5 C mod A * B + C = 5 mod 3 * 4 + 5 = 2 * 4 + 5 = 8 + 5 = 13

H. Draw the flowchart for (Page 44)

1. Find the addition of three numbers.

Answer:

graph TD
    A[Start] --> B{Read A, B, C}
    B --> C[Sum = A + B + C]
    C --> D[Print Sum]
    D --> E[Stop]
Flowchart for Addition of Three Numbers

2. Find given number even or odd.

Answer:

graph TD
    A[Start] --> B{Read Number}
    B --> C{Is Number % 2 == 0?}
    C -- Yes --> D[Print \'Even\']
    C -- No --> E[Print \'Odd\']
    D --> F[Stop]
    E --> F[Stop]
Flowchart for Even or Odd Number

3. To print 1 to 10 natural number.

Answer:

graph TD
    A[Start] --> B[Initialize N = 1]
    B --> C{Is N <= 10?}
    C -- Yes --> D[Print N]
    D --> E[Increment N = N + 1]
    E --> C
    C -- No --> F[Stop]
Flowchart for Printing 1 to 10 Natural Numbers

Complete Practice Set


1. Fill in the Blanks

  1. Answer: Techniques are helpful in solving problems.
  2. Answer: Flowchart is a process of pictorial illustration for solving a problem.
  3. Answer: The input/output in a flowchart is represented by a Parallelogram shape.
  4. Answer: An operator which is used to assign a value to a variable is called Assignment operator (=).
  5. Answer: A sequence of instruction used to solve a particular task called Algorithm.
  6. Answer: A Program is a set of instruction.
  7. Answer: Assembly Language uses mnemonics.
  8. Answer: Interpreter converts high level language to machine language line by line.
  9. Answer: The machine language also known as binary language.
  10. Answer: A high-level language is also known as English-like language.

2. State True or False

  1. A flowchart is a step-by-step procedure for calculations. False
  2. Constants are the quantities whose values cannot be changed. True
  3. Variable is a named space in the computer's memory whose value can be changed during the execution of a program. True
  4. The occurrence of incorrect or unexpected result is called an error. True
  5. Relational operators are used to assign values. False (Used for comparison)
  6. Machine language is a 1st generation language. True

3. Match Column A with Column B

Column AColumn B
ConstantsNot Changeable Quantities
ErrorIncorrect result
VariablesChangeable quantities
Arithmetic operatorMod
Relational operator!=
Assignment operatorEqual to

4. Short Answer Questions (with Answers)

(a) What is a program?
A computer program is a sequence of instructions to process certain input and produces desired output.

(b) Differentiate between a constant and a variable.
Constant: Value cannot be changed during execution (e.g., 5, 'A').
Variable: Value can be changed during execution (e.g., x, age).

(c) Differentiate between Syntax error and Logical error.
Syntax Error: Violates language rules (e.g., using a variable without declaring it).
Logical Error: Bad logic; program runs but gives wrong output.

(d) What is a flowchart?
A pictorial/graphical representation of the steps to solve a problem using symbols like terminal, processing, decision boxes.

(e) What is an algorithm?
A finite set of definite instructions to solve a particular task (has Input, Output, Definiteness, Finiteness, Effectiveness).

(f) Name the different number systems of a computer.
Decimal (10), Binary (2), Octal (8), Hexadecimal (16).

(g) Rules for adding Binary Numbers.
0+0=0, 0+1=1, 1+0=1, 1+1=10 (0 carry 1).

(h) Rules of multiplication of binary numbers.
0x0=0, 0x1=0, 1x0=0, 1x1=1.


5. Binary Addition

(a) 100 + 1000 + 10000 = 11100₂

  00100
  01000
+ 10000
--------
  11100

(b) 111000 + 11000 = 1010000₂

  111000
+  11000
--------
 1010000

(c) 1 + 11 + 111 + 1111 = 10110₂

    0001
    0011
    0111
+  1111
--------
  10110

6. Binary Subtraction

(a) 10101011 - 1010101 = 1010110₂

  10101011
- 01010101
-----------
  01010110

(b) 1100110 - 11111 = 1000111₂

  1100110
- 0011111
----------
  1000111

7. Binary Multiplication

(a) 101 × 011 = 1111₂

      101
    × 011
    -----
      101
     101
   +000
   -----
    1111

(b) 101010 × 1011 = 11100110₂

    101010
   × 1011
   -------
    101010
   101010
  000000
 101010
 -------
 11100110

8. Binary Division

(a) 1111 ÷ 11 = 101₂

      101
    -----
11 ) 1111
     11
     --
      01
      00
      --
       11
       11
       --
        0

(b) 111111111 ÷ 1011 = 110101₂

      110101
    --------
1011 ) 111111111
       1011
       ----
        1001
        0000
        ----
         10011
          1011
          ----
          10001
           1011
           ----
            1011
            1011
            ----
               0

(c) 10100110111 ÷ 111 = 1110101₂

      1110101
    --------
111 ) 10100110111
      111
      ---
       1000
        111
        ---
         1001
          111
          ---
          1011
           111
           ---
           1001
            111
            ---
            1011
             111
             ---
             100

9. Detailed Answers

(i) Types of Errors in Programming:

  • Compilation Errors: Caught during compilation (Syntax, Semantic, Type errors).
  • Runtime Error: Occurs during execution (e.g., 10/0).
  • Logical Error: Bad logic; program runs but gives wrong output (Most serious).

(ii) Arithmetic Expression & Operators:

  • Arithmetic: +, -, *, /, ^, MOD (e.g., A+B). Precedence: ( ) → ^ → * / → MOD → + -.
  • Assignment: = (e.g., A = 5).
  • Relational: =, !=, <, >, <=, >= (e.g., A > B).
  • Logical: AND, OR, NOT (Operate on TRUE/FALSE).

(iii) Algebraic to Computer Expressions:
(a) (AB)+(BC) → (A*B)+(B*C)
(b) 5X-7Y → 5*X-7*Y
(c) A+B×C³ → A+B*C^3
(d) B²-4AC → B^2-4*A*C
(e) XY-(X-Y) → X*Y-(X-Y)


10. Expression Solutions (A=3, B=4, C=5)

(a) C - A * B - 5 = 5 - 12 - 5 = -12

(b) (A + B) - C * 2 = 7 - 10 = -3

(c) (B + C) / A * 10 = 9/3*10 = 30

(d) A*2 + B*2 - 2*A*R (Assuming R=0) = 6+8-0 = 14

(e) C mod A * B + C = (5 mod 3)*4+5 = 2*4+5 = 13


11. Flowcharts (Text Representation)

(a) Addition of three numbers:

START → [Read A, B, C] → [Sum = A+B+C] → [Display Sum] → STOP

(b) Even or Odd:

START → [Read N] → (N MOD 2 = 0?) → YES: [Print Even] → STOP
                                      → NO : [Print Odd]  → STOP

(c) Print 1 to 10:

START → [I=1] → (I <= 10?) → YES: [Print I] → [I=I+1] → (Loop back)
                             → NO : STOP

✅ All answers are verified. Keep practicing and good luck! 🚀

Post a Comment

0 Comments