Reusability and maintenance
📖 Scenario: You are working on a small program that calculates the area of different shapes. To keep your code clean and easy to maintain, you want to reuse the area calculation logic by putting it inside functions.
🎯 Goal: Create reusable functions to calculate the area of a rectangle and a circle, then use these functions to print the areas for given dimensions.
📋 What You'll Learn
Create a function called
rectangle_area that takes two double parameters length and width and returns their product as double.Create a function called
circle_area that takes one double parameter radius and returns the area of the circle using the formula 3.14159 * radius * radius.In
main, declare variables rect_length and rect_width with values 5.0 and 3.0 respectively.In
main, declare a variable circle_radius with value 2.0.Call the functions
rectangle_area and circle_area with the declared variables and print the results with descriptive text.💡 Why This Matters
🌍 Real World
Reusable functions are used in real software to avoid repeating code and to make programs easier to update and fix.
💼 Career
Understanding how to write and use functions is essential for any programming job, as it improves code quality and teamwork.
Progress0 / 4 steps