Visual Logic: Arithmetic Expressions & Intrinsic Functions (Vocabulary)

Visual Logic: Arithmetic Expressions and Intrinsic Functions – Study Notes

PEMDAS and Basic Arithmetic Expressions

  • Order of operations (PEMDAS):

    • P: Parentheses

    • E: Exponents

    • M/D: Multiplication and Division (from left to right)

    • A/S: Addition and Subtraction (from left to right)

  • Examples (evaluate with PEMDAS):

    • 4 - 5 + 2 = 1

    • 1 + 3 \times 7 = 22

    • 52 + 2 \times 8 = 68

    • \dfrac{12}{4} \times 2 = 6

    • \dfrac{12}{5} + 3 = \dfrac{27}{5} = 5.4

  • Expressions (as listed in the transcript):

    • 4 - 5 + 2

    • 1 + 3*7

    • 52 + 2*8

    • 12/4*2

    • 12/5+3

  • Note: Visual Logic distinguishes between standard division (/) and integer division ().

Operators in Visual Logic

  • Exponentiation: ^

    • Example: 2^3 = 8

  • Multiplication and Division: * , /

    • Examples: 2 \times 3 = 6\quad 5 / 2 = 2.5

  • Integer Division: "$\"" (backslash) operator

    • Examples: 5\2 = 2\quad 38\10 = 3

  • Integer Remainder: Mod

    • Example: 5\,\text{Mod}\, 2 = 1

  • Addition and Subtraction: + , -

    • Example: 2 + 15 = 17

  • Important note: The “New Operators” discussed are for integers (whole numbers) only for integer division and remainder.

  • Additional examples (from transcript):

    • Integer Division: 12\4 = 3\quad 17\3 = 5

    • Integer Remainder: 12 \text{ Mod } 4 = 0\quad 17 \text{ Mod } 3 = 2

Quick Check 1-A (content review and interpretation)

  • 1-A setup: A = 3, B = 5

    • Evaluate: A + B * 5

    • With PEMDAS, this is 3 + 5 \times 5 = 28.

    • Evaluate: (2 * 3)^2

    • (2 \times 3)^2 = 6^2 = 36

    • Evaluate: A = 2 * 3^2

    • Exponent before multiplication: 3^2 = 9 \Rightarrow 2 \times 9 = 18\Rightarrow A = 18

    • A mod A: In general, A \bmod A = 0 (since any number modulo itself is 0). If A = 18, then 18 \bmod 18 = 0.

    • 1-B items (from transcript, note that some entries are garbled):

    • 1.(Exam 1 + Exam 2 + Exam 3)/3

    • 2. 1 + 1 / 2 + 1/4

    • 3. (4A^2B)/C (question about needed parentheses)

    • Takeaway: These items test understanding of order of operations and when parentheses are necessary. For item 2, with standard precedence, the value is 1 + \frac{1}{2} + \frac{1}{4} = 1.75. For item 3, parentheses clarify the numerator vs. denominator depending on intended grouping.

  • Ambiguity in transcript: some lines appear garbled (e.g., results like 40 vs 28, and a mismatched A value). Use the above consistent interpretations and verify against the exact source when possible.

Average Example (Visual Logic program)

  • Purpose: compute the average of three numbers:

    • Formula: \text{Avg} = \dfrac{\text{Num1} + \text{Num2} + \text{Num3}}{3}

  • Pseudo program structure shown in the transcript:

    • Main

    • NUM1: 2

    • NUM2: 3

    • NUM3: 4

    • AVG: 3

    • Begin

    • Input: Num1

    • Input: Num2

    • Input: Num3

    • Avg =

      • (Num1 + Num2 + Num3) / 3

    • End

  • Important concept: intrinsic to Visual Logic, use of Step Into, Variable Watch to trace values during execution.

Odd or Even – Parity Check

  • Problem: Given a whole number N, determine if N is odd or even.

  • Algorithm (as stated): If N Mod 2 equals 0, then N is even; otherwise, N is odd.

  • Key idea: parity determined by remainder when divided by 2.

Coins Change Problem (Greedy approach)

  • Goal: For N cents (N < 100), compute the least number of coins using quarters, dimes, nickels, pennies.

  • Example: N = 92

    • Quarters: 3

    • Dimes: 1

    • Nickels: 1

    • Pennies: 2

  • Step-by-step (as shown):

    • Q = floor(N / 25) = floor(92 / 25) = 3

    • R1 = N mod 25 = 92 mod 25 = 17

    • D = floor(R1 / 10) = floor(17 / 10) = 1

    • R2 = R1 mod 10 = 17 mod 10 = 7

    • N = floor(R2 / 5) = floor(7 / 5) = 1

    • P = R2 mod 5 = 7 mod 5 = 2

  • Result: 3 quarters, 1 dime, 1 nickel, 2 pennies.

  • In Visual Logic, this is implemented by integer division () and modulus (Mod) to obtain counts and remainders.

Input Dialog (User input)

  • Demonstrates a user Prompt:

    • Prompt text: "Please type a value for CENTS:" and user types 92.

    • Output shows the breakdown:

    • Quarters: 3

    • Dimes: 1

    • Nickels: 1

    • Pennies: 2

  • This illustrates how inputs are read and then used in calculations to update outputs.

Variable Watch Demo (Trace variables during execution)

  • Example variables for the change-making program:

    • CENTS: 92

    • QUARTERS: 3

    • LEFT_Q: 17

    • DIMES: 1

    • LEFT_D: 7

    • NICKELS: 1

    • LEFT_N: 2

  • Structure shown in Visual Logic:

    • Begin

    • Input: Cents

    • Quarters = Cents \ 25

    • Left_Q = Cents Mod 25

    • Dimes = Left_Q \ 10

    • LeftD = LeftQ Mod 10

    • Nickels = Left_D \ 5

    • Left N = Left_D Mod 5

    • Output: concatenated strings to display the breakdown

    • End

Intrinsic Functions in Visual Logic

  • A list of built-in functions and their example outputs:

    • FormatCurrency(12345) => $12,345.00

    • FormatCurrency(0.02) => $0.02

    • FormatPercent(0.0625) => 6.25%

    • FormatPercent(0.75) => 75.00%

    • Abs(-3.3) => 3.3

    • Abs(5.67) => 5.67

    • Int(3.8) => 3

    • Int(7.1) => 7

    • Round(3.8) => 4

    • Round(7.1) => 7

    • Random(5) => an integer between 0 and 4

  • These functions format numbers for display, convert types, and generate random values.

Correct Programming Formats (Table 1-1 concepts)

  • Value vs. Written Format vs. Programming Format vs. Comment

  • Strings:

    • Written: Hello World

    • Programming: "Hello World" (strings delimited by quotes)

  • Percent:

    • Written: 15%

    • Programming: 0.15

    • Comment: Use decimal format

  • Dollars:

    • Written: $300

    • Programming: 300

    • Comment: Dollar signs are not allowed in literal numbers

  • Large Numbers:

    • Written: 12,345,678

    • Programming: 12345678

    • Comment: Commas not allowed in numeric literals

Output Statement Summary (Visual Logic)

  • Output statements display information using a parallelogram shape labeled Output.

  • Behavior:

    • String literals (e.g., " Dave" or "Quarters ") are displayed exactly as written inside quotes.

    • Expressions are evaluated and the resulting value is displayed.

  • Concatenation:

    • The ampersand operator & is used to concatenate a sequence of strings, variables, and expressions into a single output expression.

  • Line breaks:

    • Carriage returns in the output expression appear as carriage returns (new lines) in the displayed output.

Quick Practical Takeaways

  • Distinguish between / (true division) and \ (integer division) and between Mod and regular modulo.

  • Use PEMDAS to evaluate expressions; parentheses can override default precedence.

  • For currency and percentage outputs, rely on intrinsic functions (FormatCurrency, FormatPercent).

  • When prompting for input, reflect user input in subsequent computations and outputs.

  • Use the Output statement with concatenation to format multi-part results on one line or across lines.

Note on transcription accuracy: Some lines in the provided transcript appear garbled or inconsistent (e.g., mixed results for (2*3)^2 and A values). The notes above reflect standard interpretations of Visual Logic syntax and the clearly legible items. If you have the original source, use it to confirm those ambiguous items and adjust the examples accordingly.