• If you do not have a copy constructor function for Date , add it to the class definition, which is in the following form o Date (const Date &src) • Modify the constructor functions of the Date class (including the copy constructor function mentioned above) to add a line of code to print The constructor function is executed on the screen. • Write two functions that accept an Date object as parameter void f(Date &d); void g(Date d); • For both f and g, call the member function print . Please observe the execution results of f and g, and answer the following two questions: • What is the difference when you run function f and g ? • What is the reason for the difference?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Based on this code, can you add what is in the picture to it?

#include <iostream>

#include <stdlib.h>

#include <string>

 

using namespace std;

 

// Declare the class

 

class Date

 

{

    

    // Declare the private members of class

    

private:

    

    int day_of_month, month, year;

    

    // Declare the public members of the class.

    

public:

    

    Date()

    

    {

        

        // initialize the variables.

        

        day_of_month = 1;

        

        month = 1;

        

        year = 2001;

        

    }

    

    Date(int d, int m, int y)

    

    {

        

        // Initialized the values.

        

        day_of_month = d;

        

        month = m;

        

        year = y;

        

    }

    

    // Definition of the function.

    

    void printNumerical()

    

    {

        

        cout << month << "/" << day_of_month << "/" << year << endl;

        

    }

    

    // Definition of the function.

    

    void printMonthFirst()

    

    {

        

        cout << getMonth(month) << " " << day_of_month << ", " << year << endl;

        

    }

    

    // Definition of the function

    

    void printDateFirst()

    

    {

        

        cout << day_of_month << " " << getMonth(month) << " " << year << endl;

        

    }

    

    // Definition of the function

    

    string getMonth(int month) {

        

        

        if (month == 1) {

            

            return "January";

            

        }

        

        else if (month == 2) {

            

            return "February";

            

        }

        

        else if (month == 3) {

            

            return "March";

            

        }

        

        else if (month == 4) {

            

            return "April";

            

        }

        

        else if (month == 5) {

            

            return "May";

            

        }

        

        else if (month == 6) {

            

            return "June";

            

        }

        

        else if (month == 7) {

            

            return "July";

            

        }

        

        else if (month == 8) {

            

            return "August";

            

        }

        

        else if (month == 9) {

            

            return "September";

            

        }

        

        else if (month == 10) {

            

            return "October";

            

        }

        

        else if (month == 11) {

            

            return "November";

            

        }

        

        else if (month == 12) {

            

            return "December";

            

        }

        

        return 0;

    }

    

};

 

// Declare the main method.

 

int main()

 

{

    

    

    int day_of_month, month, year;

    

    // Prompt the user to enter the date of month.

    

    cout << "Enter the day of month: ";

    cin >> day_of_month;

    

    // Prompt the user to enter the month.

    

    cout << "Enter the month: ";

    cin >> month;

    

    // Prompt the user to enter the year.

    

    cout << "Enter the year: ";

    cin >> year;

    cout << endl;

    // Check whether the condition are valid or not.

    

    if (day_of_month < 1 || day_of_month > 31 || month < 1 || month > 12 || year<0)

        

    {

        

        // Create the object of class.

        

        Date d1;

        

        // Call to the functions

        

        d1.printNumerical();

        

        d1.printMonthFirst();

        

        d1.printDateFirst();

        

    }

    

    else

        

    {

        

        // Create the object of class.

        

        Date d2(day_of_month, month, year);

        

        // Call to the functions

        

        d2.printNumerical();

        

        d2.printMonthFirst();

        

        d2.printDateFirst();

        

    }

    

    

    return 0;

    

}

- If you do not have a copy constructor function for `Date`, add it to the class definition, which is in the following form:
  - `Date (const Date &src)`

- Modify the constructor functions of the `Date` class (including the copy constructor function mentioned above) to add a line of code to print `The constructor function is executed` on the screen.

- Write two functions that accept a `Date` object as parameter:

  ```cpp
  void f(Date &d);
  void g(Date d);
  ```

- For both `f` and `g`, call the member function `print`.

Please observe the execution results of `f` and `g`, and answer the following two questions:

- What is the difference when you run function `f` and `g`?
- What is the reason for the difference?

*Hint 1: Note that `f` accepts reference parameter, and `g` accepts value parameter.*

*Hint 2: For this question, you do not need to submit your code, you only need to answer the two questions.*

This question will provide you a better understanding of reference parameter, recall the [slide](#).
Transcribed Image Text:- If you do not have a copy constructor function for `Date`, add it to the class definition, which is in the following form: - `Date (const Date &src)` - Modify the constructor functions of the `Date` class (including the copy constructor function mentioned above) to add a line of code to print `The constructor function is executed` on the screen. - Write two functions that accept a `Date` object as parameter: ```cpp void f(Date &d); void g(Date d); ``` - For both `f` and `g`, call the member function `print`. Please observe the execution results of `f` and `g`, and answer the following two questions: - What is the difference when you run function `f` and `g`? - What is the reason for the difference? *Hint 1: Note that `f` accepts reference parameter, and `g` accepts value parameter.* *Hint 2: For this question, you do not need to submit your code, you only need to answer the two questions.* This question will provide you a better understanding of reference parameter, recall the [slide](#).
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education