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
|
#include <iostream>
#include <string>
using namespace std;
//Global variable
int arraySize = 0;
class member
{
public:
//default constructor
member()
{
}
//constructor
member(string firstNamec, string surNamec, char genderc, int memberNoc)
{
firstName = firstNamec;
surName = surNamec;
gender = genderc;
memberNo = memberNoc;
}
//destructor
/*
~member()
{
delete firstName;
delete surName;
delete gender;
delete memberNo;
}
*/
//edit name
void edit_name(string newFirstname, string newSurname)
{
firstName = newFirstname;
surName = newSurname;
}
//edit gender
void edit_gender(char newgender)
{
gender = newgender;
}
//edit memberNo
void edit_memberNo(int newmemberno)
{
memberNo = newmemberno;
}
//friend functions
//friend void show_data(member*&); //*******************temporarily sommented out
private:
string firstName;
string surName;
char gender;
int memberNo;
};
void create_member(string firstName, string surName, char gender, int memberNo, member*& memberA)
{
member* tempArray;
tempArray = new member[arraySize+1];
for(int i = arraySize-1; i >= 0; i--)
{
tempArray[i] = memberA[i];
}
delete [] memberA;
cout << arraySize << endl;
tempArray[arraySize] = member(firstName, surName, gender, memberNo);
memberA = tempArray;
arraySize++;
}
int main ()
{
//Create and initialise the array
//Note: We create an array of 1 in this case using the default constructor
member *pmem = new member[1];
pmem[0] = member();
// Add a few members
create_member("Andy","St.Clair",'M', 220,pmem);
create_member("Jean","Simmons",'F', 221,pmem);
create_member("Paul","Jones",'M', 222,pmem);
delete []pmem;
return 0;
}
|