C++. Customer Data. This program will have two classes. The first class defines
ID: 3663108 • Letter: C
Question
C++. Customer Data. This program will have two classes. The first class defines a person, which means this class can be used for anything that involves a person. We will use it to define a Customer but it could be used to define a Student.
Create a class called PersonData and it will have its class declaration in PersonData.h and its implementation in PersonData.cpp. This class will have private data member’s lastName, firstName, address, city, state, zip and phone number as strings. Write the appropriate accessor and mutator functions for these member variables. It should have two constructors. One constructor is a default constructor that sets all of the data members to empty strings. A second constructor has parameters for all of its data members.
Create a class called CustomerData which will have its class declaration in CustomerData.h and its implementation in CustomerData.cpp. This class will be a derived class of PersonData. This class will have two private data members for the customer number (customerNumber) as an integer; the other will be called mailingList which is a bool to indicate if they want to be on the mailing list or not. Write appropriate accessor and mutator functions for these data members. This class will also have two constructors. It will have a default constructor that sets its data members to zero and false. The other constructor will have parameters to set all of the data members of the two classes.
Create a program that will create two instances of the CustomerData class. It must create one instance using the default constructor and then another using the second constructor. Once both instances are fully populated with data, call a function that will display the customer information.
void displayCustomer(CustomerData c)
Explanation / Answer
/*Programs to be entered in seperate files */
/*======================================*/
/*PersonData .h*/
#ifndef PersonData_h
#define PersonData_h
class PersonData
{
/*This class will have private data member’s lastName, firstName,
address, city, state, zip and phone number as strings. */
string lastname;
string firstname;
string address;
string city;
string state;
string zip;
string phonenumber;
/*It should have two constructors.*/
public:
/*One constructor is default constructor that sets all of the data members
to empty strings.*/
PersonData();
/*A second constructor has parameters
for all of its data members*/
PersonData(string lname, string fname,string a,string s, string c,string z,string ph);
/* accessor and mutator functions for these member variables*/
void setlastname(string lname);
void setfirstname(string fname);
void setaddress(string a);
void setstate(string s);
void setcity(string c);
void setzip(string z);
void setphonenumber(string ph);
string getlastname();
string getfirstname();
string getaddress();
string getstate();
string getcity();
string getzip();
string getphonenumber();
};
#endif
/*======================================*/
/*PersonData .cpp*/
#include <iostream>
#include "PersonData.h"
using namespace std;
/*One constructor is default constructor that sets all of the data members
to empty strings.*/
PersonData::PersonData()
{
lastname="";
firstname="";
address="";
state="";
city="";
zip="";
phonenumber="";
}
/*A second constructor has parameters
for all of its data members*/
PersonData::PersonData(string lname, string fname,string a,string s, string c,string z,string ph)
{
lastname=lname;
firstname=fname;
address=a;
state=s;
city=c;
zip=z;
phonenumber=ph;
}
/* accessor and mutator functions for these member variables*/
void PersonData::setlastname(string lname)
{
lastname=lname;
}
void PersonData::setfirstname(string fname)
{
firstname=fname;
}
void PersonData::setaddress(string a)
{
address=a;
}
void PersonData::setstate(string s)
{
state=s;
}
void PersonData::setcity(string c)
{
city=c;
}
void PersonData::setzip(string z)
{
zip=z;
}
void PersonData::setphonenumber(string ph)
{
phonenumber=ph;
}
string PersonData::getlastname()
{
return lastname;
}
string PersonData::getfirstname()
{
return firstname;
}
string PersonData::getaddress()
{
return address;
}
string PersonData::getstate()
{
return state;
}
string PersonData::getcity()
{
return city;
}
string PersonData::getzip()
{
return zip;
}
string PersonData::getphonenumber()
{
return phonenumber;
}
/*======================================*/
/*CustomerData.h*/
#ifndef CustomerData_h
#define CustomerData_h
#include <iostream>
#include "PersonData.cpp"
using namespace std;
/*This class will be a derived class of PersonData*/
class CustomerData : public PersonData
{
/*This class will have two private data members for the customer number
(customerNumber) as an integer; the other will be called mailingList
which is a bool to indicate if they want to be on the mailing list or not. */
int customerNumber;
bool mailingList;
public:
/*accessor and mutator functions for these data members*/
void setCustomerNumber(int cno);
void setMailingList(bool ans);
int getCustomerNumber();
bool getMailingList();
/* It will have a default constructor that sets its data members to zero and false.*/
CustomerData();
/*The other constructor will have parameters to set all of the data members of the two classes.*/
CustomerData(int cno,bool ans,string lname, string fname,string a,string s, string c,string z,string ph);
};
#endif
/*======================================*/
/*CustomerData.cpp*/
#include "CustomerData.h"
/*accessor and mutator functions for these data members*/
void CustomerData::setCustomerNumber(int cno)
{
customerNumber=cno;
}
void CustomerData::setMailingList(bool ans)
{
mailingList=ans;
}
int CustomerData::getCustomerNumber()
{
return customerNumber;
}
bool CustomerData::getMailingList()
{
return mailingList;
}
/* It will have a default constructor that sets its data members to zero and false.*/
CustomerData()
{
customerNumber=0;
mailingList=false;
}
/*The other constructor will have parameters to set all of the data members of the two classes.*/
CustomerData(int cno,bool ans,string lname, string fname,string a,string s, string c,string z,string ph)
:PersonData(lname, fname,a,s, c,z,ph)
{
customerNumber=0;
mailingList=false;
}
/*======================================*/
/*Implementation file contains main function*/
#include <iostream>
#include "CustomerData.cpp"
using namespace std;
void displayCustomer(CustomerData c);
int main()
{
/*create two instances of the CustomerData class.*/
/*It must create one instance using the default constructor*/
CustomerData C1();
/*another using the second constructor. */
CustomerData C2(101,true,"James","Williams","CMR 345,BOX 12334","APO","AA APO/FPO","09250","918-555-0123");
/*display details*/
cout<<"Customer 1 details";
displayCustomer(C1);
cout<<endl<<"Customer 2 details";
displayCustomer(C2);
}
void displayCustomer(CustomerData c)
{
cout<<endl<<"Last Name: "<<c.getlastname();
cout<<endl<<"First Name: "<<c.getfirstname();
cout<<endl<<"Address: "<<c.getaddress();
cout<<endl<<"State: "<<c.getstate();
cout<<endl<<"City: "<<c.getcity();
cout<<endl<<"Zip: "<<c.getzip();
cout<<endl<<"Phone number: "<<c.getphonenumber();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.