Advertisement
Guest User

Untitled

a guest
May 30th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <map>
  5. using namespace std;
  6.  
  7.  
  8. class Student
  9. {
  10. public:
  11.     string name;
  12. };
  13. class StudentGroup
  14. {
  15. public:
  16.     map <string, Student*> myMap;
  17.     void insertio(Student *toAdd)
  18.     {
  19.         myMap[toAdd->name] = toAdd;
  20.     };
  21.     void display()
  22.     {
  23.         map<string, Student*>::iterator it;
  24.         for (it = myMap.begin(); it != myMap.end(); it++)
  25.         {
  26.             cout << it->first << "|" << it->second << endl;
  27.         }
  28.     };
  29.     StudentGroup operator*(StudentGroup *input)
  30.     {
  31.         StudentGroup temp;
  32.         map<string, Student*>::iterator iter1, iter2;
  33.         for (iter1 = this->myMap.begin(); iter1 != myMap.end(); iter1++)
  34.         {
  35.             for (iter2 = input->myMap.begin(); iter2 != input->myMap.end(); iter2++)
  36.             {
  37.                 if (iter1->first == iter2->first && iter1->second == iter2->second) // <---- Czy zawsze będzie 1 & 1, albo 0 & 0 ?
  38.                     temp.insertio(iter1->second);
  39.             }
  40.         };
  41.         return temp;
  42.     };
  43. };
  44.  
  45. void main()
  46. {
  47.     Student *a = new Student;
  48.     Student *b = new Student;
  49.     Student *c = new Student;
  50.     Student *d = new Student;
  51.     a->name = "kok";
  52.     b->name = "butt-blocker";
  53.     c->name = "cock";
  54.     d->name = "dick-tator";
  55.     StudentGroup group;
  56.     group.insertio(a);
  57.     group.insertio(b);
  58.     group.display();
  59.  
  60.     StudentGroup *groupOther = new StudentGroup;
  61.     groupOther->insertio(c);
  62.     groupOther->insertio(d);
  63.     groupOther->insertio(a);
  64.     cout << endl;
  65.     groupOther->display();
  66.     cout << endl;
  67.     (group*groupOther).display();
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement