// PersonData.h
#ifndef PersonData_h
#define PersonData_h
#include
#include
#include
using namespace std;
class PersonData {
protected:
//member variables
string lastName; //holds the users last name
string firstName; //holds the users first name
string address; //holds the users address
string city; //holds the users city
string state; //holds the users state
int zip; //holds the users zip code
int phone; //holds the users phone number
public:
//constructors and destructor
PersonData(); //default constructor
PersonData( string ln , string fn , string addr , string c , string s , int z , int p); // overloaded
constructor
~PersonData(){ /*cout << \"The object has been deleted.\" << endl ;*/ } //destructor
//member functions
//returns the users lastName
string getLastName();
//sets the users lastName
void setLastName( string lastN );
//returns the users firstName
string getFirstName();
//sets the users firstName
void setFirstName( string firstN );
//returns the users address
string getAddress();
//sets the users address
void setAddress( string addr );
//returns the users city
string getCity();
//sets the users city
void setCity( string city );
//returns the users state
string getState();
//sets the users state
void setState( string state );
//returns the users zip
int getZip();
//sets the users zip
void setZip( int zip );
//returns the users phone
int getPhone();
//sets the users phone
void setPhone( int phone );
};
#endif /* PersonData_h */
// PersonData.cpp
#include
#include \"PersonData.h\"
using namespace std;
//constructors and destructor
PersonData::PersonData(){
//defining arbitrary values for member variables
string lastName = \"\"; //holds the users last name
string firstName = \"\"; //holds the users first name
string address = \"\"; //holds the users address
string city = \"\"; //holds the users city
string state = \"\"; //holds the users state
int zip = 0; //holds the users zip code
int phone = 0; //holds the users phone number
}//default constructor
PersonData::PersonData( string strln , string name , string stradd , string liveingcity , string
livingstate , int code , int number){
// user defined values for member variables
string lastName = strln; //holds the users last name
string firstName = name; //holds the users first name
string address = stradd; //holds the users address
string city = liveingcity; //holds the users city
string state = livingstate; //holds the users state
int zip = code; //holds the users zip code
int phone = number; //holds the users phone number
}// overloaded constructor
//member functions
//returns the users lastName
string PersonData::getLastName(){
return lastName;
}
//sets the users lastName
void PersonData::setLastName( string lastN ){
lastName = lastN;
}
//returns the users firstName
string PersonData::getFirstName(){
return firstName;
}
//sets the users firstName
void PersonData::setFirstName( string firstN ){
firstName = firstN;
}
//returns the users address
string PersonData::getAddress(){
retur.
1. // PersonData.h
#ifndef PersonData_h
#define PersonData_h
#include
#include
#include
using namespace std;
class PersonData {
protected:
//member variables
string lastName; //holds the users last name
string firstName; //holds the users first name
string address; //holds the users address
string city; //holds the users city
string state; //holds the users state
int zip; //holds the users zip code
int phone; //holds the users phone number
public:
//constructors and destructor
PersonData(); //default constructor
PersonData( string ln , string fn , string addr , string c , string s , int z , int p); // overloaded
constructor
~PersonData(){ /*cout << "The object has been deleted." << endl ;*/ } //destructor
//member functions
//returns the users lastName
string getLastName();
//sets the users lastName
void setLastName( string lastN );
//returns the users firstName
string getFirstName();
//sets the users firstName
void setFirstName( string firstN );
2. //returns the users address
string getAddress();
//sets the users address
void setAddress( string addr );
//returns the users city
string getCity();
//sets the users city
void setCity( string city );
//returns the users state
string getState();
//sets the users state
void setState( string state );
//returns the users zip
int getZip();
//sets the users zip
void setZip( int zip );
//returns the users phone
int getPhone();
//sets the users phone
void setPhone( int phone );
};
#endif /* PersonData_h */
// PersonData.cpp
#include
#include "PersonData.h"
using namespace std;
//constructors and destructor
PersonData::PersonData(){
//defining arbitrary values for member variables
3. string lastName = ""; //holds the users last name
string firstName = ""; //holds the users first name
string address = ""; //holds the users address
string city = ""; //holds the users city
string state = ""; //holds the users state
int zip = 0; //holds the users zip code
int phone = 0; //holds the users phone number
}//default constructor
PersonData::PersonData( string strln , string name , string stradd , string liveingcity , string
livingstate , int code , int number){
// user defined values for member variables
string lastName = strln; //holds the users last name
string firstName = name; //holds the users first name
string address = stradd; //holds the users address
string city = liveingcity; //holds the users city
string state = livingstate; //holds the users state
int zip = code; //holds the users zip code
int phone = number; //holds the users phone number
}// overloaded constructor
//member functions
//returns the users lastName
string PersonData::getLastName(){
return lastName;
}
//sets the users lastName
void PersonData::setLastName( string lastN ){
lastName = lastN;
}
//returns the users firstName
string PersonData::getFirstName(){
return firstName;
}
4. //sets the users firstName
void PersonData::setFirstName( string firstN ){
firstName = firstN;
}
//returns the users address
string PersonData::getAddress(){
return address;
};
//sets the users address
void PersonData::setAddress( string addr ){
address = addr;
}
//returns the users city
string PersonData::getCity(){
return city ;
}
//sets the users city
void PersonData::setCity( string c ){
city = c;
}
//returns the users state
string PersonData::getState(){
return state;
}
//sets the users state
void PersonData::setState( string s ){
state = s;
}
//returns the users zip
int PersonData::getZip(){
return zip;
}
//sets the users zip
void PersonData::setZip( int z ){
zip = z;
}
5. //returns the users phone
int PersonData::getPhone(){
return phone;
}
//sets the users phone
void PersonData::setPhone( int p ){
phone = p;
}
// CustomerData.h
#ifndef CustomerData_h
#define CustomerData_h
#include
#include "PersonData.h"
class CustomerData : public PersonData {
private:
//member variables
int customerNumber; //holds a unique integer ID for each customer
bool mailingList; //holds a bool indicating whether the customer has opted into the mailing
list
public:
//constructors and destructor
//default constructor
CustomerData(){ customerNumber = 0; mailingList = false; }
//overloaded constructor
CustomerData( int cn , bool ml ){ customerNumber = cn ; mailingList = ml; }
//destructor
~CustomerData(){ /*cout << "The object has been deleted." << endl;*/ }
//member functions
//returns the users customerNumber
int getCustomerNumber();
//sets the users customerNumber
6. void setCustomerNumber( int ID );
//returns mailingList
bool getMailingList();
//sets mailingList
void setMailingList( bool list );
//ask if the user wishes to join the list
void displayCustomer();
};
#endif /* CustomerData_h */
// CustomerData.cpp
#include "CustomerData.h"
//returns the users customerNumber
int CustomerData::getCustomerNumber(){
return customerNumber;
}
//sets the users customerNumber
void CustomerData::setCustomerNumber( int ID ){
customerNumber = ID;
}
//returns mailingList
bool CustomerData::getMailingList(){
return mailingList;
}
//sets mailingList
void CustomerData::setMailingList( bool list ){
mailingList = list;
}
//asks if the user wishes to join the mailing list
void CustomerData::displayCustomer(){
cout << "Last Name: " << getLastName() << endl;
cout << "First Name: " << getFirstName() << endl;
cout << "Address: " << getAddress() << endl;
cout << "City: " << getCity() << endl;
8. cout << "------------" << endl;
c2.setLastName("Jones");
c2.setFirstName("Jenny");
c2.setAddress("555 East Street");
c2.setCity("Jonesville");
c2.setState("VA");
c2.setZip(88888);
c2.setPhone(89787887);
c2.setCustomerNumber(77777);
c2.setMailingList(0);
c2.displayCustomer();
return 0;
}
/*
output:
Customer #1
------------
Last Name: Smith
First Name: Joan
Address: 123 Main Street
City: Smithville
State: NC
ZIP Code: 99999
Customer Number: 12345
Mailing List? Yes
Customer #2
------------
Last Name: Jones
First Name: Jenny
Address: 555 East Street
City: Jonesville
State: VA
ZIP Code: 88888
Customer Number: 77777
Mailing List? No
9. */
/*
compilation: g++ main.cpp CustomerData.cpp PersonData.cpp
run: ./a.out
*/
Solution
// PersonData.h
#ifndef PersonData_h
#define PersonData_h
#include
#include
#include
using namespace std;
class PersonData {
protected:
//member variables
string lastName; //holds the users last name
string firstName; //holds the users first name
string address; //holds the users address
string city; //holds the users city
string state; //holds the users state
int zip; //holds the users zip code
int phone; //holds the users phone number
public:
//constructors and destructor
PersonData(); //default constructor
PersonData( string ln , string fn , string addr , string c , string s , int z , int p); // overloaded
constructor
~PersonData(){ /*cout << "The object has been deleted." << endl ;*/ } //destructor
//member functions
//returns the users lastName
10. string getLastName();
//sets the users lastName
void setLastName( string lastN );
//returns the users firstName
string getFirstName();
//sets the users firstName
void setFirstName( string firstN );
//returns the users address
string getAddress();
//sets the users address
void setAddress( string addr );
//returns the users city
string getCity();
//sets the users city
void setCity( string city );
//returns the users state
string getState();
//sets the users state
void setState( string state );
//returns the users zip
int getZip();
//sets the users zip
void setZip( int zip );
//returns the users phone
int getPhone();
//sets the users phone
void setPhone( int phone );
};
#endif /* PersonData_h */
11. // PersonData.cpp
#include
#include "PersonData.h"
using namespace std;
//constructors and destructor
PersonData::PersonData(){
//defining arbitrary values for member variables
string lastName = ""; //holds the users last name
string firstName = ""; //holds the users first name
string address = ""; //holds the users address
string city = ""; //holds the users city
string state = ""; //holds the users state
int zip = 0; //holds the users zip code
int phone = 0; //holds the users phone number
}//default constructor
PersonData::PersonData( string strln , string name , string stradd , string liveingcity , string
livingstate , int code , int number){
// user defined values for member variables
string lastName = strln; //holds the users last name
string firstName = name; //holds the users first name
string address = stradd; //holds the users address
string city = liveingcity; //holds the users city
string state = livingstate; //holds the users state
int zip = code; //holds the users zip code
int phone = number; //holds the users phone number
}// overloaded constructor
//member functions
//returns the users lastName
string PersonData::getLastName(){
return lastName;
}
12. //sets the users lastName
void PersonData::setLastName( string lastN ){
lastName = lastN;
}
//returns the users firstName
string PersonData::getFirstName(){
return firstName;
}
//sets the users firstName
void PersonData::setFirstName( string firstN ){
firstName = firstN;
}
//returns the users address
string PersonData::getAddress(){
return address;
};
//sets the users address
void PersonData::setAddress( string addr ){
address = addr;
}
//returns the users city
string PersonData::getCity(){
return city ;
}
//sets the users city
void PersonData::setCity( string c ){
city = c;
}
//returns the users state
string PersonData::getState(){
return state;
}
//sets the users state
void PersonData::setState( string s ){
state = s;
}
13. //returns the users zip
int PersonData::getZip(){
return zip;
}
//sets the users zip
void PersonData::setZip( int z ){
zip = z;
}
//returns the users phone
int PersonData::getPhone(){
return phone;
}
//sets the users phone
void PersonData::setPhone( int p ){
phone = p;
}
// CustomerData.h
#ifndef CustomerData_h
#define CustomerData_h
#include
#include "PersonData.h"
class CustomerData : public PersonData {
private:
//member variables
int customerNumber; //holds a unique integer ID for each customer
bool mailingList; //holds a bool indicating whether the customer has opted into the mailing
list
public:
//constructors and destructor
//default constructor
CustomerData(){ customerNumber = 0; mailingList = false; }
//overloaded constructor
CustomerData( int cn , bool ml ){ customerNumber = cn ; mailingList = ml; }
//destructor
14. ~CustomerData(){ /*cout << "The object has been deleted." << endl;*/ }
//member functions
//returns the users customerNumber
int getCustomerNumber();
//sets the users customerNumber
void setCustomerNumber( int ID );
//returns mailingList
bool getMailingList();
//sets mailingList
void setMailingList( bool list );
//ask if the user wishes to join the list
void displayCustomer();
};
#endif /* CustomerData_h */
// CustomerData.cpp
#include "CustomerData.h"
//returns the users customerNumber
int CustomerData::getCustomerNumber(){
return customerNumber;
}
//sets the users customerNumber
void CustomerData::setCustomerNumber( int ID ){
customerNumber = ID;
}
//returns mailingList
bool CustomerData::getMailingList(){
return mailingList;
}
//sets mailingList
void CustomerData::setMailingList( bool list ){
mailingList = list;
17. Last Name: Jones
First Name: Jenny
Address: 555 East Street
City: Jonesville
State: VA
ZIP Code: 88888
Customer Number: 77777
Mailing List? No
*/
/*
compilation: g++ main.cpp CustomerData.cpp PersonData.cpp
run: ./a.out
*/