/**
 *   Løsning til eksamen i OOProg (i C++), mai 2026, oppgave 1A.
 *
 *   @file     EX_V26_1A.CPP
 *   @author   Frode Haug, NTNU
 */


#include <iostream>
#include <string>
#include <map>
using namespace std;


class A  {
  protected:
    map <string, int> data;

  public:
    A()  {  }

    void funk1(const string t, const int n)  {  data[t] = n;  }

    bool funk2(const string t) { return (data.find(t) != data.end()); }

    virtual int funk3()  {  return data.size(); }

    virtual void funk4()  {
      for (const auto & val : data)
          cout << ' ' << val.second << '-' << val.first;
      cout << '\n';
    }

    bool funk5(const string t)  {
      if (data.find(t) != data.end())  {
         data.erase(t);
         return true;
      } else
         return false;
    }

    void funk6(const int n)  {
      auto it = data.begin();
      while (it != data.end())  {
        if ((*it).second > n) cout << it->first << ' ';
        it++;
      }
    }
};


class B : public A {
  private:
    string txt;

  public:
    B(const string t)  {  txt = t;  }

    int funk3()  {  return txt.length(); }

    void funk4()  {
      cout << txt << ':';
      A::funk4();
    }
};


int main() {
  A* aa = new A;
  B* bb = new B("Reidar");

  bb->funk1("Bukse", 8);   bb->funk1("Sokker", 20);   bb->funk1("Genser", 12);
  bb->funk4();

  cout << (*bb).funk2("Sokker") << ' ' << bb->funk2("Bukser") << ' '
       << aa->funk2("Genser") << '\n';

  cout << aa->funk3() << ' ' << bb->funk3() << '\n';

  bb->funk1("Jakke", 2);  bb->funk1("Sko", 6);  bb->funk1("Boxer", 12);
  bb->funk5("Bukse");     bb->funk5("Sokker");  bb->funk5("Skjorte");
  bb->funk4();

  bb->funk6(6);    cout << '\n';

  return 0;
}




//  Utskrift:  Reidar: 8-Bukse 12-Genser 20-Sokker
//             1 0 0
//             0 6
//             Reidar: 12-Boxer 12-Genser 2-Jakke 6-Sko
//             Boxer Genser
