Question
code provided c++ #include #include pch.h using namespace std; struct Date { int day; int month; int year; }; class Deep_Copy_Date { public: Deep_Copy_Date(int d,
code provided
c++
#include
#include "pch.h"
using namespace std;
struct Date
{
int day;
int month;
int year;
};
class Deep_Copy_Date {
public:
Deep_Copy_Date(int d, int m, int y);
Deep_Copy_Date();
Deep_Copy_Date(const Deep_Copy_Date &);
void print();
Deep_Copy_Date operator=(const Deep_Copy_Date&);
Deep_Copy_Date operator+(const int) const;
private:
Date *date;
};
class Shallow_Copy_Date {
public:
Shallow_Copy_Date(int d, int m, int y);
Shallow_Copy_Date();
Shallow_Copy_Date(const Shallow_Copy_Date &);
void print();
Shallow_Copy_Date operator=(const Shallow_Copy_Date&);
Shallow_Copy_Date operator+(const int);
private:
Date *date;
};
#pragma Below are the implementation of member functions of Deep_Copy_Date
Deep_Copy_Date::Deep_Copy_Date(int d, int m, int y)
{
date = new Date();
this->date->day = d;
this->date->month = m;
this->date->year = y;
}
Deep_Copy_Date::Deep_Copy_Date()
{
}
Deep_Copy_Date::Deep_Copy_Date(const Deep_Copy_Date &other)
{
}
Deep_Copy_Date Deep_Copy_Date::operator=(const Deep_Copy_Date &other)
{
}
Deep_Copy_Date Deep_Copy_Date::operator+(const int month) const
{
}
void Deep_Copy_Date::print()
{
cout date->month date->day date->year
}
#pragma Below are the implementation of member functions of Shallow_Copy_Date
Shallow_Copy_Date::Shallow_Copy_Date(int d, int m, int y)
{
}
Shallow_Copy_Date::Shallow_Copy_Date()
{
}
Shallow_Copy_Date::Shallow_Copy_Date(const Shallow_Copy_Date &other)
{
}
Shallow_Copy_Date Shallow_Copy_Date::operator=(const Shallow_Copy_Date &other)
{
}
Shallow_Copy_Date Shallow_Copy_Date::operator+(const int month)
{
}
void Shallow_Copy_Date::print()
{
cout date->month date->day date->year
}
int main() {
Deep_Copy_Date d_date(1, 10, 2018);
Shallow_Copy_Date s_date(1, 11, 2018);
cout
// Call the overloaded + operator to add 10 months
// and call the copy construct to perform deep copy
cout
Deep_Copy_Date d_date2 = d_date + 10;
d_date.print();
d_date2.print();
cout
d_date = d_date + 1;
d_date.print();
d_date2.print();
cout
// Call the overloaded + operator to add 10 months
// and call the copy contrust to perform Shallow copy
cout
Shallow_Copy_Date s_date2 = s_date + 10;
s_date.print();
s_date2.print();
cout
s_date = s_date + 1;
s_date.print();
s_date2.print();
return 0;
}#include
#include "pch.h"
using namespace std;
struct Date
{
int day;
int month;
int year;
};
class Deep_Copy_Date {
public:
Deep_Copy_Date(int d, int m, int y);
Deep_Copy_Date();
Deep_Copy_Date(const Deep_Copy_Date &);
void print();
Deep_Copy_Date operator=(const Deep_Copy_Date&);
Deep_Copy_Date operator+(const int) const;
private:
Date *date;
};
class Shallow_Copy_Date {
public:
Shallow_Copy_Date(int d, int m, int y);
Shallow_Copy_Date();
Shallow_Copy_Date(const Shallow_Copy_Date &);
void print();
Shallow_Copy_Date operator=(const Shallow_Copy_Date&);
Shallow_Copy_Date operator+(const int);
private:
Date *date;
};
#pragma Below are the implementation of member functions of Deep_Copy_Date
Deep_Copy_Date::Deep_Copy_Date(int d, int m, int y)
{
date = new Date();
this->date->day = d;
this->date->month = m;
this->date->year = y;
}
Deep_Copy_Date::Deep_Copy_Date()
{
}
Deep_Copy_Date::Deep_Copy_Date(const Deep_Copy_Date &other)
{
}
Deep_Copy_Date Deep_Copy_Date::operator=(const Deep_Copy_Date &other)
{
}
Deep_Copy_Date Deep_Copy_Date::operator+(const int month) const
{
}
void Deep_Copy_Date::print()
{
cout date->month date->day date->year
}
#pragma Below are the implementation of member functions of Shallow_Copy_Date
Shallow_Copy_Date::Shallow_Copy_Date(int d, int m, int y)
{
}
Shallow_Copy_Date::Shallow_Copy_Date()
{
}
Shallow_Copy_Date::Shallow_Copy_Date(const Shallow_Copy_Date &other)
{
}
Shallow_Copy_Date Shallow_Copy_Date::operator=(const Shallow_Copy_Date &other)
{
}
Shallow_Copy_Date Shallow_Copy_Date::operator+(const int month)
{
}
void Shallow_Copy_Date::print()
{
cout date->month date->day date->year
}
int main() {
Deep_Copy_Date d_date(1, 10, 2018);
Shallow_Copy_Date s_date(1, 11, 2018);
cout
// Call the overloaded + operator to add 10 months
// and call the copy construct to perform deep copy
cout
Deep_Copy_Date d_date2 = d_date + 10;
d_date.print();
d_date2.print();
cout
d_date = d_date + 1;
d_date.print();
d_date2.print();
cout
// Call the overloaded + operator to add 10 months
// and call the copy contrust to perform Shallow copy
cout
Shallow_Copy_Date s_date2 = s_date + 10;
s_date.print();
s_date2.print();
cout
s_date = s_date + 1;
s_date.print();
s_date2.print();
return 0;
}
Instructions: In the given cpp file, you can find two classes Deep_Copy_Date and Shallow_Copy_Date. Both of them have two constructors, a copy constructor, two overloading operators, a print function and a private pointer date, try to implement these member functions to generate the same output as the given screenshot. Do not add any extra code in the main function. No additional member function allowed. These are your specific tasks Implement the Deep_Copy_Date to perform deep copy 2) 1) Implement the Shallow_Copy_Date to perform shallow copy Prototype: class Deep Copy Date ( public: class Shallow_Copy Date f public: Deep-Copy,Date (int d, nt m, int y); Deep Copy Date) eep Copy Date(const Deep_Copy Date &) void print Deep_Copy Date operatore(const Deap_CopyDate) Deep_Copy Date operatort(const int) const shallow-copy-Date( int d, nt m, int y); Shallow Copy Date) Shallow Copy Date(const Shallow Copy Date &) void print Shallow Copy Date operator (const Shallow Copy Dates) Shallow Copy Date operatort (const int) private: private: date Date "date; Output: dd 1e months to ddate and assign the result to a new object ddate ate 1e1 2018 te /1 2819 dd 1 nonth to object d date ate: 1/3 2818 te: /1 2819 e Shallow Copy ad 1e months to d date and assign the result to a new objact dat V1 2019 V1 2019 th to object "-date dd 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started