Table of Contents

    Practice Assignment: Operators and Expressions

    Programming Mastery

    Practice Assignment: Operators and Expressions

    Practice arithmetic operators, assignment operators, logical operators, increment and decrement concepts, operator precedence, operator associativity, and expression evaluation using language-neutral pseudocode.

    Assignment Overview

    This practice assignment is designed to help students apply the concepts of operators and expressions in programming. Students will identify operators, evaluate expressions, use assignment operators, apply logical conditions, understand precedence and associativity, and write small language-neutral pseudocode programs.

    The purpose of this assignment is not to memorize syntax from one programming language. Instead, students should understand how operators work, how expressions produce results, and how programs use operators to calculate, compare, assign, and make decisions.

    Operators help a program perform actions on data, and expressions combine values, variables, and operators to produce results.

    Learning Objectives

    After completing this assignment, students should be able to:

    Objectives

    • Identify operators and operands in expressions.
    • Differentiate between arithmetic, assignment, comparison, and logical operators.
    • Evaluate arithmetic expressions step by step.
    • Use assignment operators to store and update values.
    • Apply logical operators in decision-making expressions.
    • Understand increment and decrement concepts.
    • Apply operator precedence rules correctly.
    • Understand operator associativity in same-precedence expressions.
    • Use parentheses to make expressions clearer.
    • Write simple pseudocode programs using operators and expressions.

    Prerequisites

    Before attempting this assignment, students should revise the following topics:

    Required Topics

    • What are operators?
    • Operators and operands.
    • Expressions and statements.
    • Arithmetic operators.
    • Assignment operators.
    • Logical operators.
    • Increment and decrement operators.
    • Operator precedence.
    • Operator associativity.
    • Variables and data types.

    Assignment Instructions

    Read each task carefully and write your answers clearly. Use language-neutral pseudocode where coding is required.

    Important: Use clear variable names and show step-by-step evaluation wherever needed. Do not depend on a specific programming language.

    General Instructions

    • Write answers in a clean and organized format.
    • Use pseudocode keywords such as SET, DECLARE, INPUT, DISPLAY, IF, and ELSE.
    • Show calculations step by step for expression evaluation tasks.
    • Use parentheses where they make expressions clearer.
    • Use meaningful variable names.
    • Clearly mention the operator type where asked.
    • Check whether the result should be numeric or Boolean.
    • Avoid overly complex one-line expressions.

    Task 1: Identify Operator, Operand, and Expression

    Identify the operators, operands, and final expression from the given examples.

    Expression Operators Operands Expression Purpose
    10 + 5 ________________ ________________ ________________
    price * quantity ________________ ________________ ________________
    age >= 18 ________________ ________________ ________________
    isLoggedIn AND hasPermission ________________ ________________ ________________
    score += 10 ________________ ________________ ________________

    Task 2: Identify the Operator Type

    Identify whether each operator is arithmetic, assignment, comparison, or logical.

    Operator Operator Type Purpose
    + ________________ ________________
    = ________________ ________________
    * ________________ ________________
    >= ________________ ________________
    AND ________________ ________________
    OR ________________ ________________
    NOT ________________ ________________
    % ________________ ________________

    Task 3: Evaluate Arithmetic Expressions

    Evaluate the following expressions step by step.

    1. 10 + 5 * 2
    2. (10 + 5) * 2
    3. 20 - 4 * 3 + 2
    4. 100 / 5 / 2
    5. 100 / 5 % 3
    6. 8 + 2 * 5 - 6 / 3
    7. (8 + 2) * (5 - 3)
    8. 25 % 4 + 6

    Your Answer Format

    Expression:
    Step-by-step evaluation:
    Final result:

    Task 4: Assignment Operators

    Find the final value of score after each operation.

    SET score = 50
    
    SET score += 20
    SET score -= 10
    SET score *= 2
    SET score /= 5
    SET score %= 7
    
    DISPLAY score

    Your Task

    Write the value of score after each step.

    Step Statement Value of score
    Start score = 50 ________
    1 score += 20 ________
    2 score -= 10 ________
    3 score *= 2 ________
    4 score /= 5 ________
    5 score %= 7 ________

    Task 5: Logical Operators

    Evaluate the following logical expressions. Assume:

    SET isLoggedIn = true
    SET isAdmin = false
    SET hasPermission = true
    SET isBanned = false
    Logical Expression Result Reason
    isLoggedIn AND hasPermission ________ ________________
    isAdmin OR hasPermission ________ ________________
    NOT isBanned ________ ________________
    isLoggedIn AND NOT isBanned ________ ________________
    isAdmin AND hasPermission ________ ________________

    Task 6: Increment and Decrement Concepts

    Trace the value of counter after each statement.

    SET counter = 3
    
    SET counter = counter + 1
    SET counter = counter + 1
    SET counter = counter - 1
    SET counter = counter + 1
    SET counter = counter - 1
    
    DISPLAY counter

    Trace Table

    Step Statement Value of counter
    Start counter = 3 ________
    1 counter = counter + 1 ________
    2 counter = counter + 1 ________
    3 counter = counter - 1 ________
    4 counter = counter + 1 ________
    5 counter = counter - 1 ________

    Task 7: Operator Precedence

    Add parentheses to show the actual evaluation order.

    Expression Add Parentheses to Show Evaluation Order
    10 + 5 * 2 ________________________
    20 - 4 * 3 ________________________
    100 / 5 + 10 ________________________
    marks1 + marks2 + marks3 / 3 ________________________
    price * quantity - discount ________________________

    Task 8: Operator Associativity

    Identify the grouping based on associativity.

    Expression Common Grouping Result / Meaning
    20 - 5 - 3 ________________ ________________
    100 / 5 / 2 ________________ ________________
    100 / 5 % 3 ________________ ________________
    50 - 10 + 5 ________________ ________________
    a = b = c = 10 ________________ ________________

    Task 9: Find and Correct the Mistakes

    Identify the problems in the following pseudocode and rewrite it correctly.

    SET mathMarks = 80
    SET scienceMarks = 70
    SET englishMarks = 90
    
    SET averageMarks = mathMarks + scienceMarks + englishMarks / 3
    
    IF averageMarks >= 35 OR averageMarks <= 100 THEN
        DISPLAY "Valid average"
    ELSE
        DISPLAY "Invalid average"
    END IF

    Mistakes to Find

    • Average calculation may be wrong because parentheses are missing.
    • The logical condition may not correctly check the valid range.
    • The condition should likely require both minimum and maximum rules to be true.
    • The expression should be written clearly for readability.

    Write Corrected Version

    WRITE YOUR CORRECTED PSEUDOCODE HERE

    Task 10: Mini Program - Simple Calculator

    Write language-neutral pseudocode for a simple calculator.

    Requirements

    • Input two numbers.
    • Calculate addition.
    • Calculate subtraction.
    • Calculate multiplication.
    • Calculate division.
    • Calculate remainder if applicable.
    • Display all results clearly.
    • Use meaningful variable names.
    • Avoid division by zero.

    Your Pseudocode

    WRITE YOUR SIMPLE CALCULATOR PSEUDOCODE HERE

    Task 11: Mini Program - Student Eligibility Checker

    Write pseudocode to check whether a student is eligible for an exam.

    Requirements

    • Input student name.
    • Input attendance percentage.
    • Input whether fees are paid.
    • Input whether the student has an admit card.
    • Use logical operators to check eligibility.
    • Student is eligible if attendance is at least 75, fees are paid, and admit card is available.
    • Display eligibility result.

    Your Pseudocode

    WRITE YOUR STUDENT ELIGIBILITY CHECKER PSEUDOCODE HERE

    Task 12: Mini Program - Billing Expression

    Write pseudocode to calculate a final bill amount using arithmetic and assignment operators.

    Requirements

    • Input product price.
    • Input quantity.
    • Input discount amount.
    • Calculate subtotal using multiplication.
    • Calculate final amount after discount.
    • If final amount is greater than or equal to 1000, display “Large purchase”.
    • Otherwise, display “Regular purchase”.
    • Use parentheses where needed.

    Your Pseudocode

    WRITE YOUR BILLING EXPRESSION PSEUDOCODE HERE

    Bonus Challenge

    Create a small program that uses at least three types of operators.

    Requirements

    • Use at least one arithmetic operator.
    • Use at least one assignment operator.
    • Use at least one logical operator.
    • Use at least one comparison operator.
    • Use parentheses in at least one expression.
    • Display the final result clearly.

    Bonus Pseudocode Area

    WRITE YOUR BONUS PROGRAM HERE

    Submission Checklist

    Before submitting, students should check the following:

    Checklist

    • All expressions are evaluated step by step where required.
    • Operator types are identified correctly.
    • Assignment operators are expanded correctly when needed.
    • Logical operators are used correctly.
    • Parentheses are used for clarity.
    • Precedence rules are applied correctly.
    • Associativity rules are considered when operators have the same precedence.
    • Variable names are meaningful.
    • Pseudocode is language-neutral.
    • Answers are neat and easy to understand.

    Evaluation Rubric

    The assignment can be evaluated using the following rubric.

    Criteria Marks What to Check
    Operator Identification 10 Correctly identifies operators and operands.
    Operator Type Classification 10 Correctly classifies arithmetic, assignment, comparison, and logical operators.
    Expression Evaluation 20 Evaluates expressions step by step with correct results.
    Assignment Operator Usage 10 Correctly traces variable updates.
    Logical Expression Handling 15 Correctly applies AND, OR, and NOT conditions.
    Precedence and Associativity 15 Uses correct evaluation order and grouping.
    Pseudocode Programs 15 Writes clear, logical, language-neutral pseudocode.
    Presentation and Readability 5 Answers are neat, readable, and well-structured.

    Sample Answer Key

    This answer key can be used by instructors for checking. Students should attempt the assignment first before viewing the answers.

    Task 3: Arithmetic Expression Answers

    Expression Evaluation Result
    10 + 5 * 2 10 + 10 20
    (10 + 5) * 2 15 * 2 30
    20 - 4 * 3 + 2 20 - 12 + 2 10
    100 / 5 / 2 20 / 2 10
    100 / 5 % 3 20 % 3 2
    8 + 2 * 5 - 6 / 3 8 + 10 - 2 16
    (8 + 2) * (5 - 3) 10 * 2 20
    25 % 4 + 6 1 + 6 7

    Task 4: Assignment Operator Answer

    Step Statement Value of score
    Start score = 50 50
    1 score += 20 70
    2 score -= 10 60
    3 score *= 2 120
    4 score /= 5 24
    5 score %= 7 3

    Task 9: Corrected Pseudocode

    SET mathMarks = 80
    SET scienceMarks = 70
    SET englishMarks = 90
    
    SET averageMarks = (mathMarks + scienceMarks + englishMarks) / 3
    
    IF averageMarks >= 35 AND averageMarks <= 100 THEN
        DISPLAY "Valid average"
    ELSE
        DISPLAY "Invalid average"
    END IF

    Task 10: Simple Calculator Sample

    ENTRY POINT
        DECLARE numberOne AS DECIMAL = 0.0
        DECLARE numberTwo AS DECIMAL = 0.0
        DECLARE sum AS DECIMAL = 0.0
        DECLARE difference AS DECIMAL = 0.0
        DECLARE product AS DECIMAL = 0.0
        DECLARE quotient AS DECIMAL = 0.0
    
        INPUT numberOne
        INPUT numberTwo
    
        SET sum = numberOne + numberTwo
        SET difference = numberOne - numberTwo
        SET product = numberOne * numberTwo
    
        IF numberTwo != 0 THEN
            SET quotient = numberOne / numberTwo
            DISPLAY quotient
        ELSE
            DISPLAY "Division by zero is not allowed"
        END IF
    
        DISPLAY sum
        DISPLAY difference
        DISPLAY product
    END ENTRY POINT

    Task 11: Student Eligibility Checker Sample

    ENTRY POINT
        DECLARE studentName AS TEXT = ""
        DECLARE attendancePercentage AS DECIMAL = 0.0
        DECLARE feesPaid AS BOOLEAN = false
        DECLARE hasAdmitCard AS BOOLEAN = false
    
        INPUT studentName
        INPUT attendancePercentage
        INPUT feesPaid
        INPUT hasAdmitCard
    
        IF attendancePercentage >= 75 AND feesPaid AND hasAdmitCard THEN
            DISPLAY "Student is eligible for exam"
        ELSE
            DISPLAY "Student is not eligible for exam"
        END IF
    END ENTRY POINT

    Task 12: Billing Expression Sample

    ENTRY POINT
        DECLARE productPrice AS DECIMAL = 0.0
        DECLARE quantity AS INTEGER = 0
        DECLARE discountAmount AS DECIMAL = 0.0
        DECLARE subtotal AS DECIMAL = 0.0
        DECLARE finalAmount AS DECIMAL = 0.0
    
        INPUT productPrice
        INPUT quantity
        INPUT discountAmount
    
        SET subtotal = productPrice * quantity
        SET finalAmount = subtotal - discountAmount
    
        IF finalAmount >= 1000 THEN
            DISPLAY "Large purchase"
        ELSE
            DISPLAY "Regular purchase"
        END IF
    
        DISPLAY subtotal
        DISPLAY finalAmount
    END ENTRY POINT

    Quick Summary

    Concept What Students Practiced
    Operators Identifying symbols or keywords that perform operations.
    Operands Identifying values or variables used by operators.
    Expressions Combining operators and operands to produce results.
    Arithmetic Operators Performing calculations such as addition, subtraction, multiplication, division, and modulus.
    Assignment Operators Storing and updating variable values.
    Logical Operators Combining Boolean conditions using AND, OR, and NOT.
    Precedence Applying correct operation priority.
    Associativity Evaluating same-precedence operators in the correct direction.

    Final Takeaway

    This assignment helps students practice one of the most important foundations of programming: operators and expressions. Students should understand that operators perform actions, operands provide values, expressions produce results, and precedence and associativity control how expressions are evaluated. Mastering these concepts will make future topics such as conditions, loops, functions, arrays, and algorithms much easier.