Episode 7 — DSA with JavaScript / 7.4 — Object Oriented Programming

7.4 — Exercise Questions: OOP in JavaScript

<< Overview


Easy

E1. Create a Student class

Properties: name, grade, scores array. Methods: addScore, getAverage.

Solution (JS)
class Student {
    constructor(name, grade) {
        this.name = name;
        this.grade = grade;
        this.scores = [];
    }
    addScore(score) { this.scores.push(score); }
    getAverage() {
        if (this.scores.length === 0) return 0;
        return this.scores.reduce((a, b) => a + b, 0) / this.scores.length;
    }
}
const s = new Student("Alice", 10);
s.addScore(90); s.addScore(85);
console.log(s.getAverage());  // 87.5
Solution (C++)
#include <vector>
#include <string>
#include <numeric>
using namespace std;

class Student {
public:
    string name;
    int grade;
    vector<int> scores;
    Student(const string& n, int g) : name(n), grade(g) {}
    void addScore(int s) { scores.push_back(s); }
    double getAverage() const {
        if (scores.empty()) return 0;
        return (double)accumulate(scores.begin(), scores.end(), 0) / scores.size();
    }
};

E2. Implement a Counter class with method chaining

Solution (JS)
class Counter {
    #count = 0;
    increment() { this.#count++; return this; }
    decrement() { this.#count--; return this; }
    getValue() { return this.#count; }
}
const c = new Counter();
console.log(c.increment().increment().decrement().getValue());  // 1

E3. Create an Animal hierarchy with Dog and Cat

Solution (JS)
class Animal {
    constructor(name) { this.name = name; }
    speak() { return `${this.name} makes a sound`; }
}
class Dog extends Animal {
    speak() { return `${this.name} barks!`; }
}
class Cat extends Animal {
    speak() { return `${this.name} meows!`; }
}
[new Dog("Rex"), new Cat("Whiskers")].forEach(a => console.log(a.speak()));

E4. Implement a BankAccount with private balance

Solution (JS)
class BankAccount {
    #balance;
    constructor(initial) { this.#balance = initial; }
    deposit(amt) {
        if (amt <= 0) throw new Error("Positive amount required");
        this.#balance += amt;
    }
    withdraw(amt) {
        if (amt > this.#balance) throw new Error("Insufficient funds");
        this.#balance -= amt;
    }
    getBalance() { return this.#balance; }
}

E5. Create a Stack class using OOP

Solution (JS)
class Stack {
    #items = [];
    push(val) { this.#items.push(val); }
    pop() {
        if (this.isEmpty()) throw new Error("Stack underflow");
        return this.#items.pop();
    }
    peek() { return this.#items[this.#items.length - 1]; }
    isEmpty() { return this.#items.length === 0; }
    size() { return this.#items.length; }
}
Solution (C++)
#include <vector>
#include <stdexcept>
using namespace std;

class Stack {
    vector<int> items;
public:
    void push(int val) { items.push_back(val); }
    int pop() {
        if (isEmpty()) throw runtime_error("Stack underflow");
        int val = items.back();
        items.pop_back();
        return val;
    }
    int peek() const { return items.back(); }
    bool isEmpty() const { return items.empty(); }
    int size() const { return items.size(); }
};

Medium

E6. Implement a Shape hierarchy with area() polymorphism

Solution (JS)
class Shape {
    area() { throw new Error("Implement area()"); }
}
class Circle extends Shape {
    constructor(r) { super(); this.r = r; }
    area() { return Math.PI * this.r ** 2; }
}
class Rectangle extends Shape {
    constructor(w, h) { super(); this.w = w; this.h = h; }
    area() { return this.w * this.h; }
}
class Triangle extends Shape {
    constructor(b, h) { super(); this.b = b; this.h = h; }
    area() { return 0.5 * this.b * this.h; }
}

E7. Build an EventEmitter class

Solution (JS)
class EventEmitter {
    #events = {};
    on(event, fn) { (this.#events[event] ??= []).push(fn); }
    emit(event, ...args) {
        (this.#events[event] ?? []).forEach(fn => fn(...args));
    }
    off(event, fn) {
        this.#events[event] = (this.#events[event] ?? []).filter(f => f !== fn);
    }
}

E8. Implement a LinkedList class with add, remove, find

Solution (JS)
class ListNode {
    constructor(val, next = null) { this.val = val; this.next = next; }
}
class LinkedList {
    #head = null;
    #size = 0;

    addFirst(val) { this.#head = new ListNode(val, this.#head); this.#size++; }
    addLast(val) {
        if (!this.#head) { this.addFirst(val); return; }
        let curr = this.#head;
        while (curr.next) curr = curr.next;
        curr.next = new ListNode(val);
        this.#size++;
    }
    find(val) {
        let curr = this.#head;
        while (curr) { if (curr.val === val) return curr; curr = curr.next; }
        return null;
    }
    remove(val) {
        if (!this.#head) return false;
        if (this.#head.val === val) { this.#head = this.#head.next; this.#size--; return true; }
        let curr = this.#head;
        while (curr.next) {
            if (curr.next.val === val) { curr.next = curr.next.next; this.#size--; return true; }
            curr = curr.next;
        }
        return false;
    }
    getSize() { return this.#size; }
}

E9. Create a QueryBuilder with method chaining

Solution (JS)
class QueryBuilder {
    #table; #wheres = []; #orderBy = null; #limitVal = null;
    from(t) { this.#table = t; return this; }
    where(cond) { this.#wheres.push(cond); return this; }
    order(col) { this.#orderBy = col; return this; }
    limit(n) { this.#limitVal = n; return this; }
    build() {
        let q = `SELECT * FROM ${this.#table}`;
        if (this.#wheres.length) q += ` WHERE ${this.#wheres.join(" AND ")}`;
        if (this.#orderBy) q += ` ORDER BY ${this.#orderBy}`;
        if (this.#limitVal) q += ` LIMIT ${this.#limitVal}`;
        return q;
    }
}

E10. Implement a Validator class with composable rules

Solution (JS)
class Validator {
    #rules = [];
    required() { this.#rules.push(v => v !== null && v !== undefined && v !== ""); return this; }
    minLength(n) { this.#rules.push(v => v.length >= n); return this; }
    maxLength(n) { this.#rules.push(v => v.length <= n); return this; }
    matches(re) { this.#rules.push(v => re.test(v)); return this; }
    validate(value) { return this.#rules.every(rule => rule(value)); }
}

const v = new Validator().required().minLength(3).maxLength(20);
console.log(v.validate("hello"));  // true
console.log(v.validate("hi"));     // false (too short)

Hard

E11. Implement the Observer pattern

Create a Subject class that notifies Observer objects on state changes.

Solution (JS)
class Subject {
    #observers = [];
    #state;
    subscribe(obs) { this.#observers.push(obs); }
    unsubscribe(obs) { this.#observers = this.#observers.filter(o => o !== obs); }
    setState(s) { this.#state = s; this.#notify(); }
    getState() { return this.#state; }
    #notify() { this.#observers.forEach(o => o.update(this.#state)); }
}
class Observer {
    constructor(name) { this.name = name; }
    update(state) { console.log(`${this.name} received: ${state}`); }
}

E12. Build a Trie (prefix tree) using classes

Solution (JS)
class TrieNode {
    constructor() { this.children = {}; this.isEnd = false; }
}
class Trie {
    constructor() { this.root = new TrieNode(); }
    insert(word) {
        let node = this.root;
        for (const ch of word) {
            if (!node.children[ch]) node.children[ch] = new TrieNode();
            node = node.children[ch];
        }
        node.isEnd = true;
    }
    search(word) {
        let node = this.root;
        for (const ch of word) {
            if (!node.children[ch]) return false;
            node = node.children[ch];
        }
        return node.isEnd;
    }
    startsWith(prefix) {
        let node = this.root;
        for (const ch of prefix) {
            if (!node.children[ch]) return false;
            node = node.children[ch];
        }
        return true;
    }
}

E13. Implement a simple Pub/Sub system

Solution (JS)
class PubSub {
    #topics = {};
    subscribe(topic, fn) {
        (this.#topics[topic] ??= []).push(fn);
        return () => { this.#topics[topic] = this.#topics[topic].filter(f => f !== fn); };
    }
    publish(topic, data) {
        (this.#topics[topic] ?? []).forEach(fn => fn(data));
    }
}

Additional exercise bank

EX-014

  • Problem: OOP exercise #14 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-015

  • Problem: OOP exercise #15 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-016

  • Problem: OOP exercise #16 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-017

  • Problem: OOP exercise #17 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-018

  • Problem: OOP exercise #18 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-019

  • Problem: OOP exercise #19 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-020

  • Problem: OOP exercise #20 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-021

  • Problem: OOP exercise #21 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-022

  • Problem: OOP exercise #22 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-023

  • Problem: OOP exercise #23 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-024

  • Problem: OOP exercise #24 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-025

  • Problem: OOP exercise #25 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-026

  • Problem: OOP exercise #26 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-027

  • Problem: OOP exercise #27 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-028

  • Problem: OOP exercise #28 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-029

  • Problem: OOP exercise #29 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-030

  • Problem: OOP exercise #30 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-031

  • Problem: OOP exercise #31 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-032

  • Problem: OOP exercise #32 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-033

  • Problem: OOP exercise #33 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-034

  • Problem: OOP exercise #34 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-035

  • Problem: OOP exercise #35 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-036

  • Problem: OOP exercise #36 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-037

  • Problem: OOP exercise #37 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-038

  • Problem: OOP exercise #38 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-039

  • Problem: OOP exercise #39 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-040

  • Problem: OOP exercise #40 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-041

  • Problem: OOP exercise #41 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-042

  • Problem: OOP exercise #42 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-043

  • Problem: OOP exercise #43 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-044

  • Problem: OOP exercise #44 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-045

  • Problem: OOP exercise #45 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-046

  • Problem: OOP exercise #46 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-047

  • Problem: OOP exercise #47 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-048

  • Problem: OOP exercise #48 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-049

  • Problem: OOP exercise #49 — design and implement a class-based solution.
  • Difficulty: Easy
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-050

  • Problem: OOP exercise #50 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-051

  • Problem: OOP exercise #51 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-052

  • Problem: OOP exercise #52 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-053

  • Problem: OOP exercise #53 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-054

  • Problem: OOP exercise #54 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-055

  • Problem: OOP exercise #55 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-056

  • Problem: OOP exercise #56 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-057

  • Problem: OOP exercise #57 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-058

  • Problem: OOP exercise #58 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-059

  • Problem: OOP exercise #59 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-060

  • Problem: OOP exercise #60 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-061

  • Problem: OOP exercise #61 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-062

  • Problem: OOP exercise #62 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-063

  • Problem: OOP exercise #63 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-064

  • Problem: OOP exercise #64 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-065

  • Problem: OOP exercise #65 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-066

  • Problem: OOP exercise #66 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-067

  • Problem: OOP exercise #67 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-068

  • Problem: OOP exercise #68 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-069

  • Problem: OOP exercise #69 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-070

  • Problem: OOP exercise #70 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-071

  • Problem: OOP exercise #71 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-072

  • Problem: OOP exercise #72 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-073

  • Problem: OOP exercise #73 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-074

  • Problem: OOP exercise #74 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-075

  • Problem: OOP exercise #75 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-076

  • Problem: OOP exercise #76 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-077

  • Problem: OOP exercise #77 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-078

  • Problem: OOP exercise #78 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-079

  • Problem: OOP exercise #79 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-080

  • Problem: OOP exercise #80 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-081

  • Problem: OOP exercise #81 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-082

  • Problem: OOP exercise #82 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-083

  • Problem: OOP exercise #83 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-084

  • Problem: OOP exercise #84 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-085

  • Problem: OOP exercise #85 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-086

  • Problem: OOP exercise #86 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-087

  • Problem: OOP exercise #87 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-088

  • Problem: OOP exercise #88 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-089

  • Problem: OOP exercise #89 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-090

  • Problem: OOP exercise #90 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-091

  • Problem: OOP exercise #91 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-092

  • Problem: OOP exercise #92 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-093

  • Problem: OOP exercise #93 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-094

  • Problem: OOP exercise #94 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-095

  • Problem: OOP exercise #95 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-096

  • Problem: OOP exercise #96 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-097

  • Problem: OOP exercise #97 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-098

  • Problem: OOP exercise #98 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-099

  • Problem: OOP exercise #99 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-100

  • Problem: OOP exercise #100 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-101

  • Problem: OOP exercise #101 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-102

  • Problem: OOP exercise #102 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-103

  • Problem: OOP exercise #103 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-104

  • Problem: OOP exercise #104 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-105

  • Problem: OOP exercise #105 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-106

  • Problem: OOP exercise #106 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-107

  • Problem: OOP exercise #107 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-108

  • Problem: OOP exercise #108 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-109

  • Problem: OOP exercise #109 — design and implement a class-based solution.
  • Difficulty: Medium
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-110

  • Problem: OOP exercise #110 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-111

  • Problem: OOP exercise #111 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-112

  • Problem: OOP exercise #112 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-113

  • Problem: OOP exercise #113 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-114

  • Problem: OOP exercise #114 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-115

  • Problem: OOP exercise #115 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-116

  • Problem: OOP exercise #116 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-117

  • Problem: OOP exercise #117 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-118

  • Problem: OOP exercise #118 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-119

  • Problem: OOP exercise #119 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-120

  • Problem: OOP exercise #120 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-121

  • Problem: OOP exercise #121 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-122

  • Problem: OOP exercise #122 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-123

  • Problem: OOP exercise #123 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-124

  • Problem: OOP exercise #124 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-125

  • Problem: OOP exercise #125 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-126

  • Problem: OOP exercise #126 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-127

  • Problem: OOP exercise #127 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-128

  • Problem: OOP exercise #128 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-129

  • Problem: OOP exercise #129 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-130

  • Problem: OOP exercise #130 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-131

  • Problem: OOP exercise #131 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-132

  • Problem: OOP exercise #132 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-133

  • Problem: OOP exercise #133 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-134

  • Problem: OOP exercise #134 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-135

  • Problem: OOP exercise #135 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-136

  • Problem: OOP exercise #136 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-137

  • Problem: OOP exercise #137 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-138

  • Problem: OOP exercise #138 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-139

  • Problem: OOP exercise #139 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-140

  • Problem: OOP exercise #140 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-141

  • Problem: OOP exercise #141 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-142

  • Problem: OOP exercise #142 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-143

  • Problem: OOP exercise #143 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-144

  • Problem: OOP exercise #144 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-145

  • Problem: OOP exercise #145 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-146

  • Problem: OOP exercise #146 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-147

  • Problem: OOP exercise #147 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-148

  • Problem: OOP exercise #148 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-149

  • Problem: OOP exercise #149 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-150

  • Problem: OOP exercise #150 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-151

  • Problem: OOP exercise #151 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-152

  • Problem: OOP exercise #152 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-153

  • Problem: OOP exercise #153 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-154

  • Problem: OOP exercise #154 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-155

  • Problem: OOP exercise #155 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-156

  • Problem: OOP exercise #156 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-157

  • Problem: OOP exercise #157 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-158

  • Problem: OOP exercise #158 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-159

  • Problem: OOP exercise #159 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-160

  • Problem: OOP exercise #160 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-161

  • Problem: OOP exercise #161 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-162

  • Problem: OOP exercise #162 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.

EX-163

  • Problem: OOP exercise #163 — design and implement a class-based solution.
  • Difficulty: Hard
  • Skills: Classes, inheritance, encapsulation, polymorphism, design patterns.
  • Implementation: Both JavaScript and C++.