Knowee
Questions
Features
Study Tools

Create a class called Date that includes three pieces of information as instance variables—a month, a day and a year. Your class should have a constructor that initializes the three instance variables after validating the given date. Provide a getDetails() member method to read the date. Provide a method displayDate() that displays the month, day and year separated by forward slashes(/). Write a C++ application and pseudocode that demonstrates classDate’s capabilities.Input : Read Month, Day and Year (Line by line)Output :Print Date that displays the month, day and year separated by forward slashes(/)Note: print "Invalid Date" other than the following2000 < Year < 20250 < Day <= 31 ( for the months Jan, March, May, July, August, October, December)0 < Day <= 30 ( for the months April, June, September, and November)0 < Day <= 28 ( for the month February ) and (0 < Day <= 29), if month = 2 and year = leap year0 < Month < = 12

Question

Create a class called Date that includes three pieces of information as instance variables—a month, a day and a year. Your class should have a constructor that initializes the three instance variables after validating the given date. Provide a getDetails() member method to read the date. Provide a method displayDate() that displays the month, day and year separated by forward slashes(/). Write a C++ application and pseudocode that demonstrates classDate’s capabilities.Input : Read Month, Day and Year (Line by line)Output :Print Date that displays the month, day and year separated by forward slashes(/)Note: print "Invalid Date" other than the following2000 < Year < 20250 < Day <= 31 ( for the months Jan, March, May, July, August, October, December)0 < Day <= 30 ( for the months April, June, September, and November)0 < Day <= 28 ( for the month February ) and (0 < Day <= 29), if month = 2 and year = leap year0 < Month < = 12

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is the C++ code and pseudocode for the Date class:

C++ Code:

#include<iostream>
using namespace std;

class Date {
    private:
        int month, day, year;
    public:
        Date(int m, int d, int y) {
            if(y > 2000 && y < 2025) {
                if(m > 0 && m <= 12) {
                    if((m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) && (d > 0 && d <= 31)) {
                        month = m;
                        day = d;
                        year = y;
                    } else if((m == 4 || m == 6 || m == 9 || m == 11) && (d > 0 && d <= 30)) {
                        month = m;
                        day = d;
                        year = y;
                    } else if(m == 2) {
                        if((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) {
                            if(d > 0 && d <= 29) {
                                month = m;
                                day = d;
                                year = y;
                            }
                        } else if(d > 0 && d <= 28) {
                            month = m;
                            day = d;
                            year = y;
                        }
                    }
                }
            } else {
                cout << "Invalid Date" << endl;
            }
        }

        void getDetails() {
            cout << "Month: " << month << endl;
            cout << "Day: " << day << endl;
            cout << "Year: " << year << endl;
        }

        void displayDate() {
            cout << month << "/" << day << "/" << year << endl;
        }
};

int main() {
    Date date(2, 29, 2020);
    date.getDetails();
    date.displayDate();
    return 0;
}

Pseudocode:

class Date
    private variables: month, day, year

    constructor(m, d, y)
        if y is between 2000 and 2025
            if m is between 1 and 12
                if m is in [1, 3, 5, 7, 8, 10, 12] and d is between 1 and 31
                    set month, day, year
                else if m is in [4, 6, 9, 11] and d is between 1 and 30
                    set month, day, year
                else if m is 2
                    if y is a leap year and d is between 1 and 29
                        set month, day, year
                    else if d is between 1 and 28
                        set month, day, year
        else
            print "Invalid Date"

    method getDetails()
        print month, day, year

    method displayDate()
        print month/day/year

main
    create Date object with month, day, year
    call getDetails method
    call displayDate method

This problem has been solved

Similar Questions

create a class called date, with integer data members for day, month, and year. the comprises of member functions: 1. to display date in DD/MM/YYYY format 2. to subtract an integer from date object 3. to subtract one date from another using oops in c++

Write a JAVA program in which take date(DDMMYYYY) from user and displaynext day date(DDMMYYYY) as output.Example:Input: date=09, month=-06, year=1992Output: date=10, month=-06, year=1992Note:-1. Consider condition for leap year2. Consider number of days in month of February based on leap year ( if leapyear then February days =29, else days = 28 ) )3. Consider number of days either 30 or 31 based on month entered by user

Write a C program that prompts the user to enter the date as three integer values for the month, the day in the month, and the year. The program should then output the date in the form 31st December 2010 when the user enters 12 31 2010, say. The program has to work out when superscripts “th”, “nd”, “st”, and “rd” need to be appended to the day value. The programmer should not forget 1st, 2nd, 3rd, 4th; and then 11th, 12th, 13th, 14th; and 21st, 22nd, 23rd, and 24th.Testcases:Input:02 11 2021Output:11th February 202

shu wants to create a program that asks users to input their birthdates, including the day, month, and year. The program should then display the entered birthdate in the format "DD/MM/YYYY."Write a program to assist Ishu in achieving this task.Input format :The input consists of three space-separated integer values, representing the user's birthdate(day, month, and year).Output format :The output displays the user's birthdate in the format "Your birthday is on " followed by the formatted date DD/MM/YYYY.

Create a class named Year that contains a data field that holds the number of days in theyear. Include a get method that displays the number of days and a constructor that setsthe number of days to 365. Create a subclass named LeapYear. LeapYear’s constructoroverrides Year’s constructor and sets the day field to 366.Write a program that instan6ates one object of each class and displays their data.Add a method named daysElapsed() to the Year class you created in Exercise 5a. ThedaysElapsed() method accepts two arguments represen6ng a month and a day; it returnsan integer indica6ng the number of days that have elapsed since January 1 of the year.Create a daysElapsed() method for the LeapYear class that overrides the method in theYear class. Write a program that calculates the days elapsed on March 1 for a Year and fora LeapYear.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.