PersonalData and CustomerData classes in c++ Design a class named PersonData wit
ID: 3702630 • Letter: P
Question
PersonalData and CustomerData classes 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 <bits/stdc++.h>
using namespace std;
class PersonData{
private:
string firstName;
string lastName;
string address;
string city;
string state;
string zip;
string phone;
public:
PersonData(){
firstName=lastName=address=city=state=zip=phone="";
}
void setFirstName(string firstName)
{
this->firstName=firstName;
}
void setLastName(string lastName)
{
this->lastName=lastName;
}
void setAddress(string address)
{
this->address=address;
}
void setCity(string city)
{
this->city=city;
}
void setState(string state)
{
this->state=state;
}
void setZip(string zip)
{
this->zip=zip;
}
void setPhone(string phone)
{
this->phone=phone;
}
string getFirstName()
{
return this->firstName;
}
string getLastName()
{
return this->lastName;
}
string getAddress()
{
return this->address;
}
string getCity()
{
return this->city;
}
string getState()
{
return this->state;
}
string getZip()
{
return this->zip;
}
string getPhone()
{
return this->phone;
}
};
class CustomerData:public PersonData{
private:
int customerNo;
bool mailingList;
public:
CustomerData()
{
static int id=0;
this->customerNo=++id;
}
int getCustomerNo()
{
return this->customerNo;
}
void setMailingList(bool mailingList)
{
this->mailingList=mailingList;
}
bool getMailingList()
{
return this->mailingList;
}
void print()
{
cout<<" Customer No : "<<getCustomerNo()<<" Mailing List : "<<(getMailingList()?"True":"False")<<" First Name : "<<getFirstName()<<" Last Name : "<<getLastName()<<" Address : "<<getAddress()<<" City : "<<getCity()<<" State : "<<getState()<<" Zip : "<<getZip()<<" Phone No : "<<getPhone()<<endl;
}
};
int main() {
// your code goes here
CustomerData c1;
string c1fname,c1lname,c1add,c1city,c1state,c1zip,c1phone,c1mailinglist;
string c2fname,c2lname,c2add,c2city,c2state,c2zip,c2phone,c2mailinglist;
cout<<"Enter First Name: "<<endl;cin>>c1fname;c1.setFirstName(c1fname);
cout<<"Enter Last Name: "<<endl;cin>>c1lname;c1.setLastName(c1lname);
cout<<"Enter Address: "<<endl;cin>>c1add;c1.setAddress(c1add);
cout<<"Enter City: "<<endl;cin>>c1city;c1.setCity(c1city);
cout<<"Enter State: "<<endl;cin>>c1state;c1.setState(c1state);
cout<<"Enter Zip: "<<endl;cin>>c1zip;c1.setZip(c1zip);
cout<<"Enter Phone: "<<endl;cin>>c1phone;c1.setPhone(c1phone);
cout<<"Do you wish to be on mailing list(Y/N)?"<<endl;cin>>c1mailinglist;if(c1mailinglist=="Y")c1.setMailingList(true);else c1.setMailingList(false);
cout<<"Customer Details entered are: "<<endl;
c1.print();
cout<<endl;
cout<<"Enter a new customer's details: "<<endl;
CustomerData c2;
cout<<"Enter First Name: "<<endl;cin>>c2fname;c2.setFirstName(c2fname);
cout<<"Enter Last Name: "<<endl;cin>>c2lname;c2.setLastName(c2lname);
cout<<"Enter Address: "<<endl;cin>>c2add;c2.setAddress(c2add);
cout<<"Enter City: "<<endl;cin>>c2city;c2.setCity(c2city);
cout<<"Enter State: "<<endl;cin>>c2state;c2.setState(c2state);
cout<<"Enter Zip: "<<endl;cin>>c2zip;c2.setZip(c2zip);
cout<<"Enter Phone: "<<endl;cin>>c2phone;c2.setPhone(c2phone);
cout<<"Do you wish to be on mailing list(Y/N)?"<<endl;cin>>c2mailinglist;if(c2mailinglist=="Y")c2.setMailingList(true);else c2.setMailingList(false);
cout<<"Customer Details entered are: "<<endl;
c2.print();
cout<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.