Question
#include using namespace std; struct Date { int day; int month; int year; }; class Deep_Copy_Date { public : Deep_Copy_Date( int d, int m, int
#include
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)
{
}
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 this->date->month this->date->day this->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()
{
coutthis->date->month this->date->day this->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;
}
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 1) Implement the Deep Copy Date to perform deep copy 2) Implement the ShallowCopy Date to perform shallow copy Prototype: class Deep_Copy_Date public: class Shallow_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; 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-Data); shallow-copy-Date operator+(const int); private: private: Date "date; Date date; Output: dd 18 months to d date and assign the result to a new object d date ate: 10/1 2818 ate: 8/1 2819 dd 1 month to object d date ate: 11/1 2018 ate: 8/1 2019 Shallow Copy dd 18 months to d date and assign the result to a new object s_datel ate: 9/1 2819 ate: 9/1 2019 dd 1 month to object s date ate:18/1 2819 ate: 1/1 2819Step 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