01
02
03
04
05
06
07
08
09
10
11
A
A2Z Sheet

4. Switch Case & The Geometry Dispatcher

Easy
Step 1: Learn the basics›Things to Know in C++/Java/Python or any language

Switch Case & The Geometry Dispatcher

EasyFunction: switchCase()
ASCI Mission Breakdown • Simple as Hell
"Dispatch calculation to Circle Area or Rectangle Area based on the choice code."
Real-World Metaphor:

Imagine a coffee vending machine. Button 1 brews an Espresso (uses 1 bean measure), while Button 2 mixes a Cappuccino (uses coffee plus milk). Depending on the button pressed, the machine routes to a specific dispenser.

Interactive Visual WalkthroughFLOW-DIAGRAM
Step 1 / 3
Choice1
ShapeCircle
Radius5
Evaluating

1. Read Choice Code

Received choice = 1 with radius r = 5.

How to Think About This (Mental Model)

  1. Inspect choice parameter (1 or 2).
  2. If choice === 1: extract radius r, compute Math.PI * r * r.
  3. If choice === 2: extract length l and breadth b, compute l * b.
  4. Return the resulting area.

### The Mission You are writing software for an automated drafting plotter. The user sends a choice code indicating which geometric figure they want calculated: - Choice **1**: Calculate the area of a **Circle** given its radius `r`: Area = `π * r * r`. - Choice **2**: Calculate the area of a **Rectangle** given length `l` and breadth `b`: Area = `l * b`. Return the exact calculated area for the requested figure.

Examples

Example 1
Input: x = 10, y = 20
Output: 30
Explanation: Returns the processed result of the inputs.

Constraints

  • -10^5 <= x, y <= 10^5
Topic Tags:
Learn the basicsThings to Know in C++/Java/Python or any languageswitchCase
14px
Ln 1:Col 1
9 lines•128 chars
Spaces: 2•UTF-8
JS(Node v20.12)