7. PersonData and CustomerData classes Design a class named PersonData with the
ID: 3773670 • Letter: 7
Question
7. 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 simpleprogram .
Explanation / Answer
#include <iostream>
using namespace std;
class PersonData
{
private:
string lastName,firstName, address, city, state,zip, phone;
public:
//set and get methods
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:
//set and get methods
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(1007);
cust.setMailingList(true);
cust.setLastName("Jones");
cust.setFirstName("Emily");
cust.setAddress("7764,Hillside");
cust.setCity("Trenton");
cust.setState("NJ");
cust.setZip("08625-0088");
cust.setPhone("768-687878");
cout<<"Customer Number : "<<cust.getCustomerNumber();
cout<<" Name : "<<cust.getFirstName()<<" "<<cust.getLastName();
cout<<" Address : "<<cust.getAddress()<<","<<cust.getCity()<<","<<cust.getState()<<" "<<cust.getZip();
cout<<" Phone : "<<cust.getPhone();
return 0;
}
output:
Customer Number : 1007
Name : Emily Jones
Address : 7764,Hillside,Trenton,NJ 08625-0088
Phone : 768-687878
Do ask if any doubt. Please upvote.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.