Build a Shape Area Overloader

Hard Polymorphism & Function Overloading PRO
🔒 Login to Unlock

Problem Statement

Combine the concepts! Create an `AreaCalc` class that overloads a `calculateArea` method three ways: `calculateArea(int side)` for a Square, `calculateArea(int length, int width)` for a Rectangle, and `calculateArea(double radius)` for a Circle (assume PI = 3.14). Read `s`, `l`, `w`, and `r` from input. Call all three overloads and print the results.

Input Format

Four space-separated numbers: int s, int l, int w, double r.

Output Format

Print Square, Rectangle, and Circle areas on separate lines.

Constraints

None

Sample Input

5 4 6 2.5

Sample Output

Square: 25
Rectangle: 24
Circle: 19.625

Explanation

A complete demonstration of leveraging compile-time polymorphism to handle varied contextual logic through an identical interface name.

Starter Code

#include <iostream>

class AreaCalc {
public:
    // Implement all three calculateArea methods here
};

int main() {
    // Read input, process calculations, and print
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used