Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "std_lib_facilities.h"
- class student {
- private:
- int mnr;
- public:
- student(int);
- void print(void);
- };
- student::student(int mnr) { this->mnr = mnr;}
- void student::print(void) { cout <<mnr<<endl;}
- class group {
- private:
- int size;
- vector<student> participants;
- public:
- group(void);
- group(student);
- void addStudent(student);
- void listAll();
- int getSize();
- friend group operator+ (group a, group b); };
- group::group(void) {}
- group::group(student stud) {participants.push_back(stud);}
- void group::addStudent(student stud) {participants.push_back(stud);}
- void group::listAll()
- {
- if(getSize()==0) {throw length_error( "vector is empty");}
- else {
- for( auto i : participants)
- {cout << i<<endl; }
- }
- }
- int group::getSize() { return participants.size(); }
- group operator+(group a, group b)
- {
- group ab();
- ab.reserve( a.size(), b.size());
- ab.insert(ab.begin(), a.begin(), a.end());
- ab.insert(ab.end(), b.begin(), b.end());
- return ab;
- }
- int main() {
- group a(student(1234567)), b(student(7654321));
- group myGroup = a + b;
- try {
- myGroup.listAll();
- } catch (string error) {
- cerr << error << endl; }
- return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement