• 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?

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 1PE: In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain...
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 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?
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 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? 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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,