Aggregation: "Has-a" Relationship

Easy Composition & Aggregation
Solve in Playground →

Problem Statement

Implement a `Player` class and a `Team` class. The `Team` class takes an existing `Player` pointer via a method `addPlayer(Player* p)`. Read a player name and team name, instantiate them separately, link them using the method, and print ‘[player] joined [team]’.

Input Format

Two strings: Player name then Team name.

Output Format

Print the formatted joining message.

Constraints

No spaces in names.

Sample Input

Alice Warriors

Sample Output

Alice joined Warriors

Explanation

Aggregation represents a weak 'has-a' relationship where the child object can exist independently of the parent, utilizing pointers.

Starter Code

#include <iostream>
#include <string>

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

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

int main() {
    // Create objects, use aggregation, 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