Learning C ++ first project implementation

Source: Internet
Author: User

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;
 
};

# 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 % s \ n", (* _ elements [I]). get_name (), (* _ elements [I]). get_email_address ());
(* _ Elements [I]). Print ();
Printf ("\ n ");
}
}

Void personset: reset (){

_ Index = 0;

}

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.