Implementation of the aaaa Project
// Date. h file
# Ifndef _ Date_H
# Define _ Date_H
Class Date
{
Public:
Date ();
Date (int year, int month, int day );
Void print () const;
Private:
Int _ year;
Int _ month;
Int _ day;
};
# Endif
// Date. cpp File
# Include "stdafx. h"
# Include "Date. h"
# Include "process. h"
Date: Date (){
}
Date: Date (int year, int month, int day ){
_ Year = year;
_ Month = month;
_ Day = day;
}
Void Date: print () const {
Printf ("Date of Birth: % d-% d", _ year, _ month, _ day );
}
// Person. h
# Include "Date. h"
# Ifndef _ Person_H
# Define _ Person_H
Class Person {
Public:
Person ();
Person (char * name, char * email_address, int year, int month, int day );
Public:
Char * get_Name () const;
Char * get_email_address () const;
Date getBirthDate () const;
Void print () const;
Private:
Char * _ name;
Char * _ email_address;
Date date;
};
# Endif
// Person. cpp File
# Include "stdafx. h"
# Include "Person. h"
# Include "Date. h"
Person: Person (){
}
Person: Person (char * name, char * email_address, int year, int month, int day)
: Date (year, month, day ){
_ Name = name;
_ Email_address = email_address;
}
Char * Person: get_Name () const {
Return _ name;
}
Char * Person: get_email_address () const {
Return _ email_address;
}
Date Person: getBirthDate () const {
Return date;
}
Void Person: print () const {
Printf ("name: % s, email: % s", _ name, _ email_address );
Printf (",");
Date. print ();
}
// PersonSet. h file
# Ifndef _ PersonSet_H
# Define _ PersonSet_H
# Include "Person. h"
Class PersonSet {
Public:
PersonSet (int initial_size );
~ PersonSet ();
Public:
Void add (Person & element );
Person & nextElement ();
Person & removeElement ();
Person & removeElement (int index );
Int size ();
Void print ();
Void reset ();
Private:
Person ** _ elements;
Int _ capacity;
Int _ size;
Int _ index;
};
# Endif
// PersonSet. cpp File
# Include "stdafx. h"
# Include "PersonSet. h"
# Include "Person. h"
# Include "Date. h"
PersonSet: PersonSet (int I _size ){
_ Size = 0;
_ Capacity = I _size;
_ Index = 1;
_ Elements = new Person * [_ capacity];
}
PersonSet ::~ PersonSet (){
Delete [] _ elements;
}
Void PersonSet: add (Person & element ){
If (_ size = _ capacity ){
Person ** temp = _ elements;
_ Elements = new Person * [_ capacity * 2];
For (int I = 0; I <_ size; I ++ ){
_ Elements [I] = temp [I];
}
_ Capacity * = 2;
Delete [] temp;
}
_ Elements [_ size ++] = & element;
_ Index = _ size;
}
Person & PersonSet: nextElement (){
Return * (_ elements [(_ index) ++]);
}
Person & PersonSet: removeElement (){
_ Size --;
Person * p = _ elements [_ size];
If (_ size <_ capacity/2 ){
Person ** temp = _ elements;
_ Elements = new Person * [_ capacity/2];
For (int I = 0; I <_ size; I ++ ){
_ Elements [I] = temp [I];
}
_ Capacity/= 2;
Delete [] temp;
}
Return * p;
}
Person & PersonSet: removeElement (int index ){
_ Size --;
Person * p = _ elements [index];
If (_ size <_ capacity/2 ){
Person ** temp = _ elements;
_ Elements = new Person * [_ capacity/2];
For (int I = 0; I <_ size; I ++ ){
_ Elements [I] = temp [I];
}
_ Capacity/= 2;
Delete [] temp;
}
Return * p;
}
Int PersonSet: size (){
Return _ size;
}
Void PersonSet: print (){
For (int I = 0; I <_ size; I ++ ){
// Printf ("% s \ n", (* _ elements [I]). get_Name (), (* _ elements [I]). get_email_address ());
(* _ Elements [I]). print ();
Printf ("\ n ");
}
}
Void PersonSet: reset (){
_ Index = 0;
}
From asdfqwer1314