Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Function Overloading Practice | Some Advanced Topics
C++ Functions

bookChallenge: Function Overloading Practice

Tarea

Swipe to start coding

You are building a geometry calculation tool that can compute the area of different shapes. You will implement function overloading so that the same function name calculateArea can handle rectangles, circles, and triangles.

  1. Rectangle Area Function

    • Declare a function calculateArea that takes two double parameters: length and width.
    • Inside the function, calculate the area by multiplying length by width.
    • Return the calculated area.
  2. Circle Area Function

    • Overload the calculateArea function to take one double parameter: radius.
    • Calculate the area using the formula PI multiplied by radius squared, using the pow function to raise radius to the power of 2.
    • Return the calculated area.
  3. Triangle Area Function

    • Overload the calculateArea function to take three double parameters: a, b, and c.
    • Compute the semi-perimeter s = (a + b + c) / 2.
    • Use Heron's formula: sqrt(s * (s - a) * (s - b) * (s - c)) to calculate the area.
    • Return the calculated area.

Do not modify the value of the PI variable.

Example

calculateArea(4, 6)24 (rectangle)
calculateArea(3)28.27431 (circle)
calculateArea(5, 4, 6)9.92157 (triangle)

Solución

solution.cpp

solution.cpp

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 2
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

Can you explain this in simpler terms?

What are some examples related to this topic?

How does this information apply to real-world situations?

close

Awesome!

Completion rate improved to 5

bookChallenge: Function Overloading Practice

Desliza para mostrar el menú

Tarea

Swipe to start coding

You are building a geometry calculation tool that can compute the area of different shapes. You will implement function overloading so that the same function name calculateArea can handle rectangles, circles, and triangles.

  1. Rectangle Area Function

    • Declare a function calculateArea that takes two double parameters: length and width.
    • Inside the function, calculate the area by multiplying length by width.
    • Return the calculated area.
  2. Circle Area Function

    • Overload the calculateArea function to take one double parameter: radius.
    • Calculate the area using the formula PI multiplied by radius squared, using the pow function to raise radius to the power of 2.
    • Return the calculated area.
  3. Triangle Area Function

    • Overload the calculateArea function to take three double parameters: a, b, and c.
    • Compute the semi-perimeter s = (a + b + c) / 2.
    • Use Heron's formula: sqrt(s * (s - a) * (s - b) * (s - c)) to calculate the area.
    • Return the calculated area.

Do not modify the value of the PI variable.

Example

calculateArea(4, 6)24 (rectangle)
calculateArea(3)28.27431 (circle)
calculateArea(5, 4, 6)9.92157 (triangle)

Solución

solution.cpp

solution.cpp

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 2
single

single

some-alt