Overloading Type Conversions

Medium Polymorphism & Function Overloading PRO
🔒 Login to Unlock

Problem Statement

Create a `Distance` class with an integer `meters`. Overload the `float()` typecast operator to return the distance in kilometers (`meters / 1000.0f`). Read an integer, instantiate the object, explicitly cast it to float, and print the resulting float.

Input Format

A single integer.

Output Format

Print the distance in kilometers.

Constraints

None

Sample Input

1500

Sample Output

1.5

Explanation

Type conversion overloading `operator float()` allows custom objects to seamlessly cast themselves to basic primitive types.

Starter Code

#include <iostream>

class Distance {
public:
    int meters;
    Distance(int m) : meters(m) {}
    
    // Write your type conversion overload here
};

int main() {
    // Read input, instantiate, cast to float, 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