Distance Class

Medium Classes & Objects
Solve in Playground →

Problem Statement

Write a C++ program defining a `Distance` class with feet and inches, adding two distances and printing the normalised result.

Input Format

Feet1, Inches1, Feet2, and Inches2.

Output Format

Print total feet and inches.

Constraints

Feet >= 0, Inches >= 0

Sample Input

5 10 3 8

Sample Output

Total Distance: 9 feet 6 inches

Explanation

Performs object-based addition with compound unit carryovers.

Starter Code

#include <iostream>

class Distance {
public:
    int feet;
    int inches;
    
    void addAndDisplay(Distance d1, Distance d2) {
        // Write your code here
    }
};

int main() {
    Distance d1, d2, result;
    if (std::cin >> d1.feet >> d1.inches >> d2.feet >> d2.inches) {
        result.addAndDisplay(d1, d2);
    }
    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