Bidirectional Association

Hard Composition & Aggregation PRO
🔒 Login to Unlock

Problem Statement

Create `Author` and `Book` classes. Because they reference each other, use a forward declaration (`class Book;`). When `Author::write(Book* b)` is called, it sets `this->book = b` AND `b->author = this`. It prints ‘[Author] wrote [Book]’ and then on a new line ‘[Book] written by [Author]’ by accessing the properties recursively from the `Book` object.

Input Format

Two strings: Author name then Book title.

Output Format

Print the bidirectional link messages on two lines.

Constraints

No spaces in strings.

Sample Input

Tolkien Hobbit

Sample Output

Tolkien wrote Hobbit
Hobbit written by Tolkien

Explanation

In a bidirectional association, both objects maintain a pointer reference to each other, requiring careful forward declarations in C++.

Starter Code

#include <iostream>
#include <string>

class Book; // Forward declaration

class Author {
public:
    // Write your code here
};

class Book {
public:
    // Write your code here
};

// Implement Author::write here

int main() {
    // Establish bidirectional link 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