Respuesta :
Answer:
#include <iostream>
using namespace std;
class PersonData //Base class
{
public :
string lastName;
string firstName;
string address;
string city;
string state;
int zip;
int phone;
};
class CustomerData : public PersonData //inheriting PersonData publicly
{
public:
CustomerData(string fName,string lName) //constructor which initializes firstname n lastname
{
firstName=fName;
lastName=lName;
}
string product;
string date_of_purchase;
void print() //Method to print variables
{
cout<<firstName<<" "<<lastName<<" r/o "<<address<<" purchased "<<product<<" on "<<date_of_purchase;
}
};
int main()
{
CustomerData c("John","Thomsons"); //testing this class
c.address="x/123,New york street-5";
c.product="Jeans";
c.date_of_purchase="12/8/15";
c.print();
return 0;
}
OUTPUT :
John Thomsons r/o x/123,New york street-5 purchased Jeans on 12/8/15
Explanation:
In the above code a class PersonData is created with the given variables. Then CustomerData is an derived class which inherits properties of PersonData publicly and has some new variables like product and date_of_purchase. It has a parameterized constructor who initializes firstname and lastname. It has one more method which prints its variables if called. Then in the main method an object of CustomerData is created and print method is called.