0

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 - The customerNumber variable will be used to hold a unique integer for each customer. • mailingList - 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.

The CustomerData class should also maintain a static variable to keep track of the total number of customers created and a static function to access that number.

Write appropriate accessor and mutator functions for these member variables. Demonstrate an object of the CustomerData class in a simple program.

#include <iostream>
#include <string>

using namespace std;

class PersonData
{
private:
    string lastName;
    string firstName;
    string address;
    string city;
    string state;
    string zip;
    string phone;

public:
    void setLastName(string newLastName);
    void setFirstName(string newFirstName);
    void setAddress(string newAddress);
    void setCity(string newCity);
    void setState(string newState);
    void setZip(string newZip);
    void setPhone(string newPhone);
    string getLastName();
    string getFirstName();
    string getAddress();
    string getCity();
    string getState();
    string getZip();
    string getPhone();
};

void PersonData::setLastName(string newLastName)
{
    lastName = newLastName;
}

void PersonData::setFirstName(string newFirstName)
{
    firstName = newFirstName;
}

void PersonData::setAddress(string newAddress)
{
    address = newAddress;
}

void PersonData::setCity(string newCity)
{
    city = newCity;
}

void PersonData::setState(string newState)
{
    state = newState;
}

void PersonData::setZip(string newZip)
{
    zip = newZip;
}

void PersonData::setFirstName(string newFirstName)
{
    firstName = newFirstName;
}

class CustomerData: public PersonData
{
public:


};
int main()
{


    system("pause");
    return 0;
}

I'm not really sure where to go from here. Any suggestions or tips would be awesome!

  • 1
    Easy on the setters! There is no practical use for separate setters for City, State, and Zip, because they are dependent. [Are getters and setters poor design?](http://stackoverflow.com/questions/565095/are-getters-and-setters-poor-design-contradictory-advice-seen) – Bo Persson Dec 08 '15 at 08:06
  • The way you use getters and setters offers no advantage over public fields. See my favourite answer ever on this topic: http://stackoverflow.com/questions/1568091/why-use-getters-and-setters#12108025 On top of this, your derivation is pretty useless, because `PersonData` is obviously not designed to be a base class. – Christian Hackl Dec 08 '15 at 11:09

1 Answers1

0

You want to derive a class CustomerData. You can add this code for that class

class CustomerData: public PersonData

{

public:

int customerNumber;
bool mailingList;
static int totalCustomer;

};

int CustomerData :: totalCustomer=0; This code is to initialize the static variable of the class.

You can Write the code to get data by using the prototype defined by you.

In main you can use the object of CustomerData class to access the setters and mutator functions defined in the PersonData class.

for example : CustomerData obj;

obj.setLastName("XYZ");

and to get the last name you can write

obj.getLastName();

but remember you have to write the getLastName() and all get______() functions.

Nutan
  • 778
  • 1
  • 8
  • 18