In: Computer Science
C++
PersonData and CustomerData classes
Design a class named PersonData with the following member
variables:
lastName
firstName
address
city
state
zip
phone
Write the appropriate accessor and mutator functions for these
member variables. Next, design a class named CustomerData, which is
derived from the PersonData class. The CustomerData class should
have the following member variables:
customerNumber
mailingList
The customerNumber variable will be used to hold a unique integer
for each customer. The mailingList variable should be a bool. It
will be set to true if the customer wishes to be on a mailing list,
or false if the customer does not wish to be on a mail- ing list.
Write appropriate accessor and mutator functions for these member
variables. Demonstrate an object of the CustomerData class in a
simple program.
#include <iostream>
using namespace std;
class PersonData
{
private:
string lastName,firstName, address, city, state,zip, phone;
public:
void setLastName(string lastName)
{
this->lastName = lastName;
}
string getLastName()
{
return lastName;
}
void setFirstName(string firstName)
{
this->firstName = firstName;
}
string getFirstName()
{
return firstName;
}
void setAddress(string address)
{
this->address = address;
}
string getAddress()
{
return address;
}
void setCity(string city)
{
this->city = city;
}
string getCity()
{
return city;
}
void setState(string state)
{
this->state = state;
}
string getState()
{
return state;
}
void setZip(string zip)
{
this->zip = zip;
}
string getZip()
{
return zip;
}
void setPhone(string phone)
{
this->phone = phone;
}
string getPhone()
{
return phone;
}
};
class CustomerData : public PersonData
{
private:
int customerNumber;
bool mailingList;
public:
void setCustomerNumber(int customerNumber)
{
this->customerNumber = customerNumber;
}
int getCustomerNumber()
{
return customerNumber;
}
void setMailingList(bool mailingList)
{
this->mailingList = mailingList;
}
int getMailingList()
{
return mailingList;
}
};
int main() {
CustomerData cust;
cust.setCustomerNumber(10);
cust.setMailingList(true);
cust.setLastName("Tom");
cust.setFirstName("Das");
cust.setAddress("34, SAS");
cust.setCity("ASD");
cust.setState("KSL");
cust.setZip("09868");
cust.setPhone("7865758789");
cout<<"Customer Number : "<<cust.getCustomerNumber();
cout<<"\nName : "<<cust.getFirstName()<<" "<<cust.getLastName();
cout<<"\nAddress : "<<cust.getAddress()<<","<<cust.getCity()<<","<<cust.getState()<<" "<<cust.getZip();
cout<<"\nPhone : "<<cust.getPhone();
return 0;
}