Please write in C++ Design a class named PersonData with the following member va
ID: 3783259 • Letter: P
Question
Please write in C++
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 mailing list. Write appropriate accessor and mutator functions for these member variables. Demonstrate an object of the CustomerData class in a simple program.Explanation / Answer
#include <iostream>
using namespace std;
class PersonData
{
private:
string lastName;
string firstName;
string address;
string city;
string state;
int zip;
string phone;
public:
PersonData() //default constructor
{
}
PersonData(string lastName,string firstName,string address,string city,string state,int zip,string phone)
{
this->lastName = lastName;
this->firstName = firstName;
this->address = address;
this->city = city;
this->state = state;
this->zip = zip;
this->phone = phone;
}
//accessor and mutator functions
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(int zip)
{
this->zip = zip;
}
int getZip()
{
return zip;
}
void setPhone(string phone)
{
this->phone = phone;
}
string getPhone()
{
return phone;
}
};
class CustomerData:public PersonData
{
private:
int customerNumber;
bool mailingList;
public:
CustomerData() //default constructor
{
}
CustomerData(int customerNumber,bool mailingList) //parameterized constructor
{
this->customerNumber = customerNumber;
this->mailingList = mailingList;
}
void setCustomerNumber(int customerNumber) //set and get methods
{
this->customerNumber = customerNumber;
}
int getCustomerNumber()
{
return customerNumber;
}
void setMailingList(bool mailingList)
{
this->mailingList = mailingList;
}
bool getMailingList()
{
return mailingList;
}
};
int main()
{
CustomerData c; //customer object
c.setLastName("Smith"); //call set methods of PersonData class and CustomerData class
c.setFirstName("John");
c.setAddress("1876,Lane 4");
c.setCity("Hillside");
c.setState("New Jersey");
c.setPhone("001-345-5855");
c.setZip(364745);
c.setCustomerNumber(2004);
c.setMailingList(true);
//call get methods of PersonData class and CustomerData class to display values
cout<<"Name of the customer : "<<c.getFirstName()<<" "<<c.getLastName()<<endl;
cout<<"Address : "<<c.getAddress()<<endl;
cout<<"City : "<<c.getCity()<<endl;
cout<<"State : "<<c.getState()<<endl;
cout<<"Phone : "<<c.getPhone()<<endl;
cout<<"Zip Code : "<<c.getZip()<<endl;
cout<<"Customer Number : "<<c.getCustomerNumber()<<endl;
cout<<"On mailing list : "<<c.getMailingList()<<endl;
return 0;
}
output: