Answer to Question #274323 in C++ for Ase Abera

Question #274323

write a c++application that extracts a day,month and year and determines whether the date is valid. if the program is given a valid date,an appropriate message is displayed.


1
Expert's answer
2021-12-02T00:35:13-0500
#include <chrono>
#include <iostream>

void
displayMessage(std::chrono::year_month_day ymd)
{
    using namespace std;
    using namespace std::chrono;
    if (!ymd.year().ok())
    {
        cout << "Bad year\n";
        return;
    }
    if (!ymd.month().ok())
    {
        cout << "Bad month\n";
        return;
    }
    if (!ymd.ok())
    {
        cout << "Bad day, not 1-" << (ymd.year()/ymd.month()/last).day() << '\n';
        return;
    }
    cout << "Good date!\n";
}

int
main()
{
    using namespace std::literals;
    displayMessage(29d/2/1900);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment