1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include "group.h"
/*
class Group
{
public:
Group(); // default constructor
Group(const char *groupName, int groupSize, int specialNeeds, int promo); // constructor with parameters
Group(const Group& aGroup); // copy constructor
~Group(); // destructor
// accessor functions
const char *getGroupName() const;
void getGroupName(char *groupName) const;
int getGroupSize() const;
int getSpecialNeeds() const;
int getPromo() const;
// mutator functions
void setGroupName(const char *groupName);
void setGroupSize(int groupSize);
void setSpecialNeeds(int specialNeeds);
void setPromo(int promo);
// print
void print(ostream& out)const;
// operator functions
const Group& operator=(const Group &g);
friend ostream& operator<<(ostream& out, const Group& g);
private:
char *groupName;
int groupSize;
int specialNeeds;
int promo;
void init(const char *groupName, int groupSize, int specialNeeds, int promo); // initializer
};
bool operator==(const Group &g1, const Group &g2);
*/
Group::Group() // default constructor
{
groupName = nullptr;
groupSize = 0;
specialNeeds = 0;
promo = 0;
}
// constructor with parameters
Group::Group(const char *groupName, int groupSize, int specialNeeds, int promo)
{
init(groupName, groupSize, specialNeeds, promo);
}
// copy constructor
Group::Group(const Group& aGroup)
{
init(aGroup.groupName, aGroup.groupSize, aGroup.specialNeeds, aGroup.promo);
}
void Group::init(const char *groupName, int groupSize, int specialNeeds, int promo)
{
this->groupName = new char[strlen(groupName) + 1];
strcpy(this->groupName, groupName);
this->groupSize = groupSize;
this->specialNeeds = specialNeeds;
this->promo = promo;
}
Group::~Group()
{
if (this->groupName)
{
delete[] this->groupName;
}
}
// accessor functions
const char *Group::getGroupName() const
{
return this->groupName;
}
void Group::getGroupName(char *groupName) const
{
strcpy(groupName, this->groupName);
}
// mutator functions
void Group::setGroupName(const char *groupName)
{
if (this->groupName)
{
delete[] this->groupName;
}
this->groupName = new char[strlen(groupName) + 1];
strcpy(this->groupName, groupName);
}
// overload '=' operator
const Group& Group::operator=(const Group& g)
{
if (this == &g)
return *this;
this->setGroupName(g.groupName);
this->setGroupSize(g.groupSize);
this->setSpecialNeeds(g.specialNeeds);
this->setPromo(g.promo);
return *this;
}
bool operator==(const Group &g1, const Group &g2)
{
return strcmp(g1.getGroupName(), g2.getGroupName()) == 0;
}
// overload << operator
ostream& operator<<(ostream &out, const Group &g)
{
g.print(out);
return out;
}
// print using overloaded << operator
void Group::print(ostream& out)const
{
out << this->groupName << ';' << this->groupSize << ';' << this->specialNeeds << ';'
<< this->promo << endl;
}
|