Bird
0
0

You are writing a PowerShell script to calculate both the area and perimeter of a rectangle. How should you use functions to make your script more maintainable?

hard📝 Application Q8 of 15
PowerShell - Functions
You are writing a PowerShell script to calculate both the area and perimeter of a rectangle. How should you use functions to make your script more maintainable?
AUse one function that calculates area and perimeter but returns only the area
BWrite all calculations in the main script body without functions
CCreate separate functions for area and perimeter calculations and call them as needed
DDefine functions but avoid passing parameters to keep it simple
Step-by-Step Solution
Solution:
  1. Step 1: Understand maintainability

    Maintainable scripts separate concerns and reuse code.
  2. Step 2: Evaluate options

    Create separate functions for area and perimeter calculations and call them as needed correctly suggests separate functions for each calculation, improving clarity and reuse.
  3. Final Answer:

    Create separate functions for area and perimeter calculations and call them as needed -> Option C
  4. Quick Check:

    Separate functions improve clarity and reuse [OK]
Quick Trick: Use distinct functions for distinct calculations [OK]
Common Mistakes:
  • Putting all logic in the main script body
  • Returning only partial results from combined functions
  • Avoiding parameters, which reduces flexibility

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes