C++ * Please be sure that your code is structured into the following files: - Pe
ID: 3750123 • Letter: C
Question
C++
* Please be sure that your code is structured into the following files:
- PersonType.h
- PersonType.cpp
- PersonTypeMain.cpp
- makefile
_________________________________________________________________
*Please include user input
Develop a user defined data type : extPersonType by the following procedures.
- Define a class, addressType, that can store a street address, city, state, and ZIP code. Use the appropriate functions to print and store the address. Also, use constructors to automatically initialize the member variables.
- Define a class, personType, that can store the first name and the last name of a person. Use the appropriate functions to print and store the first and the last name. Also, use constructors to automatically initialize the member variables.
- Define a class, dataType, that can store the day, the month, and the year of a date. Use the appropriate functions to print and store the day, the month, and the year. Also, use constructors to automatically initialize the member variables.
- Define a class extPersonType. The class is a derived class from the above classes. The class adds a member variable to classify the person as a family member, friend, or business associate. Also, the class adds a member variable to store the phone number. Moreover, the class adds (or override) functions to print and store the appropriate information. Use constructors to automatically initialize the member variables.
- Add more member functions on the class extPersonType.
The following functions are needed to be added:
– = assign one object to the other
– == check if two objects are equal
– A copy constructor
Write a C++ program to test your design. Moreover, test your design by creating pointers.
Explanation / Answer
// File Name: AddressType.h
#ifndef AddressType_H
#define AddressType_H
#include <string>
using namespace std;
// Defines class AddressType
class AddressType
{
// Data member to store data
string street, city, state, ZIP;
public:
// Prototype of member functions
AddressType();
AddressType(string, string, string, string);
void setStreet(string);
void setCity(string);
void setState(string);
void setZip(string);
string getStreet();
string getCity();
string getState();
string getZip();
void display();
};// End of class
#endif
---------------------------------------------------------------------
// File Name: AddressType.cpp
#include "AddressType.h"
#include <iostream>
#include <string>
using namespace std;
// Default constructor definition
AddressType::AddressType()
{
street, city, state, ZIP = "";
}// End of default constructor
// Parameterized constructor to assign parameter value to data members
AddressType::AddressType(string str, string ci, string sta, string zip)
{
street = str;
city = ci;
state = sta;
ZIP = zip;
}// End of parameterized constructor
// Function to set street
void AddressType::setStreet(string str)
{
street = str;
}// End of function
// Function to set city
void AddressType::setCity(string ci)
{
city = ci;
}// End of function
// Function to set state
void AddressType::setState(string sta)
{
state = sta;
}// End of function
// Function to set zip
void AddressType::setZip(string zip)
{
ZIP = zip;
}// End of function
// Function to return street
string AddressType::getStreet()
{
return street;
}// End of function
// Function to return city
string AddressType::getCity()
{
return city;
}// End of function
// Function to return state
string AddressType::getState()
{
return state;
}// End of function
// Function to return zip
string AddressType::getZip()
{
return ZIP;
}// End of function
// Function to display address
void AddressType::display()
{
cout<<" Street: "<<street<<" City: "<<city<<" State: "<<state<<" ZIP: "<<ZIP;
}// End of function
------------------------------------------------------------------------------------
// File Name: PersonType.h
#ifndef PersonType_H
#define PersonType_H
#include <string>
using namespace std;
// Defines class PersonType
class PersonType
{
// Data member to store data
string firstName, lastName;
public:
// Prototype of member functions
PersonType();
PersonType(string, string);
void setFirstName(string);
void setLastName(string);
string getFirstName();
string getLastName();
void display();
};// End of class
#endif
----------------------------------------------------------------
// File Name: PersonType.cpp
#include "PersonType.h"
#include <iostream>
#include <string>
using namespace std;
// Default constructor definition
PersonType::PersonType()
{
firstName = lastName = "";
}// End of default constructor
// Parameterized constructor to assign parameter value to data members
PersonType::PersonType(string fn, string ln)
{
firstName = fn;
lastName = ln;
}// End of parameterized constructor
// Function to set first name
void PersonType::setFirstName(string fn)
{
firstName = fn;
}// End of function
// Function to set last name
void PersonType::setLastName(string ln)
{
lastName = ln;
}// End of function
// Function to return fast name
string PersonType::getFirstName()
{
return firstName;
}// End of function
// Function to return last name
string PersonType::getLastName()
{
return lastName;
}// End of function
// Function to display names
void PersonType::display()
{
cout<<" First Name: "<<firstName<<" Last Name: "<<lastName;
}// End of function
----------------------------------------------------------------------------
// File Name: DateType.h
#ifndef DateType_H
#define DateType_H
#include <string>
using namespace std;
// Defines class DateType
class DateType
{
// Data member to store data
int day, month, year;
public:
// Prototype of member functions
DateType();
DateType(int, int, int);
void setDay(int);
void setMonth(int);
void setYear(int);
int getDay();
int getMonth();
int getYear();
void display();
};// End of class
#endif
--------------------------------------------------------------------------------
// File Name: DateType.cpp
#include "DateType.h"
#include <iostream>
using namespace std;
// Default constructor definition
DateType::DateType()
{
day = month = year = 0;
}// End of default constructor
// Parameterized constructor to assign parameter value to data members
DateType::DateType(int d, int m, int y)
{
day = d;
month = m;
year = y;
}// End of parameterized constructor
// Function to set day
void DateType::setDay(int d)
{
day = d;
}// End of function
// Function to set month
void DateType::setMonth(int m)
{
month = m;
}// End of function
// Function to set year
void DateType::setYear(int y)
{
year = y;
}// End of function
// Function to return day
int DateType::getDay()
{
return day;
}// End of function
// Function to return month
int DateType::getMonth()
{
return month;
}// End of function
// Function to return year
int DateType::getYear()
{
return year;
}// End of function
// Function to display date data
void DateType::display()
{
cout<<" DOB: "<<day<<"/"<<month<<"/"<<year;
}// End of function
-----------------------------------------------------------------------------------
// File Name: ExtPersonType.h
#ifndef ExtPersonType_H
#define ExtPersonType_H
#include "AddressType.cpp"
#include "PersonType.cpp"
#include "DateType.cpp"
using namespace std;
// Defines class ExtPersonType derived from class AddressType, PersonType and DateType
class ExtPersonType : public AddressType, public PersonType, public DateType
{
// Declares an object type pointer for class AddressType as data member
AddressType *addressT;
// Declares an object type pointer for class PersonType as data member
PersonType *personT;
// Declares an object type pointer for class DateType as data member
DateType *dateT;
// Data member to store phone number
string phoneNumber;
public:
// Prototype of member functions
ExtPersonType();
ExtPersonType(AddressType *, PersonType *, DateType *, string);
void setPhoneNumber(string);
string getPhoneNumber();
void display();
};// End of class
#endif
-----------------------------------------------------------------------------------------
// File Name: ExtPersonType.cpp
#include "ExtPersonType.h"
using namespace std;
// Default constructor definition
ExtPersonType::ExtPersonType()
{
phoneNumber = "";
}// End of default constructor
// Parameterized constructor to assign parameter value to data members
ExtPersonType::ExtPersonType(AddressType *ad, PersonType *pt, DateType *dt, string ph)
{
addressT = ad;
personT = pt;
dateT = dt;
phoneNumber = ph;
}// End of parameterized constructor
// Function to set phone number
void ExtPersonType::setPhoneNumber(string ph)
{
phoneNumber = ph;
}// End of function
// Function to returns phone number
string ExtPersonType::getPhoneNumber()
{
return phoneNumber;
}// End of function
// Displays person information
void ExtPersonType::display()
{
// Calls the display function of AddressType class
addressT->display();
// Calls the display function of PersonType class
personT->display();
// Calls the display function of DateType class
dateT->display();
// Displays phone number
cout<<" Mobile: "<<phoneNumber;
}// End of function
--------------------------------------------------------------------------------------
// File Name: MainExtPersonType.h
#include "ExtPersonType.cpp"
#include <iostream>
using namespace std;
// Defines main function
int main()
{
// Creates an object for family using parameterized constructor
// Passes dynamically created object for AddressType, PersonType, and DateType
ExtPersonType family(new AddressType("Bank Colony", "Berhampur", "Orissa", "760004"), new PersonType("Pyari", "Sahu"), new DateType(12, 3, 1919), "9933456987");
// Creates an object for friends using parameterized constructor
// Passes dynamically created object for AddressType, PersonType, and DateType
ExtPersonType friends(new AddressType("Gate bazar", "Bhubaneswar", "Orissa", "761104"), new PersonType("Suresh", "Panda"), new DateType(10, 8, 1900), "9944456777");
// Creates an object for business using parameterized constructor
// Passes dynamically created object for AddressType, PersonType, and DateType
ExtPersonType business(new AddressType("Sunari Colony", "Rourkela", "Orissa", "762221"), new PersonType("Anil", "Sahu"), new DateType(7, 9, 2000), "7712454567");
// Calls the function to display family data
cout<<" ************************ FAMILY ************************";
family.display();
// Calls the function to display friend data
cout<<" ************************ FRIENDS ************************";
friends.display();
// Calls the function to display business data
cout<<" ************************ BUSINES ************************";
business.display();
return 0;
}// End of main function
Sample Output:
************************ FAMILY ************************
Street: Bank Colony City: Berhampur State: Orissa ZIP: 760004
First Name: Pyari Last Name: Sahu
DOB: 12/3/1919
Mobile: 9933456987
************************ FRIENDS ************************
Street: Gate bazar City: Bhubaneswar State: Orissa ZIP: 761104
First Name: Suresh Last Name: Panda
DOB: 10/8/1900
Mobile: 9944456777
************************ BUSINES ************************
Street: Sunari Colony City: Rourkela State: Orissa ZIP: 762221
First Name: Anil Last Name: Sahu
DOB: 7/9/2000
Mobile: 7712454567
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.