Complete the missing code for the constructors as indicated in the comments in all three header files. C++
mainDriver.cpp
#include <string>
#include "Address.h"
#include "Date.h"
#include "Person.h"
using namespace std;
int main() {
Person p1;
Person p2("Smith", "Bobby", "[email protected]", 111,
"Main St", "Clemson",
"SC", 29630, 1,
31, 1998);
cout << endl << endl;
p1.printInfo();
p2.printInfo();
return 0;
}
Person.h
#ifndef PERSON_H
#define PERSON_H
#include <iostream>
#include <string>
using namespace std;
class Person {
private:
string last;
string first;
string email;
Address address;
Date bday;
public:
// Complete both Person constructors
// default constructor with an initialization
list
// initializing a Person with these values:
// name: John Doe
// email: jdoe@
// address: 0 Main St Clemson SC 29630
// birthday: 1, 1, 1
// include print statement that says:
// default Person constructor
Person()
// regular, parameterized,
constructor with an initialization list
// initializing a Person with these values:
// name: John Doe
// email: jdoe@
// address: 0 Main St Clemson SC 29630
// birthday: 1, 1, 1
// include print statement that says:
// regular Person constructor
Person(string l, string f, string
e,
int house, string street, string city, string
state, int zip,
int month, int day, int year)
~Person() {
cout <<
"Person destructor " << endl;
}
void printInfo();
};
ostream &operator<<(ostream& out, Address a)
{
out << a.getHouse() << " " <<
a.getStreet() << " "
<< a.getCity() << ", "
<< a.getState() << " "
<< a.getZip();
return out;
}
ostream &operator<<(ostream& out, Date d) {
out << d.getMonth() << " " <<
d.getDay() << " "
<< d.getYear();
return out;
}
void Person::printInfo() {
cout << endl << last << ", "
<< first << ", " << email << endl;
cout << address << bday << endl
<< endl;
}
#endif
Date.h
#ifndef DATE_H
#define DATE_H
#include <iostream>
#include <string>
using namespace std;
class Date {
private:
int month, day, year;
public:
Date();
// complete the parameterized Date
constructor with
// with an initialization
list
// include print statement that
says:
// Date constructor
Date(int m, int d, int y)
~Date() {
cout <<
"Date destructor " << endl;
}
int getMonth() { return month;
}
int getDay() { return day; }
int getYear() { return year;
}
};
#endif
Address.h
#ifndef ADDRESS_H
#define ADDRESS_H
#include <iostream>
#include <string>
using namespace std;
class Address {
private:
int house;
string street;
string city;
string state;
int zip;
public:
// complete the parameterized Address constructor
with
// with an initialization
list
// include print statement that
says:
// Address constructor
Address(int h, string str, string
c, string st, int z)
~Address() {
cout <<
"Address destructor " << endl;
}
int getHouse() { return house;
}
string getStreet() { return street;
}
string getCity() { return city;
}
string getState() { return state;
}
int getZip() { return zip; }
};
#endi
Here are your constructors:
Default Constructor Person:
Person() : last("Doe"), first("John"), email("jdoe@"),
address(0, "Main St", "Clemson", "SC", 29630), Date(1,1,1) {
cout<<"default Person constructor.\n";
}
Regular Constructor Person:
Person(string l, string f, string e, int house, string street,
string city, string state, int zip, int month, int day, int year):
last(l), first(f), email(e), address(house,street,city,state,zip),
Date(month, day, year) {
cout<<"regular Person constructor.\n";
}
Date Constructor :
Date(int m, int d, int y) : month(m), day(d), year(y) {
cout<<"Date constructor.\n";
}
Address Constructor :
Address(int h, string str, string c, string st, int z) :
house(h), street(str), city(c), state(st), zip(z) {
cout<<"Address constructor.\n";
}
Get Answers For Free
Most questions answered within 1 hours.