Fraction

Medium Classes & Objects
Solve in Playground →

Problem Statement

Write a C++ program defining a `Fraction` class to multiply two fractions, then simplify and display the result.

Input Format

Numerator1, Denominator1, Numerator2, and Denominator2.

Output Format

Print simplified product fraction as num/den.

Constraints

Denominators != 0

Sample Input

1 2 2 3

Sample Output

Product: 1/3

Explanation

Demonstrates math GCD simplification applied to class objects.

Starter Code

#include <iostream>

class Fraction {
public:
    int num;
    int den;
    
    int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }
    
    void multiplyAndDisplay(Fraction f1, Fraction f2) {
        // Write your code here
    }
};

int main() {
    Fraction f1, f2, res;
    if (std::cin >> f1.num >> f1.den >> f2.num >> f2.den) {
        res.multiplyAndDisplay(f1, f2);
    }
    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